From 3eec0defce6312003676c642440a2e3ba607e396 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sun, 6 Dec 2020 21:17:56 +0100 Subject: [PATCH] improved playback sound muting --- src/common/RewindManager.hxx | 1 + src/emucore/FrameBuffer.cxx | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/RewindManager.hxx b/src/common/RewindManager.hxx index 5f53083f7..d1087478a 100644 --- a/src/common/RewindManager.hxx +++ b/src/common/RewindManager.hxx @@ -158,6 +158,7 @@ class RewindManager uInt64 getFirstCycles() const; uInt64 getCurrentCycles() const; uInt64 getLastCycles() const; + uInt64 getInterval() const { return myInterval; } /** Get a collection of cycle timestamps, offset from the first one in diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index a1b1ba294..c1012797b 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -450,14 +450,17 @@ void FrameBuffer::update(UpdateMode mode) success = r.unwindStates(1); + // Determine playback speed, the faster the more the statess are apart Int64 frameCycles = 76 * std::max(myOSystem.console().tia().scanlinesLastFrame(), 240); + Int32 intervalFrames = r.getInterval() / frameCycles; + Int32 stateFrames = (r.getCurrentCycles() - prevCycles) / frameCycles; - // Use time between previous and current state - // to playback larger state gaps faster - frames = std::sqrt((r.getCurrentCycles() - prevCycles) / frameCycles); + //frames = intervalFrames + std::sqrt(std::max(stateFrames - intervalFrames, 0)); + frames = std::round(std::sqrt(stateFrames)); - // TODO: test and verify with CS - //myOSystem.sound().mute(uInt32(frames) > myOSystem.audioSettings().headroom() / 2 + 1); + // Mute sound if saved states were removed or states are too far apart + myOSystem.sound().mute(stateFrames > intervalFrames + || frames > myOSystem.audioSettings().bufferSize() / 2 + 1); } redraw |= success; if(redraw) @@ -468,6 +471,7 @@ void FrameBuffer::update(UpdateMode mode) if(!success) { frames = 0; + myOSystem.sound().mute(true); myOSystem.eventHandler().enterMenuMode(EventHandlerState::TIMEMACHINE); } break; // EventHandlerState::PLAYBACK