all repos — mgba @ 280c8033053ebc3b58d69508e703c0e1fefe39c6

mGBA Game Boy Advance Emulator

Qt: Fix FPS target and SDL initialization audio issues
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Dec 2014 21:58:29 -0800
commit

280c8033053ebc3b58d69508e703c0e1fefe39c6

parent

5b3a2e04b1d46152fc6e6307bf9ceaefdd6e8ff4

M src/platform/qt/AudioProcessor.cppsrc/platform/qt/AudioProcessor.cpp

@@ -33,3 +33,7 @@

void AudioProcessor::setInput(GBAThread* input) { m_context = input; } + +void AudioProcessor::setBufferSamples(int samples) { + m_samples = samples; +}
M src/platform/qt/AudioProcessor.hsrc/platform/qt/AudioProcessor.h

@@ -19,6 +19,7 @@ static AudioProcessor* create();

AudioProcessor(QObject* parent = nullptr); virtual void setInput(GBAThread* input); + int getBufferSamples() const { return m_samples; } public slots: virtual void start() = 0;

@@ -29,8 +30,10 @@ virtual void inputParametersChanged() = 0;

protected: GBAThread* input() { return m_context; } + private: GBAThread* m_context; + int m_samples; }; }
M src/platform/qt/AudioProcessorQt.cppsrc/platform/qt/AudioProcessorQt.cpp

@@ -63,6 +63,7 @@ }

} void AudioProcessorQt::setBufferSamples(int samples) { + AudioProcessor::setBufferSamples(samples); if (m_audioOutput) { m_audioOutput->stop(); m_audioOutput->setBufferSize(samples * 4);
M src/platform/qt/AudioProcessorSDL.cppsrc/platform/qt/AudioProcessorSDL.cpp

@@ -25,7 +25,9 @@ void AudioProcessorSDL::start() {

if (m_audio.thread) { GBASDLResumeAudio(&m_audio); } else { - m_audio.samples = input()->audioBuffers; + if (!m_audio.samples) { + m_audio.samples = input()->audioBuffers; + } GBASDLInitAudio(&m_audio, input()); } }

@@ -35,9 +37,10 @@ GBASDLPauseAudio(&m_audio);

} void AudioProcessorSDL::setBufferSamples(int samples) { + AudioProcessor::setBufferSamples(samples); + m_audio.samples = samples; if (m_audio.thread) { GBASDLDeinitAudio(&m_audio); - m_audio.samples = samples; GBASDLInitAudio(&m_audio, input()); } }
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -276,23 +276,16 @@ updateKeys();

} void GameController::setAudioBufferSamples(int samples) { - if (m_gameOpen) { - threadInterrupt(); - float ratio = GBAAudioCalculateRatio(m_threadContext.gba->audio.sampleRate, m_threadContext.fpsTarget, 44100); - m_threadContext.audioBuffers = samples / ratio; - GBAAudioResizeBuffer(&m_threadContext.gba->audio, samples / ratio); - threadContinue(); - } else { - float ratio = GBAAudioCalculateRatio(0x8000, m_threadContext.fpsTarget, 44100); - m_threadContext.audioBuffers = samples / ratio; - - } + threadInterrupt(); + redoSamples(samples); + threadContinue(); QMetaObject::invokeMethod(m_audioProcessor, "setBufferSamples", Q_ARG(int, samples)); } void GameController::setFPSTarget(float fps) { threadInterrupt(); m_threadContext.fpsTarget = fps; + redoSamples(m_audioProcessor->getBufferSamples()); threadContinue(); QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged"); }

@@ -373,6 +366,19 @@ #ifdef BUILD_SDL

activeKeys |= m_activeButtons; #endif m_threadContext.activeKeys = activeKeys; +} + +void GameController::redoSamples(int samples) { + float sampleRate = 0x8000; + float ratio; + if (m_threadContext.gba) { + sampleRate = m_threadContext.gba->audio.sampleRate; + } + ratio = GBAAudioCalculateRatio(sampleRate, m_threadContext.fpsTarget, 44100); + m_threadContext.audioBuffers = ceil(samples / ratio); + if (m_threadContext.gba) { + GBAAudioResizeBuffer(&m_threadContext.gba->audio, m_threadContext.audioBuffers); + } } void GameController::setLogLevel(int levels) {
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -109,6 +109,7 @@ #endif

private: void updateKeys(); + void redoSamples(int samples); uint32_t* m_drawContext; GBAThread m_threadContext;