Make audo/video sync adjustable externally

This commit is contained in:
Jeffrey Pfau 2014-10-19 00:50:23 -07:00
parent ad12bdde9d
commit 24094ecdf0
3 changed files with 40 additions and 2 deletions

View File

@ -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

View File

@ -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;
};
}

View File

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