Function for calculating audio rate for target FPS
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Jul 2014 23:24:02 -0700
3 files changed,
8 insertions(+),
2 deletions(-)
M
src/gba/gba-audio.c
→
src/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.h
→
src/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.c
→
src/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) {