all repos — mgba @ 13f1ab5ab84c83129e96ae80a9d261806b91289f

mGBA Game Boy Advance Emulator

Core: Put back fpsTarget
Jeffrey Pfau jeffrey@endrift.com
Tue, 09 Feb 2016 20:20:14 -0800
commit

13f1ab5ab84c83129e96ae80a9d261806b91289f

parent

ce085623de93a4baf202a01a11cadadc347b71ba

M src/core/core.csrc/core/core.c

@@ -190,5 +190,6 @@ mCoreConfigMap(config, &core->opts);

#ifndef MINIMAL_CORE mDirectorySetMapOptions(&core->dirs, &core->opts); #endif + core->setAudioBufferSize(core, core->opts.audioBuffers); core->loadConfig(core, config); }
M src/core/core.hsrc/core/core.h

@@ -55,6 +55,7 @@ void (*getVideoBuffer)(struct mCore*, color_t** buffer, size_t* stride);

struct blip_t* (*getAudioChannel)(struct mCore*, int ch); void (*setAudioBufferSize)(struct mCore*, size_t samples); + size_t (*getAudioBufferSize)(struct mCore*); void (*setAVStream)(struct mCore*, struct mAVStream*);
M src/core/sync.hsrc/core/sync.h

@@ -21,6 +21,8 @@

bool audioWait; Condition audioRequiredCond; Mutex audioBufferMutex; + + float fpsTarget; }; void mCoreSyncPostFrame(struct mCoreSync* sync);
M src/core/thread.csrc/core/thread.c

@@ -15,6 +15,8 @@ #include <signal.h>

#ifndef DISABLE_THREADING +static const float _defaultFPSTarget = 60.f; + #ifdef USE_PTHREADS static pthread_key_t _contextKey; static pthread_once_t _contextOnce = PTHREAD_ONCE_INIT;

@@ -163,6 +165,10 @@ bool mCoreThreadStart(struct mCoreThread* threadContext) {

threadContext->state = THREAD_INITIALIZED; threadContext->logger.p = threadContext; + if (!threadContext->sync.fpsTarget) { + threadContext->sync.fpsTarget = _defaultFPSTarget; + } + MutexInit(&threadContext->stateMutex); ConditionInit(&threadContext->stateCond);

@@ -184,6 +190,7 @@ #endif

threadContext->sync.audioWait = threadContext->core->opts.audioSync; threadContext->sync.videoFrameWait = threadContext->core->opts.videoSync; + threadContext->sync.fpsTarget = threadContext->core->opts.fpsTarget; MutexLock(&threadContext->stateMutex); ThreadCreate(&threadContext->thread, _mCoreThreadRun, threadContext);
M src/gb/core.csrc/gb/core.c

@@ -101,6 +101,11 @@ struct GB* gb = core->board;

GBAudioResizeBuffer(&gb->audio, samples); } +static size_t _GBCoreGetAudioBufferSize(struct mCore* core) { + struct GB* gb = core->board; + return gb->audio.samples; +} + static void _GBCoreSetAVStream(struct mCore* core, struct mAVStream* stream) { // TODO }

@@ -231,6 +236,7 @@ core->setVideoBuffer = _GBCoreSetVideoBuffer;

core->getVideoBuffer = _GBCoreGetVideoBuffer; core->getAudioChannel = _GBCoreGetAudioChannel; core->setAudioBufferSize = _GBCoreSetAudioBufferSize; + core->getAudioBufferSize = _GBCoreGetAudioBufferSize; core->setAVStream = _GBCoreSetAVStream; core->isROM = GBIsROM; core->loadROM = _GBCoreLoadROM;
M src/gba/core.csrc/gba/core.c

@@ -132,6 +132,11 @@ struct GBA* gba = core->board;

GBAAudioResizeBuffer(&gba->audio, samples); } +static size_t _GBACoreGetAudioBufferSize(struct mCore* core) { + struct GBA* gba = core->board; + return gba->audio.samples; +} + static void _GBACoreSetAVStream(struct mCore* core, struct mAVStream* stream) { struct GBA* gba = core->board; gba->stream = stream;

@@ -267,6 +272,7 @@ core->setVideoBuffer = _GBACoreSetVideoBuffer;

core->getVideoBuffer = _GBACoreGetVideoBuffer; core->getAudioChannel = _GBACoreGetAudioChannel; core->setAudioBufferSize = _GBACoreSetAudioBufferSize; + core->getAudioBufferSize = _GBACoreGetAudioBufferSize; core->setAVStream = _GBACoreSetAVStream; core->isROM = GBAIsROM; core->loadROM = _GBACoreLoadROM;
M src/platform/qt/AudioDevice.cppsrc/platform/qt/AudioDevice.cpp

@@ -18,8 +18,6 @@

AudioDevice::AudioDevice(QObject* parent) : QIODevice(parent) , m_context(nullptr) - , m_drift(0) - , m_ratio(1.f) { setOpenMode(ReadOnly); }

@@ -29,10 +27,12 @@ if (!m_context || !mCoreThreadIsActive(m_context)) {

LOG(QT, INFO) << tr("Can't set format of context-less audio device"); return; } - double fauxClock = GBAAudioCalculateRatio(1, 60, 1); // TODO: Put back fpsTarget + double fauxClock = GBAAudioCalculateRatio(1, m_context->sync.fpsTarget, 1); mCoreSyncLockAudio(&m_context->sync); - blip_set_rates(m_context->core->getAudioChannel(m_context->core, 0), GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock); - blip_set_rates(m_context->core->getAudioChannel(m_context->core, 1), GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock); + blip_set_rates(m_context->core->getAudioChannel(m_context->core, 0), + m_context->core->frequency(m_context->core), format.sampleRate() * fauxClock); + blip_set_rates(m_context->core->getAudioChannel(m_context->core, 1), + m_context->core->frequency(m_context->core), format.sampleRate() * fauxClock); mCoreSyncUnlockAudio(&m_context->sync); }

@@ -41,8 +41,8 @@ m_context = input;

} qint64 AudioDevice::readData(char* data, qint64 maxSize) { - if (maxSize > 0xFFFFFFFF) { - maxSize = 0xFFFFFFFF; + if (maxSize > 0xFFFFFFFFLL) { + maxSize = 0xFFFFFFFFLL; } if (!m_context->core) {
M src/platform/qt/AudioDevice.hsrc/platform/qt/AudioDevice.h

@@ -28,8 +28,6 @@ virtual qint64 writeData(const char* data, qint64 maxSize) override;

private: mCoreThread* m_context; - float m_drift; - float m_ratio; }; }
M src/platform/qt/AudioProcessorQt.cppsrc/platform/qt/AudioProcessorQt.cpp

@@ -59,7 +59,7 @@ }

