diff --git a/src/platform/qt/AudioDevice.cpp b/src/platform/qt/AudioDevice.cpp index 67f751359..0a7e0ec99 100644 --- a/src/platform/qt/AudioDevice.cpp +++ b/src/platform/qt/AudioDevice.cpp @@ -20,7 +20,7 @@ void AudioDevice::setFormat(const QAudioFormat& format) { return; } // TODO: make this thread-safe - m_ratio = GBAAudioCalculateRatio(&m_context->gba->audio, 60, format.sampleRate()); + m_ratio = GBAAudioCalculateRatio(&m_context->gba->audio, m_context->fpsTarget, format.sampleRate()); } void AudioDevice::setInput(GBAThread* input) { diff --git a/src/platform/qt/AudioProcessor.cpp b/src/platform/qt/AudioProcessor.cpp index a4ff868d0..9c522134d 100644 --- a/src/platform/qt/AudioProcessor.cpp +++ b/src/platform/qt/AudioProcessor.cpp @@ -61,3 +61,7 @@ void AudioProcessor::setBufferSamples(int samples) { QAudioFormat format = m_audioOutput->format(); m_audioOutput->setBufferSize(samples * format.channelCount() * format.sampleSize() / 8); } + +void AudioProcessor::inputParametersChanged() { + m_device->setFormat(m_audioOutput->format()); +} diff --git a/src/platform/qt/AudioProcessor.h b/src/platform/qt/AudioProcessor.h index 0a4e8fe68..f458bf349 100644 --- a/src/platform/qt/AudioProcessor.h +++ b/src/platform/qt/AudioProcessor.h @@ -23,6 +23,7 @@ public slots: void pause(); void setBufferSamples(int samples); + void inputParametersChanged(); private: GBAThread* m_context; diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 172433a6d..13ab82f25 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -181,6 +181,13 @@ void GameController::setAudioBufferSamples(int samples) { QMetaObject::invokeMethod(m_audioProcessor, "setBufferSamples", Q_ARG(int, samples)); } +void GameController::setFPSTarget(float fps) { + GBAThreadInterrupt(&m_threadContext); + m_threadContext.fpsTarget = fps; + GBAThreadContinue(&m_threadContext); + QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged"); +} + void GameController::updateKeys() { int activeKeys = m_activeKeys; #ifdef BUILD_SDL diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 251d00d40..bc27acd07 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -55,6 +55,7 @@ public slots: void keyPressed(int key); void keyReleased(int key); void setAudioBufferSamples(int samples); + void setFPSTarget(float fps); #ifdef BUILD_SDL private slots: diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 792e5b5e4..1b56d36c9 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -29,6 +29,7 @@ Window::Window(QWidget* parent) connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection); connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing())); connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int))); + connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); setupMenu(menuBar()); } @@ -167,6 +168,29 @@ void Window::setupMenu(QMenuBar* menubar) { m_gameActions.append(frameAdvance); emulationMenu->addAction(frameAdvance); + QMenu* target = emulationMenu->addMenu("FPS target"); + QAction* setTarget = new QAction(tr("15"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(15); }); + target->addAction(setTarget); + setTarget = new QAction(tr("30"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(30); }); + target->addAction(setTarget); + setTarget = new QAction(tr("45"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(45); }); + target->addAction(setTarget); + setTarget = new QAction(tr("60"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(60); }); + target->addAction(setTarget); + setTarget = new QAction(tr("90"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(90); }); + target->addAction(setTarget); + setTarget = new QAction(tr("120"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(120); }); + target->addAction(setTarget); + setTarget = new QAction(tr("240"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(240); }); + target->addAction(setTarget); + QMenu* soundMenu = menubar->addMenu(tr("&Sound")); QMenu* buffersMenu = soundMenu->addMenu(tr("Buffer &size")); QAction* setBuffer = new QAction(tr("512"), nullptr); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index fa266e8ee..27927ee33 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -40,6 +40,7 @@ protected: signals: void audioBufferSamplesChanged(int samples); + void fpsTargetChanged(float target); private slots: void gameStarted(GBAThread*);