From 2982a401104402769d694b134633c7f60758ee72 Mon Sep 17 00:00:00 2001 From: Adam Lederer Date: Sat, 24 Aug 2024 00:59:03 -0700 Subject: [PATCH] update vol-porta-ending logic to be more readable --- src/engine/cmdStream.cpp | 20 ++++++++++++++++---- src/engine/playback.cpp | 29 +++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/engine/cmdStream.cpp b/src/engine/cmdStream.cpp index 5f369b211..40542ef98 100644 --- a/src/engine/cmdStream.cpp +++ b/src/engine/cmdStream.cpp @@ -365,10 +365,22 @@ bool DivCSPlayer::tick() { if (sendVolume || chan[i].volSpeed!=0) { chan[i].volume+=chan[i].volSpeed; - if (chan[i].volSpeedTarget!=-1 && (chan[i].volume==chan[i].volSpeedTarget || (chan[i].volume>chan[i].volSpeedTarget)==(chan[i].volSpeed>0))) { - chan[i].volume=chan[i].volSpeedTarget; - chan[i].volSpeed=0; - chan[i].volSpeedTarget=-1; + if (chan[i].volSpeedTarget!=-1) { + bool atTarget=false; + if (chan[i].volSpeed>0) { + atTarget=(chan[i].volume>=chan[i].volSpeedTarget); + } else if (chan[i].volSpeed<0) { + atTarget=(chan[i].volume<=chan[i].volSpeedTarget); + } else { + atTarget=true; + chan[i].volSpeedTarget=chan[i].volume; + } + + if (atTarget) { + chan[i].volume=chan[i].volSpeedTarget; + chan[i].volSpeed=0; + chan[i].volSpeedTarget=-1; + } } if (chan[i].volume<0) { chan[i].volume=0; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 2c7e97e0e..296183f8c 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -1631,14 +1631,27 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { if (chan[i].volSpeed!=0) { chan[i].volume=(chan[i].volume&0xff)|(dispatchCmd(DivCommand(DIV_CMD_GET_VOLUME,i))<<8); chan[i].volume+=chan[i].volSpeed; - if (chan[i].volSpeedTarget!=-1 && (chan[i].volume==chan[i].volSpeedTarget || (chan[i].volume>chan[i].volSpeedTarget)==(chan[i].volSpeed>0))) { - chan[i].volume=chan[i].volSpeedTarget; - chan[i].volSpeed=0; - chan[i].volSpeedTarget=-1; - dispatchCmd(DivCommand(DIV_CMD_HINT_VOLUME,i,chan[i].volume>>8)); - dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); - dispatchCmd(DivCommand(DIV_CMD_HINT_VOL_SLIDE,i,0)); - } else if (chan[i].volume>chan[i].volMax) { + if (chan[i].volSpeedTarget!=-1) { + bool atTarget=false; + if (chan[i].volSpeed>0) { + atTarget=(chan[i].volume>=chan[i].volSpeedTarget); + } else if (chan[i].volSpeed<0) { + atTarget=(chan[i].volume<=chan[i].volSpeedTarget); + } else { + atTarget=true; + chan[i].volSpeedTarget=chan[i].volume; + } + + if (atTarget) { + chan[i].volume=chan[i].volSpeedTarget; + chan[i].volSpeed=0; + chan[i].volSpeedTarget=-1; + dispatchCmd(DivCommand(DIV_CMD_HINT_VOLUME,i,chan[i].volume>>8)); + dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); + dispatchCmd(DivCommand(DIV_CMD_HINT_VOL_SLIDE,i,0)); + } + } + if (chan[i].volume>chan[i].volMax) { chan[i].volume=chan[i].volMax; chan[i].volSpeed=0; chan[i].volSpeedTarget=-1;