mirror of https://github.com/mgba-emu/mgba.git
Qt: Fix FPS target and SDL initialization audio issues
This commit is contained in:
parent
5b3a2e04b1
commit
280c803305
|
@ -33,3 +33,7 @@ AudioProcessor::AudioProcessor(QObject* parent)
|
|||
void AudioProcessor::setInput(GBAThread* input) {
|
||||
m_context = input;
|
||||
}
|
||||
|
||||
void AudioProcessor::setBufferSamples(int samples) {
|
||||
m_samples = samples;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public:
|
|||
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 @@ public slots:
|
|||
|
||||
protected:
|
||||
GBAThread* input() { return m_context; }
|
||||
|
||||
private:
|
||||
GBAThread* m_context;
|
||||
int m_samples;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ void AudioProcessorQt::pause() {
|
|||
}
|
||||
|
||||
void AudioProcessorQt::setBufferSamples(int samples) {
|
||||
AudioProcessor::setBufferSamples(samples);
|
||||
if (m_audioOutput) {
|
||||
m_audioOutput->stop();
|
||||
m_audioOutput->setBufferSize(samples * 4);
|
||||
|
|
|
@ -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 @@ void AudioProcessorSDL::pause() {
|
|||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,23 +276,16 @@ void GameController::keyReleased(int key) {
|
|||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
@ -375,6 +368,19 @@ void GameController::updateKeys() {
|
|||
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) {
|
||||
threadInterrupt();
|
||||
m_logLevels = levels;
|
||||
|
|
|
@ -109,6 +109,7 @@ private:
|
|||
|
||||
private:
|
||||
void updateKeys();
|
||||
void redoSamples(int samples);
|
||||
|
||||
uint32_t* m_drawContext;
|
||||
GBAThread m_threadContext;
|
||||
|
|
Loading…
Reference in New Issue