From ad000bc0c0592899eb7e6ad112451cf36cfb0486 Mon Sep 17 00:00:00 2001 From: Adam Lederer Date: Fri, 6 Sep 2024 16:27:51 -0700 Subject: [PATCH] fix: volume portamento no longer cancels set vol in case where volume portamento was active but not complete, using the volume column to set volume to a point past the volume portamento target would be detected as "volume portamento complete" and set volume to the portamento target, even if the portamento target was actually lower/higher than the volume set by the volume command --- src/engine/cmdStream.cpp | 7 ++++++- src/engine/playback.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/cmdStream.cpp b/src/engine/cmdStream.cpp index 40542ef98..f1b267869 100644 --- a/src/engine/cmdStream.cpp +++ b/src/engine/cmdStream.cpp @@ -364,6 +364,7 @@ bool DivCSPlayer::tick() { } if (sendVolume || chan[i].volSpeed!=0) { + int preSpeedVol=chan[i].volume; chan[i].volume+=chan[i].volSpeed; if (chan[i].volSpeedTarget!=-1) { bool atTarget=false; @@ -377,7 +378,11 @@ bool DivCSPlayer::tick() { } if (atTarget) { - chan[i].volume=chan[i].volSpeedTarget; + if (chan[i].volSpeed>0) { + chan[i].volume=MAX(preSpeedVol,chan[i].volSpeedTarget); + } else if (chan[i].volSpeed<0) { + chan[i].volume=MIN(preSpeedVol,chan[i].volSpeedTarget); + } chan[i].volSpeed=0; chan[i].volSpeedTarget=-1; } diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index c1e14109e..2dcb838fb 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -1648,6 +1648,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { if (!song.noSlidesOnFirstTick || !firstTick) { if (chan[i].volSpeed!=0) { chan[i].volume=(chan[i].volume&0xff)|(dispatchCmd(DivCommand(DIV_CMD_GET_VOLUME,i))<<8); + int preSpeedVol=chan[i].volume; chan[i].volume+=chan[i].volSpeed; if (chan[i].volSpeedTarget!=-1) { bool atTarget=false; @@ -1661,7 +1662,11 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { } if (atTarget) { - chan[i].volume=chan[i].volSpeedTarget; + if (chan[i].volSpeed>0) { + chan[i].volume=MAX(preSpeedVol,chan[i].volSpeedTarget); + } else if (chan[i].volSpeed<0) { + chan[i].volume=MIN(preSpeedVol,chan[i].volSpeedTarget); + } chan[i].volSpeed=0; chan[i].volSpeedTarget=-1; dispatchCmd(DivCommand(DIV_CMD_HINT_VOLUME,i,chan[i].volume>>8));