mirror of https://github.com/mgba-emu/mgba.git
Variable FPS target
This commit is contained in:
parent
b14f22191c
commit
eabac4c413
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
static const float _defaultFPSTarget = 60.f;
|
||||||
|
|
||||||
#ifdef USE_PTHREADS
|
#ifdef USE_PTHREADS
|
||||||
static pthread_key_t _contextKey;
|
static pthread_key_t _contextKey;
|
||||||
static pthread_once_t _contextOnce = PTHREAD_ONCE_INIT;
|
static pthread_once_t _contextOnce = PTHREAD_ONCE_INIT;
|
||||||
|
@ -202,6 +204,10 @@ bool GBAThreadStart(struct GBAThread* threadContext) {
|
||||||
threadContext->rewindBuffer = 0;
|
threadContext->rewindBuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!threadContext->fpsTarget) {
|
||||||
|
threadContext->fpsTarget = _defaultFPSTarget;
|
||||||
|
}
|
||||||
|
|
||||||
if (threadContext->rom && !GBAIsROM(threadContext->rom)) {
|
if (threadContext->rom && !GBAIsROM(threadContext->rom)) {
|
||||||
threadContext->rom->close(threadContext->rom);
|
threadContext->rom->close(threadContext->rom);
|
||||||
threadContext->rom = 0;
|
threadContext->rom = 0;
|
||||||
|
|
|
@ -56,6 +56,7 @@ struct GBAThread {
|
||||||
const char* fname;
|
const char* fname;
|
||||||
int activeKeys;
|
int activeKeys;
|
||||||
int frameskip;
|
int frameskip;
|
||||||
|
float fpsTarget;
|
||||||
|
|
||||||
// Threading state
|
// Threading state
|
||||||
Thread thread;
|
Thread thread;
|
||||||
|
|
|
@ -230,6 +230,7 @@ static void _GBASDLDeinit(struct GLSoftwareRenderer* renderer) {
|
||||||
static void _GBASDLStart(struct GBAThread* threadContext) {
|
static void _GBASDLStart(struct GBAThread* threadContext) {
|
||||||
struct GLSoftwareRenderer* renderer = threadContext->userData;
|
struct GLSoftwareRenderer* renderer = threadContext->userData;
|
||||||
renderer->audio.audio = &threadContext->gba->audio;
|
renderer->audio.audio = &threadContext->gba->audio;
|
||||||
|
renderer->audio.thread = threadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GBASDLClean(struct GBAThread* threadContext) {
|
static void _GBASDLClean(struct GBAThread* threadContext) {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "gba-thread.h"
|
#include "gba-thread.h"
|
||||||
|
|
||||||
#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2)
|
#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2)
|
||||||
#define FPS_TARGET 60.f
|
|
||||||
|
|
||||||
static void _GBASDLAudioCallback(void* context, Uint8* data, int len);
|
static void _GBASDLAudioCallback(void* context, Uint8* data, int len);
|
||||||
|
|
||||||
|
@ -17,10 +16,11 @@ bool GBASDLInitAudio(struct GBASDLAudio* context) {
|
||||||
context->desiredSpec.freq = 44100;
|
context->desiredSpec.freq = 44100;
|
||||||
context->desiredSpec.format = AUDIO_S16SYS;
|
context->desiredSpec.format = AUDIO_S16SYS;
|
||||||
context->desiredSpec.channels = 2;
|
context->desiredSpec.channels = 2;
|
||||||
context->desiredSpec.samples = GBA_AUDIO_SAMPLES;
|
context->desiredSpec.samples = BUFFER_SIZE;
|
||||||
context->desiredSpec.callback = _GBASDLAudioCallback;
|
context->desiredSpec.callback = _GBASDLAudioCallback;
|
||||||
context->desiredSpec.userdata = context;
|
context->desiredSpec.userdata = context;
|
||||||
context->audio = 0;
|
context->audio = 0;
|
||||||
|
context->thread = 0;
|
||||||
context->drift = 0.f;
|
context->drift = 0.f;
|
||||||
if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) {
|
if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) {
|
||||||
GBALog(0, GBA_LOG_ERROR, "Could not open SDL sound system");
|
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);
|
memset(data, 0, len);
|
||||||
return;
|
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;
|
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) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ struct GBASDLAudio {
|
||||||
float drift;
|
float drift;
|
||||||
float ratio;
|
float ratio;
|
||||||
struct GBAAudio* audio;
|
struct GBAAudio* audio;
|
||||||
|
struct GBAThread* thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool GBASDLInitAudio(struct GBASDLAudio* context);
|
bool GBASDLInitAudio(struct GBASDLAudio* context);
|
||||||
|
|
Loading…
Reference in New Issue