Slow down audio slightly to match target FPS

This commit is contained in:
Jeffrey Pfau 2014-01-20 20:02:44 -08:00
parent dccde662c6
commit 98c8b42b0f
2 changed files with 4 additions and 2 deletions

View File

@ -95,7 +95,7 @@ static int _GBASDLInit(struct GLSoftwareRenderer* renderer) {
GBASDLInitEvents(&renderer->events);
GBASDLInitAudio(&renderer->audio);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);

View File

@ -4,6 +4,7 @@
#include "gba-thread.h"
#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2)
#define FPS_TARGET 60.f
struct StereoSample {
Sint16 left;
@ -87,7 +88,8 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len) {
memset(data, 0, len);
return;
}
audioContext->ratio = audioContext->obtainedSpec.freq / (float) audioContext->audio->sampleRate;
float ratio = 280896.0f * FPS_TARGET / GBA_ARM7TDMI_FREQUENCY;
audioContext->ratio = audioContext->obtainedSpec.freq / ratio / (float) audioContext->audio->sampleRate;
struct StereoSample* ssamples = (struct StereoSample*) data;
len /= 2 * audioContext->obtainedSpec.channels;
if (audioContext->obtainedSpec.channels == 2) {