Clean up audio sync code
Jeffrey Pfau jeffrey@endrift.com
Tue, 08 Oct 2013 22:36:55 -0700
3 files changed,
3 insertions(+),
5 deletions(-)
M
src/gba/gba-audio.c
→
src/gba/gba-audio.c
@@ -178,6 +178,9 @@ }
pthread_mutex_lock(&audio->bufferMutex); while (CircleBufferSize(&audio->left) + (GBA_AUDIO_SAMPLES * 2 / 5) >= audio->left.capacity) { + if (!audio->p->sync->audioWait) { + break; + } GBASyncProduceAudio(audio->p->sync, &audio->bufferMutex); } CircleBufferWrite32(&audio->left, sampleLeft);
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -92,7 +92,6 @@
pthread_mutex_init(&threadContext->sync.videoFrameMutex, 0); pthread_cond_init(&threadContext->sync.videoFrameAvailableCond, 0); pthread_cond_init(&threadContext->sync.videoFrameRequiredCond, 0); - pthread_cond_init(&threadContext->sync.audioAvailableCond, 0); pthread_cond_init(&threadContext->sync.audioRequiredCond, 0); pthread_mutex_lock(&threadContext->startMutex);@@ -122,8 +121,6 @@ pthread_cond_destroy(&threadContext->sync.videoFrameAvailableCond);
pthread_cond_broadcast(&threadContext->sync.videoFrameRequiredCond); pthread_cond_destroy(&threadContext->sync.videoFrameRequiredCond); - pthread_cond_broadcast(&threadContext->sync.audioAvailableCond); - pthread_cond_destroy(&threadContext->sync.audioAvailableCond); pthread_cond_broadcast(&threadContext->sync.audioRequiredCond); pthread_cond_destroy(&threadContext->sync.audioRequiredCond); }@@ -172,7 +169,6 @@ return sync->videoFrameSkip <= 0;
} void GBASyncProduceAudio(struct GBASync* sync, pthread_mutex_t* mutex) { - pthread_cond_broadcast(&sync->audioAvailableCond); if (&sync->audioWait) { pthread_cond_wait(&sync->audioRequiredCond, mutex); }
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -32,7 +32,6 @@ pthread_cond_t videoFrameAvailableCond;
pthread_cond_t videoFrameRequiredCond; int audioWait; - pthread_cond_t audioAvailableCond; pthread_cond_t audioRequiredCond; } sync; };