From 6e49d1fe122966ae4349ef5f9b65bae94ed29a92 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Fri, 15 Oct 2021 12:10:00 +0200 Subject: [PATCH] disable audio sample saving when TimeMachine is disabled (fixes #835) --- src/emucore/Console.cxx | 2 ++ src/emucore/EventHandler.cxx | 2 +- src/emucore/OSystem.cxx | 7 +++++++ src/emucore/OSystem.hxx | 7 +++++++ src/emucore/tia/Audio.cxx | 3 ++- src/emucore/tia/Audio.hxx | 12 ++++++++++++ src/emucore/tia/TIA.cxx | 6 ++++++ src/emucore/tia/TIA.hxx | 6 ++++++ src/gui/CommandDialog.cxx | 2 +- src/gui/TimeMachineDialog.cxx | 2 +- 10 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 791e982dd..9cbe63da0 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -49,6 +49,7 @@ #include "SaveKey.hxx" #include "Settings.hxx" #include "Sound.hxx" +#include "StateManager.hxx" #include "Switches.hxx" #include "System.hxx" #include "FrameBuffer.hxx" @@ -659,6 +660,7 @@ void Console::initializeAudio() createAudioQueue(); myTIA->setAudioQueue(myAudioQueue); + myTIA->setAudioRewindMode(myOSystem.state().mode() != StateManager::Mode::Off); myOSystem.sound().open(myAudioQueue, &myEmulationTiming); } diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 01c85a285..a8fc3fe06 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1850,7 +1850,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) return; case Event::ToggleTimeMachine: - if (pressed && !repeated) myOSystem.state().toggleTimeMachine(); + if (pressed && !repeated) myOSystem.toggleTimeMachine(); return; #ifdef PNG_SUPPORT diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 80ce13a7c..dd9f438f1 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -596,6 +596,13 @@ string OSystem::getROMInfo(const FilesystemNode& romfile) return getROMInfo(*console); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void OSystem::toggleTimeMachine() +{ + myStateManager->toggleTimeMachine(); + myConsole->tia().setAudioRewindMode(myStateManager->mode() != StateManager::Mode::Off); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystem::resetFps() { diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index ec7a15e53..4db8d7f0e 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -388,6 +388,13 @@ class OSystem */ string getROMInfo(const FilesystemNode& romfile); + /** + Toggle state rewind recording mode; this uses the RewindManager + for its functionality. Also makes sure that audio samples are + only saved if the recording mode is enabled. + */ + void toggleTimeMachine(); + /** The features which are conditionally compiled into Stella. diff --git a/src/emucore/tia/Audio.cxx b/src/emucore/tia/Audio.cxx index 9e79243fb..8ba176fa0 100644 --- a/src/emucore/tia/Audio.cxx +++ b/src/emucore/tia/Audio.cxx @@ -88,7 +88,8 @@ void Audio::phase1() addSample(sample0, sample1); #ifdef GUI_SUPPORT - mySamples.push_back(sample0 | (sample1 << 4)); + if(myRewindMode) + mySamples.push_back(sample0 | (sample1 << 4)); #endif } diff --git a/src/emucore/tia/Audio.hxx b/src/emucore/tia/Audio.hxx index 657cb7c21..c2ed274f5 100644 --- a/src/emucore/tia/Audio.hxx +++ b/src/emucore/tia/Audio.hxx @@ -33,6 +33,17 @@ class Audio : public Serializable void setAudioQueue(const shared_ptr& queue); + /** + Enable/disable pushing audio samples. These are required for TimeMachine + playback with sound. + */ + void setAudioRewindMode(bool enable) + { + #ifdef GUI_SUPPORT + myRewindMode = enable; + #endif + } + void tick(); AudioChannel& channel0(); @@ -63,6 +74,7 @@ class Audio : public Serializable Int16* myCurrentFragment{nullptr}; uInt32 mySampleIndex{0}; #ifdef GUI_SUPPORT + bool myRewindMode{false}; mutable ByteArray mySamples; #endif diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 323beab05..9b0cb65e5 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -113,6 +113,12 @@ void TIA::setAudioQueue(const shared_ptr& queue) myAudio.setAudioQueue(queue); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TIA::setAudioRewindMode(bool enable) +{ + myAudio.setAudioRewindMode(enable); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::clearFrameManager() { diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 2913a0cde..59826edc4 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -131,6 +131,12 @@ class TIA : public Device */ void setAudioQueue(const shared_ptr& audioQueue); + /** + Enable/disable pushing audio samples. These are required for TimeMachine + playback with sound. + */ + void setAudioRewindMode(bool enable); + /** Clear the configured frame manager and deteach the lifecycle callbacks. */ diff --git a/src/gui/CommandDialog.cxx b/src/gui/CommandDialog.cxx index 35407b62c..3c2db3a7f 100644 --- a/src/gui/CommandDialog.cxx +++ b/src/gui/CommandDialog.cxx @@ -189,7 +189,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd, case kTimeMachineCmd: instance().eventHandler().leaveMenuMode(); - instance().state().toggleTimeMachine(); + instance().toggleTimeMachine(); break; case kExitCmd: diff --git a/src/gui/TimeMachineDialog.cxx b/src/gui/TimeMachineDialog.cxx index d5c6b8fa6..a8ad6db75 100644 --- a/src/gui/TimeMachineDialog.cxx +++ b/src/gui/TimeMachineDialog.cxx @@ -418,7 +418,7 @@ void TimeMachineDialog::handleCommand(CommandSender* sender, int cmd, } case kToggle: - instance().state().toggleTimeMachine(); + instance().toggleTimeMachine(); handleToggle(); break;