changeset 25907:bc8452f11147

Reduce number of UnqueueBuffer calls
author reimar
date Wed, 30 Jan 2008 23:37:30 +0000
parents ffea6350c511
children 7cf1b1c1c44c
files libao2/ao_openal.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_openal.c	Wed Jan 30 22:28:41 2008 +0000
+++ b/libao2/ao_openal.c	Wed Jan 30 23:37:30 2008 +0000
@@ -161,10 +161,16 @@
   ALint p;
   int s, i;
   for (s = 0;  s < ao_data.channels; s++) {
+    int till_wrap = NUM_BUF - unqueue_buf[s];
     alGetSourcei(sources[s], AL_BUFFERS_PROCESSED, &p);
-    for (i = 0; i < p; i++) {
-      alSourceUnqueueBuffers(sources[s], 1, &buffers[s][unqueue_buf[s]]);
-      unqueue_buf[s] = (unqueue_buf[s] + 1) % NUM_BUF;
+    if (p >= till_wrap) {
+      alSourceUnqueueBuffers(sources[s], till_wrap, &buffers[s][unqueue_buf[s]]);
+      unqueue_buf[s] = 0;
+      p -= till_wrap;
+    }
+    if (p) {
+      alSourceUnqueueBuffers(sources[s], p, &buffers[s][unqueue_buf[s]]);
+      unqueue_buf[s] += p;
     }
   }
 }