all repos — mgba @ b14f22191cc902a7d4486e812e74f2eda99765e3

mGBA Game Boy Advance Emulator

Function for calculating audio rate for target FPS
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Jul 2014 23:24:02 -0700
commit

b14f22191cc902a7d4486e812e74f2eda99765e3

parent

c9f74b43afd493dae81fb1714dd721941d4a4edc

3 files changed, 8 insertions(+), 2 deletions(-)

jump to
M src/gba/gba-audio.csrc/gba/gba-audio.c

@@ -4,6 +4,7 @@ #include "gba.h"

#include "gba-io.h" #include "gba-serialize.h" #include "gba-thread.h" +#include "gba-video.h" const unsigned GBA_AUDIO_SAMPLES = 512; const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);

@@ -751,3 +752,7 @@ audio->nextEvent = state->audio.nextEvent;

audio->eventDiff = state->audio.eventDiff; audio->nextSample = state->audio.nextSample; } + +float GBAAudioCalculateRatio(struct GBAAudio* audio, float desiredFPS, float desiredSampleRate) { + return desiredSampleRate * GBA_ARM7TDMI_FREQUENCY / (VIDEO_TOTAL_LENGTH * desiredFPS * audio->sampleRate); +}
M src/gba/gba-audio.hsrc/gba/gba-audio.h

@@ -251,4 +251,6 @@ struct GBASerializedState;

void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state); void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState* state); +float GBAAudioCalculateRatio(struct GBAAudio* audio, float desiredFPS, float desiredSampleRatio); + #endif
M src/platform/sdl/sdl-audio.csrc/platform/sdl/sdl-audio.c

@@ -43,8 +43,7 @@ if (!context || !audioContext->audio) {

memset(data, 0, len); return; } - float ratio = 280896.0f * FPS_TARGET / GBA_ARM7TDMI_FREQUENCY; - audioContext->ratio = audioContext->obtainedSpec.freq / ratio / (float) audioContext->audio->sampleRate; + audioContext->ratio = GBAAudioCalculateRatio(audioContext->audio, FPS_TARGET, audioContext->obtainedSpec.freq); struct GBAStereoSample* ssamples = (struct GBAStereoSample*) data; len /= 2 * audioContext->obtainedSpec.channels; if (audioContext->obtainedSpec.channels == 2) {