From eabac4c413c0b83caa4b9a97c6ab6dc3997b4ca0 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 20 Jul 2014 23:45:30 -0700 Subject: [PATCH] Variable FPS target --- src/gba/gba-thread.c | 6 ++++++ src/gba/gba-thread.h | 1 + src/platform/sdl/gl-main.c | 1 + src/platform/sdl/sdl-audio.c | 6 +++--- src/platform/sdl/sdl-audio.h | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 9029ba9b0..9f9baf0ac 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -11,6 +11,8 @@ #include +static const float _defaultFPSTarget = 60.f; + #ifdef USE_PTHREADS static pthread_key_t _contextKey; static pthread_once_t _contextOnce = PTHREAD_ONCE_INIT; @@ -202,6 +204,10 @@ bool GBAThreadStart(struct GBAThread* threadContext) { threadContext->rewindBuffer = 0; } + if (!threadContext->fpsTarget) { + threadContext->fpsTarget = _defaultFPSTarget; + } + if (threadContext->rom && !GBAIsROM(threadContext->rom)) { threadContext->rom->close(threadContext->rom); threadContext->rom = 0; diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index a870b9610..072fd4a13 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -56,6 +56,7 @@ struct GBAThread { const char* fname; int activeKeys; int frameskip; + float fpsTarget; // Threading state Thread thread; diff --git a/src/platform/sdl/gl-main.c b/src/platform/sdl/gl-main.c index acc5f4363..f1114f0f6 100644 --- a/src/platform/sdl/gl-main.c +++ b/src/platform/sdl/gl-main.c @@ -230,6 +230,7 @@ static void _GBASDLDeinit(struct GLSoftwareRenderer* renderer) { static void _GBASDLStart(struct GBAThread* threadContext) { struct GLSoftwareRenderer* renderer = threadContext->userData; renderer->audio.audio = &threadContext->gba->audio; + renderer->audio.thread = threadContext; } static void _GBASDLClean(struct GBAThread* threadContext) { diff --git a/src/platform/sdl/sdl-audio.c b/src/platform/sdl/sdl-audio.c index fdb1f4818..ac4d0c3d6 100644 --- a/src/platform/sdl/sdl-audio.c +++ b/src/platform/sdl/sdl-audio.c @@ -4,7 +4,6 @@ #include "gba-thread.h" #define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) -#define FPS_TARGET 60.f static void _GBASDLAudioCallback(void* context, Uint8* data, int len); @@ -17,10 +16,11 @@ bool GBASDLInitAudio(struct GBASDLAudio* context) { context->desiredSpec.freq = 44100; context->desiredSpec.format = AUDIO_S16SYS; context->desiredSpec.channels = 2; - context->desiredSpec.samples = GBA_AUDIO_SAMPLES; + context->desiredSpec.samples = BUFFER_SIZE; context->desiredSpec.callback = _GBASDLAudioCallback; context->desiredSpec.userdata = context; context->audio = 0; + context->thread = 0; context->drift = 0.f; if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) { GBALog(0, GBA_LOG_ERROR, "Could not open SDL sound system"); @@ -43,7 +43,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len) { memset(data, 0, len); return; } - audioContext->ratio = GBAAudioCalculateRatio(audioContext->audio, FPS_TARGET, audioContext->obtainedSpec.freq); + audioContext->ratio = GBAAudioCalculateRatio(audioContext->audio, audioContext->thread->fpsTarget, audioContext->obtainedSpec.freq); struct GBAStereoSample* ssamples = (struct GBAStereoSample*) data; len /= 2 * audioContext->obtainedSpec.channels; if (audioContext->obtainedSpec.channels == 2) { diff --git a/src/platform/sdl/sdl-audio.h b/src/platform/sdl/sdl-audio.h index 78e51f134..436b9286a 100644 --- a/src/platform/sdl/sdl-audio.h +++ b/src/platform/sdl/sdl-audio.h @@ -11,6 +11,7 @@ struct GBASDLAudio { float drift; float ratio; struct GBAAudio* audio; + struct GBAThread* thread; }; bool GBASDLInitAudio(struct GBASDLAudio* context);