Variable FPS target

This commit is contained in:
Jeffrey Pfau 2014-07-20 23:45:30 -07:00
parent b14f22191c
commit eabac4c413
5 changed files with 12 additions and 3 deletions

View File

@ -11,6 +11,8 @@
#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;
@ -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;

View File

@ -56,6 +56,7 @@ struct GBAThread {
const char* fname;
int activeKeys;
int frameskip;
float fpsTarget;
// Threading state
Thread thread;

View File

@ -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) {

View File

@ -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) {

View File

@ -11,6 +11,7 @@ struct GBASDLAudio {
float drift;
float ratio;
struct GBAAudio* audio;
struct GBAThread* thread;
};
bool GBASDLInitAudio(struct GBASDLAudio* context);