all repos — mgba @ 24094ecdf04cdeda17711141a27bfa0bc30de467

mGBA Game Boy Advance Emulator

Make audo/video sync adjustable externally
Jeffrey Pfau jeffrey@endrift.com
Sun, 19 Oct 2014 00:50:23 -0700
commit

24094ecdf04cdeda17711141a27bfa0bc30de467

parent

ad12bdde9d34ecd477b33e02d02d8d41c115b817

3 files changed, 40 insertions(+), 2 deletions(-)

jump to
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -22,6 +22,8 @@ , m_activeKeys(0)

, 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::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)) {

@@ -231,6 +233,20 @@

void GameController::saveState(int slot) { GBAThreadInterrupt(&m_threadContext); GBASaveState(m_threadContext.gba, m_threadContext.stateDir, slot, true); + 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); }
M src/platform/qt/GameController.hsrc/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 @@ void setAudioBufferSamples(int samples);

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 @@ AudioProcessor* m_audioProcessor;

QMutex m_pauseMutex; bool m_pauseAfterFrame; + + bool m_videoSync; + bool m_audioSync; }; }
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -357,6 +357,20 @@ setTarget = new QAction(tr("240"), emulationMenu);

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);