changeset 18808:cb83184bdc70

respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer on underrun.
author reimar
date Sun, 25 Jun 2006 09:02:47 +0000
parents 30959018e908
children 9634870ebe4c
files libao2/ao_jack.c
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_jack.c	Sun Jun 25 08:53:13 2006 +0000
+++ b/libao2/ao_jack.c	Sun Jun 25 09:02:47 2006 +0000
@@ -130,10 +130,13 @@
  *
  * Assumes the data in the buffer is of type float, the number of bytes
  * read is res * num_bufs * sizeof(float), where res is the return value.
+ * If there is not enough data in the buffer remaining parts will be filled
+ * with silence.
  */
 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)
     cnt = buffered / sizeof(float) / num_bufs;
   for (i = 0; i < cnt; i++) {
@@ -142,6 +145,9 @@
       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;
 }
 
@@ -177,11 +183,11 @@
   int i;
   for (i = 0; i < num_ports; i++)
     bufs[i] = jack_port_get_buffer(ports[i], nframes);
-  if (!paused && !underrun)
+  if (paused || underrun)
+    silence(bufs, nframes, num_ports);
+  else
     if (read_buffer(bufs, nframes, num_ports) < nframes)
       underrun = 1;
-  if (paused || underrun)
-    silence(bufs, nframes, num_ports);
   if (estimate) {
     float now = (float)GetTimer() / 1000000.0;
     float diff = callback_time + callback_interval - now;
@@ -349,6 +355,7 @@
  * \brief write data into buffer and reset underrun flag
  */
 static int play(void *data, int len, int flags) {
+  if (!(flags & AOPLAY_FINAL_CHUNK))
   len -= len % ao_data.outburst;
   underrun = 0;
   return write_buffer(data, len);