SDL: Fix SDL audio in some cases

This commit is contained in:
Jeffrey Pfau 2014-11-19 23:14:44 -08:00
parent 51896cdcd6
commit d8b7452526
3 changed files with 6 additions and 4 deletions

View File

@ -117,8 +117,8 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
GBACreate(&gba); GBACreate(&gba);
ARMSetComponents(&cpu, &gba.d, numComponents, components); ARMSetComponents(&cpu, &gba.d, numComponents, components);
ARMInit(&cpu); ARMInit(&cpu);
threadContext->gba = &gba;
gba.sync = &threadContext->sync; gba.sync = &threadContext->sync;
threadContext->gba = &gba;
gba.logLevel = threadContext->logLevel; gba.logLevel = threadContext->logLevel;
#ifdef USE_PTHREADS #ifdef USE_PTHREADS
pthread_setspecific(_contextKey, threadContext); pthread_setspecific(_contextKey, threadContext);

View File

@ -25,8 +25,6 @@
static bool _GBASDLInit(struct SDLSoftwareRenderer* renderer); static bool _GBASDLInit(struct SDLSoftwareRenderer* renderer);
static void _GBASDLDeinit(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) { int main(int argc, char** argv) {
struct SDLSoftwareRenderer renderer; struct SDLSoftwareRenderer renderer;

View File

@ -53,11 +53,15 @@ void GBASDLResumeAudio(struct GBASDLAudio* context) {
static void _GBASDLAudioCallback(void* context, Uint8* data, int len) { static void _GBASDLAudioCallback(void* context, Uint8* data, int len) {
struct GBASDLAudio* audioContext = context; struct GBASDLAudio* audioContext = context;
if (!context || !audioContext->thread) { if (!context || !audioContext->thread || !audioContext->thread->gba) {
memset(data, 0, len); memset(data, 0, len);
return; return;
} }
audioContext->ratio = GBAAudioCalculateRatio(&audioContext->thread->gba->audio, audioContext->thread->fpsTarget, audioContext->obtainedSpec.freq); 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; struct GBAStereoSample* ssamples = (struct GBAStereoSample*) data;
len /= 2 * audioContext->obtainedSpec.channels; len /= 2 * audioContext->obtainedSpec.channels;
if (audioContext->obtainedSpec.channels == 2) { if (audioContext->obtainedSpec.channels == 2) {