From ceda9a8058bb9b3c39320c0ffeb4428f93158978 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 17 May 2021 15:36:14 -0500 Subject: [PATCH] the final volume fix i think all 5 test cases pass --- src/engine/platform/sms.cpp | 6 +++--- src/engine/playback.cpp | 11 +++++------ src/ta-utils.h | 5 ++++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/engine/platform/sms.cpp b/src/engine/platform/sms.cpp index 8dc2d6f0e..24d89ce08 100644 --- a/src/engine/platform/sms.cpp +++ b/src/engine/platform/sms.cpp @@ -14,7 +14,7 @@ void DivPlatformSMS::tick() { chan[i].std.next(); if (chan[i].std.hadVol) { chan[i].outVol=(chan[i].vol*chan[i].std.vol)>>4; - sn->write(0x90|(i<<5)|(15-chan[i].outVol)); + sn->write(0x90|(i<<5)|(15-(chan[i].outVol&15))); } if (chan[i].std.hadArp) { if (chan[i].std.arpMode) { @@ -81,7 +81,7 @@ int DivPlatformSMS::dispatch(DivCommand c) { chan[c.chan].freqChanged=true; chan[c.chan].note=c.value; chan[c.chan].active=true; - sn->write(0x90|c.chan<<5|(15-chan[c.chan].vol)); + sn->write(0x90|c.chan<<5|(15-(chan[c.chan].vol&15))); chan[c.chan].std.init(parent->getIns(chan[c.chan].ins)); break; case DIV_CMD_NOTE_OFF: @@ -99,7 +99,7 @@ int DivPlatformSMS::dispatch(DivCommand c) { if (!chan[c.chan].std.hasVol) { chan[c.chan].outVol=c.value; } - sn->write(0x90|c.chan<<5|(15-chan[c.chan].vol)); + sn->write(0x90|c.chan<<5|(15-(chan[c.chan].vol&15))); } break; case DIV_CMD_GET_VOLUME: diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 320ae5784..e7eef2737 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -134,7 +134,7 @@ void DivEngine::processRow(int i, bool afterDelay) { // volume if (pat->data[curRow][3]!=-1) { - if ((chan[i].volume>>8)!=pat->data[curRow][3]) { + if ((min(chan[i].volMax,chan[i].volume)>>8)!=pat->data[curRow][3]) { chan[i].volume=pat->data[curRow][3]<<8; dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); } @@ -242,7 +242,7 @@ void DivEngine::processRow(int i, bool afterDelay) { if (chan[i].legato) { dispatch->dispatch(DivCommand(DIV_CMD_LEGATO,i,chan[i].note)); } else { - dispatch->dispatch(DivCommand(DIV_CMD_NOTE_ON,i,chan[i].note)); + dispatch->dispatch(DivCommand(DIV_CMD_NOTE_ON,i,chan[i].note,chan[i].volume>>8)); } chan[i].doNote=false; } @@ -344,16 +344,15 @@ void DivEngine::nextTick() { } } if (chan[i].volSpeed!=0) { - //chan[i].volume=(chan[i].volume&0xff)|(dispatch->dispatch(DivCommand(DIV_CMD_GET_VOLUME,i))<<8); + chan[i].volume=(chan[i].volume&0xff)|(dispatch->dispatch(DivCommand(DIV_CMD_GET_VOLUME,i))<<8); chan[i].volume+=chan[i].volSpeed; if (chan[i].volume>chan[i].volMax) { chan[i].volume=chan[i].volMax; - chan[i].volSpeed=0; dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); } else if (chan[i].volume<0) { chan[i].volSpeed=0; - chan[i].volume=chan[i].volMax; - dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,0)); + chan[i].volume=chan[i].volMax+0x100; + dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); } else { dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); } diff --git a/src/ta-utils.h b/src/ta-utils.h index 23acd3c5b..ecc5dbf2b 100644 --- a/src/ta-utils.h +++ b/src/ta-utils.h @@ -6,4 +6,7 @@ typedef std::string String; -#endif \ No newline at end of file +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) + +#endif