From c45bd5a226de610ab3b518782c56d64b6bdfe856 Mon Sep 17 00:00:00 2001 From: Ben Osheroff Date: Sun, 22 May 2011 18:06:34 -0700 Subject: [PATCH] Fix for when the writer thread kicks off before the reader thread (manifested as an initial "stutter" before the buffer filled adequately) --- hairtunes.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hairtunes.c b/hairtunes.c index 285cebad..063438ab 100644 --- a/hairtunes.c +++ b/hairtunes.c @@ -326,6 +326,7 @@ void ab_resync(void) { for (i=0; iready = 1; } - if (ab_buffering && buf_fill >= START_FILL) + if (ab_buffering && buf_fill >= START_FILL) { + ab_buffering = 0; pthread_cond_signal(&ab_buffer_ready); + } if (!ab_buffering) { // check if the t+10th packet has arrived... last-chance resend read = ab_read + 10; @@ -644,7 +647,7 @@ short *buffer_get_frame(void) { pthread_mutex_lock(&ab_mutex); buf_fill = ab_write - ab_read; - if (buf_fill < 1 || !ab_synced) { // init or underrun. stop and wait + if (buf_fill < 1 || !ab_synced || ab_buffering) { // init or underrun. stop and wait if (ab_synced) fprintf(stderr, "\nunderrun.\n");