mirror of https://github.com/mgba-emu/mgba.git
Function for calculating audio rate for target FPS
This commit is contained in:
parent
c9f74b43af
commit
b14f22191c
|
@ -4,6 +4,7 @@
|
||||||
#include "gba-io.h"
|
#include "gba-io.h"
|
||||||
#include "gba-serialize.h"
|
#include "gba-serialize.h"
|
||||||
#include "gba-thread.h"
|
#include "gba-thread.h"
|
||||||
|
#include "gba-video.h"
|
||||||
|
|
||||||
const unsigned GBA_AUDIO_SAMPLES = 512;
|
const unsigned GBA_AUDIO_SAMPLES = 512;
|
||||||
const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);
|
const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);
|
||||||
|
@ -751,3 +752,7 @@ void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState
|
||||||
audio->eventDiff = state->audio.eventDiff;
|
audio->eventDiff = state->audio.eventDiff;
|
||||||
audio->nextSample = state->audio.nextSample;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -251,4 +251,6 @@ struct GBASerializedState;
|
||||||
void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state);
|
void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state);
|
||||||
void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState* state);
|
void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState* state);
|
||||||
|
|
||||||
|
float GBAAudioCalculateRatio(struct GBAAudio* audio, float desiredFPS, float desiredSampleRatio);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -43,8 +43,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len) {
|
||||||
memset(data, 0, len);
|
memset(data, 0, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float ratio = 280896.0f * FPS_TARGET / GBA_ARM7TDMI_FREQUENCY;
|
audioContext->ratio = GBAAudioCalculateRatio(audioContext->audio, FPS_TARGET, audioContext->obtainedSpec.freq);
|
||||||
audioContext->ratio = audioContext->obtainedSpec.freq / ratio / (float) audioContext->audio->sampleRate;
|
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in New Issue