m_device->setInput(input()); m_device->setFormat(m_audioOutput->format()); - m_audioOutput->setBufferSize(2048 * 4); // TODO? + m_audioOutput->setBufferSize(input()->core->getAudioBufferSize(input()->core) * 4); m_audioOutput->start(m_device); return m_audioOutput->state() == QAudio::ActiveState;
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -101,7 +101,7 @@ gba->video.renderer->disableBG[1] = !controller->m_videoLayers[1];

gba->video.renderer->disableBG[2] = !controller->m_videoLayers[2]; gba->video.renderer->disableBG[3] = !controller->m_videoLayers[3]; gba->video.renderer->disableOBJ = !controller->m_videoLayers[4];*/ - // TODO: Put back fpsTarget + controller->m_fpsTarget = context->sync.fpsTarget; if (mCoreLoadState(context->core, 0, controller->m_loadStateFlags)) { mCoreDeleteState(context->core, 0);

@@ -239,6 +239,7 @@ m_config = config;

if (isLoaded()) { threadInterrupt(); mCoreLoadForeignConfig(m_threadContext.core, config); + m_audioProcessor->setInput(&m_threadContext); threadContinue(); } }

@@ -680,9 +681,9 @@

void GameController::setFPSTarget(float fps) { threadInterrupt(); m_fpsTarget = fps; - // TODO: Put back fpsTarget + m_threadContext.sync.fpsTarget = fps; if (m_turbo && m_turboSpeed > 0) { - // TODO: Put back fpsTarget + m_threadContext.sync.fpsTarget *= m_turboSpeed; } if (m_audioProcessor) { redoSamples(m_audioProcessor->getBufferSamples());

@@ -805,15 +806,15 @@

void GameController::enableTurbo() { threadInterrupt(); if (!m_turbo) { - // TODO: Put back fpsTarget + m_threadContext.sync.fpsTarget = m_fpsTarget; m_threadContext.sync.audioWait = m_audioSync; m_threadContext.sync.videoFrameWait = m_videoSync; } else if (m_turboSpeed <= 0) { - // TODO: Put back fpsTarget + m_threadContext.sync.fpsTarget = m_fpsTarget; m_threadContext.sync.audioWait = false; m_threadContext.sync.videoFrameWait = false; } else { - // TODO: Put back fpsTarget + m_threadContext.sync.fpsTarget = m_fpsTarget * m_turboSpeed; m_threadContext.sync.audioWait = true; m_threadContext.sync.videoFrameWait = false; }

@@ -927,7 +928,6 @@ }

} void GameController::redoSamples(int samples) { - // TODO: Put back audio buffers if (m_threadContext.core) { m_threadContext.core->setAudioBufferSize(m_threadContext.core, samples); }
M src/platform/sdl/sdl-audio.csrc/platform/sdl/sdl-audio.c

@@ -38,15 +38,8 @@ return false;

} context->samples = context->obtainedSpec.samples; context->core = 0; - context->thread = 0; if (threadContext) { - context->thread = threadContext; - float ratio = GBAAudioCalculateRatio(0x8000, threadContext->fpsTarget, 44100); - threadContext->audioBuffers = context->samples / ratio; - if (context->samples > threadContext->audioBuffers) { - threadContext->audioBuffers = context->samples * 2; - } context->sync = &threadContext->sync; #if SDL_VERSION_ATLEAST(2, 0, 0)

@@ -91,7 +84,7 @@ }

static void _mSDLAudioCallback(void* context, Uint8* data, int len) { struct mSDLAudio* audioContext = context; - if (!context || (!audioContext->core && !audioContext->thread)) { + if (!context || !audioContext->core) { memset(data, 0, len); return; }

@@ -102,16 +95,12 @@ if (audioContext->core) {

left = audioContext->core->getAudioChannel(audioContext->core, 0); right = audioContext->core->getAudioChannel(audioContext->core, 1); clockRate = audioContext->core->frequency(audioContext->core); - } else if (audioContext->thread) { - left = audioContext->thread->gba->audio.psg.left; - right = audioContext->thread->gba->audio.psg.right; - clockRate = GBA_ARM7TDMI_FREQUENCY; } double fauxClock = 1; - if (audioContext->thread) { - fauxClock = GBAAudioCalculateRatio(1, audioContext->thread->fpsTarget, 1); - } if (audioContext->sync) { + if (audioContext->sync->fpsTarget > 0) { + fauxClock = GBAAudioCalculateRatio(1, audioContext->sync->fpsTarget, 1); + } mCoreSyncLockAudio(audioContext->sync); } blip_set_rates(left, clockRate, audioContext->obtainedSpec.freq * fauxClock);