changeset 25647:e93a3c68757f

Slightly simplify read_buffer code
author reimar
date Fri, 11 Jan 2008 20:32:42 +0000
parents 01f762da9c87
children 2438052a176e
files libao2/ao_jack.c
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_jack.c	Fri Jan 11 20:23:46 2008 +0000
+++ b/libao2/ao_jack.c	Fri Jan 11 20:32:42 2008 +0000
@@ -136,18 +136,18 @@
 static int read_buffer(float **bufs, int cnt, int num_bufs) {
   int buffered = buf_used();
   int i, j;
-  int orig_cnt = cnt;
-  if (cnt * sizeof(float) * num_bufs > buffered)
+  if (cnt * sizeof(float) * num_bufs > buffered) {
+    int orig_cnt = cnt;
     cnt = buffered / sizeof(float) / num_bufs;
+    for (i = 0; i < num_bufs; i++)
+      memset(&bufs[i][cnt], 0, (orig_cnt - cnt) * sizeof(float));
+  }
   for (i = 0; i < cnt; i++) {
     for (j = 0; j < num_bufs; j++) {
-      bufs[j][i] = *((float *)(&buffer[read_pos]));
+      bufs[j][i] = *(float *)&buffer[read_pos];
       read_pos = (read_pos + sizeof(float)) % BUFFSIZE;
     }
   }
-  for (i = cnt; i < orig_cnt; i++)
-    for (j = 0; j < num_bufs; j++)
-      bufs[j][i] = 0;
   return cnt;
 }