From d8b745252619874b866f895291ea9d9838ff6367 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 19 Nov 2014 23:14:44 -0800 Subject: [PATCH] SDL: Fix SDL audio in some cases --- src/gba/gba-thread.c | 2 +- src/platform/sdl/main.c | 2 -- src/platform/sdl/sdl-audio.c | 6 +++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 9060f1798..6537d1813 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -117,8 +117,8 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { GBACreate(&gba); ARMSetComponents(&cpu, &gba.d, numComponents, components); ARMInit(&cpu); - threadContext->gba = &gba; gba.sync = &threadContext->sync; + threadContext->gba = &gba; gba.logLevel = threadContext->logLevel; #ifdef USE_PTHREADS pthread_setspecific(_contextKey, threadContext); diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 67a3b9b02..9921d2ebf 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -25,8 +25,6 @@ static bool _GBASDLInit(struct SDLSoftwareRenderer* renderer); static void _GBASDLDeinit(struct SDLSoftwareRenderer* renderer); -static void _GBASDLStart(struct GBAThread* context); -static void _GBASDLClean(struct GBAThread* context); int main(int argc, char** argv) { struct SDLSoftwareRenderer renderer; diff --git a/src/platform/sdl/sdl-audio.c b/src/platform/sdl/sdl-audio.c index 876aed1a3..6a29f6754 100644 --- a/src/platform/sdl/sdl-audio.c +++ b/src/platform/sdl/sdl-audio.c @@ -53,11 +53,15 @@ void GBASDLResumeAudio(struct GBASDLAudio* context) { static void _GBASDLAudioCallback(void* context, Uint8* data, int len) { struct GBASDLAudio* audioContext = context; - if (!context || !audioContext->thread) { + if (!context || !audioContext->thread || !audioContext->thread->gba) { memset(data, 0, len); return; } audioContext->ratio = GBAAudioCalculateRatio(&audioContext->thread->gba->audio, audioContext->thread->fpsTarget, audioContext->obtainedSpec.freq); + if (audioContext->ratio == INFINITY) { + memset(data, 0, len); + return; + } struct GBAStereoSample* ssamples = (struct GBAStereoSample*) data; len /= 2 * audioContext->obtainedSpec.channels; if (audioContext->obtainedSpec.channels == 2) {