all repos — mgba @ 712b0ccb84a9e532b8725276365de7780a875d0f

mGBA Game Boy Advance Emulator

Qt: Ensure proper audio sample rate is used when resampling audio
Jeffrey Pfau jeffrey@endrift.com
Sun, 12 Jul 2015 00:19:17 -0700
commit

712b0ccb84a9e532b8725276365de7780a875d0f

parent

9d7b79db2798ae6d29aa6eca5fb651ea686ca471

M src/platform/qt/AudioProcessor.hsrc/platform/qt/AudioProcessor.h

@@ -39,6 +39,8 @@

virtual void setBufferSamples(int samples) = 0; virtual void inputParametersChanged() = 0; + virtual unsigned sampleRate() const = 0; + protected: GBAThread* input() { return m_context; }
M src/platform/qt/AudioProcessorQt.cppsrc/platform/qt/AudioProcessorQt.cpp

@@ -83,3 +83,10 @@ if (m_device) {

m_device->setFormat(m_audioOutput->format()); } } + +unsigned AudioProcessorQt::sampleRate() const { + if (!m_audioOutput) { + return 0; + } + return m_audioOutput->format().sampleRate(); +}
M src/platform/qt/AudioProcessorQt.hsrc/platform/qt/AudioProcessorQt.h

@@ -28,6 +28,8 @@

virtual void setBufferSamples(int samples); virtual void inputParametersChanged(); + virtual unsigned sampleRate() const override; + private: QAudioOutput* m_audioOutput; AudioDevice* m_device;
M src/platform/qt/AudioProcessorSDL.cppsrc/platform/qt/AudioProcessorSDL.cpp

@@ -54,3 +54,7 @@ }

void AudioProcessorSDL::inputParametersChanged() { } + +unsigned AudioProcessorSDL::sampleRate() const { + return m_audio.obtainedSpec.freq; +}
M src/platform/qt/AudioProcessorSDL.hsrc/platform/qt/AudioProcessorSDL.h

@@ -29,6 +29,8 @@

virtual void setBufferSamples(int samples); virtual void inputParametersChanged(); + virtual unsigned sampleRate() const override; + private: GBASDLAudio m_audio; };
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -746,7 +746,7 @@ float ratio;

if (m_threadContext.gba) { sampleRate = m_threadContext.gba->audio.sampleRate; } - ratio = GBAAudioCalculateRatio(sampleRate, m_threadContext.fpsTarget, 44100); + ratio = GBAAudioCalculateRatio(sampleRate, m_threadContext.fpsTarget, m_audioProcess->sampleRate()); m_threadContext.audioBuffers = ceil(samples / ratio); #else m_threadContext.audioBuffers = samples;