From 24094ecdf04cdeda17711141a27bfa0bc30de467 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 19 Oct 2014 00:50:23 -0700 Subject: [PATCH] Make audo/video sync adjustable externally --- src/platform/qt/GameController.cpp | 20 ++++++++++++++++++-- src/platform/qt/GameController.h | 8 ++++++++ src/platform/qt/Window.cpp | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 4a5b518b2..c79afb891 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -22,6 +22,8 @@ GameController::GameController(QObject* parent) , m_gameOpen(false) , m_audioThread(new QThread(this)) , m_audioProcessor(new AudioProcessor) + , m_videoSync(VIDEO_SYNC) + , m_audioSync(AUDIO_SYNC) { m_renderer = new GBAVideoSoftwareRenderer; GBAVideoSoftwareRendererCreate(m_renderer); @@ -115,8 +117,8 @@ void GameController::setDebugger(ARMDebugger* debugger) { void GameController::loadGame(const QString& path, bool dirmode) { closeGame(); - m_threadContext.sync.videoFrameWait = 0; - m_threadContext.sync.audioWait = 1; + m_threadContext.sync.videoFrameWait = m_videoSync; + m_threadContext.sync.audioWait = m_audioSync; if (!dirmode) { QFile file(path); if (!file.open(QIODevice::ReadOnly)) { @@ -234,6 +236,20 @@ void GameController::saveState(int slot) { GBAThreadContinue(&m_threadContext); } +void GameController::setVideoSync(bool set) { + m_videoSync = set; + GBAThreadInterrupt(&m_threadContext); + m_threadContext.sync.videoFrameWait = set; + GBAThreadContinue(&m_threadContext); +} + +void GameController::setAudioSync(bool set) { + m_audioSync = set; + GBAThreadInterrupt(&m_threadContext); + m_threadContext.sync.audioWait = set; + GBAThreadContinue(&m_threadContext); +} + 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 0405354d4..1371e3a6a 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -27,6 +27,9 @@ class GameController : public QObject { Q_OBJECT public: + static const bool VIDEO_SYNC = false; + static const bool AUDIO_SYNC = true; + GameController(QObject* parent = nullptr); ~GameController(); @@ -64,6 +67,8 @@ public slots: void setFPSTarget(float fps); void loadState(int slot); void saveState(int slot); + void setVideoSync(bool); + void setAudioSync(bool); #ifdef BUILD_SDL private slots: @@ -90,6 +95,9 @@ private: QMutex m_pauseMutex; bool m_pauseAfterFrame; + + bool m_videoSync; + bool m_audioSync; }; } diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 9c7813347..3d910e3f3 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -357,6 +357,20 @@ void Window::setupMenu(QMenuBar* menubar) { connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(240); }); target->addAction(setTarget); + emulationMenu->addSeparator(); + + QAction* videoSync = new QAction(tr("Sync to &video"), emulationMenu); + videoSync->setCheckable(true); + videoSync->setChecked(GameController::VIDEO_SYNC); + connect(videoSync, SIGNAL(triggered(bool)), m_controller, SLOT(setVideoSync(bool))); + emulationMenu->addAction(videoSync); + + QAction* audioSync = new QAction(tr("Sync to &audio"), emulationMenu); + audioSync->setCheckable(true); + audioSync->setChecked(GameController::AUDIO_SYNC); + connect(audioSync, SIGNAL(triggered(bool)), m_controller, SLOT(setAudioSync(bool))); + emulationMenu->addAction(audioSync); + QMenu* videoMenu = menubar->addMenu(tr("&Video")); QMenu* frameMenu = videoMenu->addMenu(tr("Frame &size")); QAction* setSize = new QAction(tr("1x"), videoMenu);