Variable FPS target
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Jul 2014 23:45:30 -0700
5 files changed,
12 insertions(+),
3 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -11,6 +11,8 @@ #include "util/vfs.h"
#include <signal.h> +static const float _defaultFPSTarget = 60.f; + #ifdef USE_PTHREADS static pthread_key_t _contextKey; static pthread_once_t _contextOnce = PTHREAD_ONCE_INIT;@@ -200,6 +202,10 @@ if (threadContext->rewindBufferCapacity) {
threadContext->rewindBuffer = calloc(threadContext->rewindBufferCapacity, sizeof(void*)); } else { threadContext->rewindBuffer = 0; + } + + if (!threadContext->fpsTarget) { + threadContext->fpsTarget = _defaultFPSTarget; } if (threadContext->rom && !GBAIsROM(threadContext->rom)) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -56,6 +56,7 @@ struct VFile* patch;
const char* fname; int activeKeys; int frameskip; + float fpsTarget; // Threading state Thread thread;
M
src/platform/sdl/gl-main.c
→
src/platform/sdl/gl-main.c
@@ -230,6 +230,7 @@
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) {
M
src/platform/sdl/sdl-audio.c
→
src/platform/sdl/sdl-audio.c
@@ -4,7 +4,6 @@ #include "gba.h"
#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 @@
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 @@ if (!context || !audioContext->audio) {
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) {
M
src/platform/sdl/sdl-audio.h
→
src/platform/sdl/sdl-audio.h
@@ -11,6 +11,7 @@ SDL_AudioSpec obtainedSpec;
float drift; float ratio; struct GBAAudio* audio; + struct GBAThread* thread; }; bool GBASDLInitAudio(struct GBASDLAudio* context);