mirror of https://github.com/mgba-emu/mgba.git
Core: Finally kill off GBAAudioCalculateRatio
This commit is contained in:
parent
96a2ef5f42
commit
73a39dea65
|
@ -216,6 +216,8 @@ void* mCoreGetMemoryBlock(struct mCore* core, uint32_t start, size_t* size);
|
||||||
void* mCoreGetMemoryBlockMasked(struct mCore* core, uint32_t start, size_t* size, uint32_t mask);
|
void* mCoreGetMemoryBlockMasked(struct mCore* core, uint32_t start, size_t* size, uint32_t mask);
|
||||||
const struct mCoreMemoryBlock* mCoreGetMemoryBlockInfo(struct mCore* core, uint32_t address);
|
const struct mCoreMemoryBlock* mCoreGetMemoryBlockInfo(struct mCore* core, uint32_t address);
|
||||||
|
|
||||||
|
double mCoreCalculateFramerateRatio(const struct mCore* core, double desiredFrameRate);
|
||||||
|
|
||||||
#ifdef USE_ELF
|
#ifdef USE_ELF
|
||||||
struct ELF;
|
struct ELF;
|
||||||
bool mCoreLoadELF(struct mCore* core, struct ELF* elf);
|
bool mCoreLoadELF(struct mCore* core, struct ELF* elf);
|
||||||
|
|
|
@ -313,8 +313,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(float inputSampleRate, float desiredFPS, float desiredSampleRatio);
|
|
||||||
|
|
||||||
CXX_GUARD_END
|
CXX_GUARD_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -442,6 +442,12 @@ const struct mCoreMemoryBlock* mCoreGetMemoryBlockInfo(struct mCore* core, uint3
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double mCoreCalculateFramerateRatio(const struct mCore* core, double desiredFrameRate) {
|
||||||
|
uint32_t clockRate = core->frequency(core);
|
||||||
|
uint32_t frameCycles = core->frameCycles(core);
|
||||||
|
return clockRate / (desiredFrameRate * frameCycles);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_ELF
|
#ifdef USE_ELF
|
||||||
bool mCoreLoadELF(struct mCore* core, struct ELF* elf) {
|
bool mCoreLoadELF(struct mCore* core, struct ELF* elf) {
|
||||||
struct ELFProgramHeaders ph;
|
struct ELFProgramHeaders ph;
|
||||||
|
|
|
@ -587,7 +587,3 @@ void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState
|
||||||
}
|
}
|
||||||
mTimingSchedule(&audio->p->timing, &audio->sampleEvent, when);
|
mTimingSchedule(&audio->p->timing, &audio->sampleEvent, when);
|
||||||
}
|
}
|
||||||
|
|
||||||
float GBAAudioCalculateRatio(float inputSampleRate, float desiredFPS, float desiredSampleRate) {
|
|
||||||
return desiredSampleRate * GBA_ARM7TDMI_FREQUENCY / (VIDEO_TOTAL_LENGTH * desiredFPS * inputSampleRate);
|
|
||||||
}
|
|
||||||
|
|
|
@ -376,7 +376,7 @@ void mPSP2Setup(struct mGUIRunner* runner) {
|
||||||
void mPSP2LoadROM(struct mGUIRunner* runner) {
|
void mPSP2LoadROM(struct mGUIRunner* runner) {
|
||||||
float rate = 60.0f / 1.001f;
|
float rate = 60.0f / 1.001f;
|
||||||
sceDisplayGetRefreshRate(&rate);
|
sceDisplayGetRefreshRate(&rate);
|
||||||
double ratio = GBAAudioCalculateRatio(1, rate, 1);
|
double ratio = mCoreCalculateFramerateRatio(runner->core, rate);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ void AudioDevice::setFormat(const QAudioFormat& format) {
|
||||||
LOG(QT, INFO) << tr("Can't set format of context-less audio device");
|
LOG(QT, INFO) << tr("Can't set format of context-less audio device");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double fauxClock = GBAAudioCalculateRatio(1, m_context->impl->sync.fpsTarget, 1);
|
double fauxClock = mCoreCalculateFramerateRatio(m_context->core, m_context->impl->sync.fpsTarget);
|
||||||
mCoreSyncLockAudio(&m_context->impl->sync);
|
mCoreSyncLockAudio(&m_context->impl->sync);
|
||||||
blip_set_rates(m_context->core->getAudioChannel(m_context->core, 0),
|
blip_set_rates(m_context->core->getAudioChannel(m_context->core, 0),
|
||||||
m_context->core->frequency(m_context->core), format.sampleRate() * fauxClock);
|
m_context->core->frequency(m_context->core), format.sampleRate() * fauxClock);
|
||||||
|
|
|
@ -103,12 +103,11 @@ static void _mSDLAudioCallback(void* context, Uint8* data, int len) {
|
||||||
if (audioContext->core) {
|
if (audioContext->core) {
|
||||||
left = audioContext->core->getAudioChannel(audioContext->core, 0);
|
left = audioContext->core->getAudioChannel(audioContext->core, 0);
|
||||||
right = audioContext->core->getAudioChannel(audioContext->core, 1);
|
right = audioContext->core->getAudioChannel(audioContext->core, 1);
|
||||||
clockRate = audioContext->core->frequency(audioContext->core);
|
|
||||||
}
|
}
|
||||||
double fauxClock = 1;
|
double fauxClock = 1;
|
||||||
if (audioContext->sync) {
|
if (audioContext->sync) {
|
||||||
if (audioContext->sync->fpsTarget > 0) {
|
if (audioContext->sync->fpsTarget > 0 && audioContext->core) {
|
||||||
fauxClock = GBAAudioCalculateRatio(1, audioContext->sync->fpsTarget, 1);
|
fauxClock = mCoreCalculateFramerateRatio(audioContext->core, audioContext->sync->fpsTarget);
|
||||||
}
|
}
|
||||||
mCoreSyncLockAudio(audioContext->sync);
|
mCoreSyncLockAudio(audioContext->sync);
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,7 +330,7 @@ static void _setup(struct mGUIRunner* runner) {
|
||||||
static void _gameLoaded(struct mGUIRunner* runner) {
|
static void _gameLoaded(struct mGUIRunner* runner) {
|
||||||
u32 samplerate = audoutGetSampleRate();
|
u32 samplerate = audoutGetSampleRate();
|
||||||
|
|
||||||
double ratio = GBAAudioCalculateRatio(1, 60.0, 1);
|
double ratio = mCoreCalculateFramerateRatio(runner->core, 60.0);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), samplerate * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), samplerate * ratio);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), samplerate * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), samplerate * ratio);
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ static void reconfigureScreen(struct mGUIRunner* runner) {
|
||||||
runner->params.width = vmode->fbWidth * guiScale * wAdjust;
|
runner->params.width = vmode->fbWidth * guiScale * wAdjust;
|
||||||
runner->params.height = vmode->efbHeight * guiScale * hAdjust;
|
runner->params.height = vmode->efbHeight * guiScale * hAdjust;
|
||||||
if (runner->core) {
|
if (runner->core) {
|
||||||
double ratio = GBAAudioCalculateRatio(1, audioSampleRate, 1);
|
double ratio = mCoreCalculateFramerateRatio(runner->core, audioSampleRate);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1422,7 @@ void _setup(struct mGUIRunner* runner) {
|
||||||
}
|
}
|
||||||
runner->core->setAudioBufferSize(runner->core, SAMPLES);
|
runner->core->setAudioBufferSize(runner->core, SAMPLES);
|
||||||
|
|
||||||
double ratio = GBAAudioCalculateRatio(1, audioSampleRate, 1);
|
double ratio = mCoreCalculateFramerateRatio(runner->core, audioSampleRate);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
|
||||||
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
|
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue