From 67847d79cf024ac86876d908b96063f90b9a12b0 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 17 May 2021 03:06:45 -0500 Subject: [PATCH] attempt to fix the volume slide mess also a fix to noise arps in basic mode in SMS the volume slides will be an adventure as the behavior seems to be hard to determine --- src/engine/dispatch.h | 1 + src/engine/platform/dummy.cpp | 3 +++ src/engine/platform/genesis.cpp | 35 ++++++++++++++++++++++----------- src/engine/platform/sms.cpp | 32 +++++++++++++++++++++++++----- src/engine/platform/sms.h | 15 ++++++++++++-- src/engine/playback.cpp | 1 + 6 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index b76ef5ae6..fb7ce9ed5 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -8,6 +8,7 @@ enum DivDispatchCmds { DIV_CMD_NOTE_OFF, DIV_CMD_INSTRUMENT, DIV_CMD_VOLUME, + DIV_CMD_GET_VOLUME, DIV_CMD_NOTE_PORTA, DIV_CMD_PITCH, DIV_CMD_PANNING, diff --git a/src/engine/platform/dummy.cpp b/src/engine/platform/dummy.cpp index 9b6cc2b02..932342166 100644 --- a/src/engine/platform/dummy.cpp +++ b/src/engine/platform/dummy.cpp @@ -29,6 +29,9 @@ int DivPlatformDummy::dispatch(DivCommand c) { case DIV_CMD_VOLUME: chan[c.chan].vol=c.value; break; + case DIV_CMD_GET_VOLUME: + return chan[c.chan].vol; + break; default: break; } diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index c59920210..76ad9837b 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -155,23 +155,32 @@ int DivPlatformGenesis::dispatch(DivCommand c) { } DivInstrument* ins=parent->getIns(chan[c.chan].ins); + for (int i=0; i<4; i++) { unsigned short baseAddr=chanOffs[c.chan]|opOffs[i]; DivInstrumentFM::Operator op=ins->fm.op[i]; - rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4)); if (isOutput[ins->fm.alg][i]) { rWrite(baseAddr+0x40,127-(((127-op.tl)*chan[c.chan].vol)/127)); } else { - rWrite(baseAddr+0x40,op.tl); + if (chan[c.chan].insChanged) { + rWrite(baseAddr+0x40,op.tl); + } + } + if (chan[c.chan].insChanged) { + rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4)); + rWrite(baseAddr+0x50,(op.ar&31)|(op.rs<<6)); + rWrite(baseAddr+0x60,(op.dr&31)|(op.am<<7)); + rWrite(baseAddr+0x70,op.d2r&31); + rWrite(baseAddr+0x80,(op.rr&15)|(op.sl<<4)); + rWrite(baseAddr+0x90,op.ssgEnv&15); } - rWrite(baseAddr+0x50,(op.ar&31)|(op.rs<<6)); - rWrite(baseAddr+0x60,(op.dr&31)|(op.am<<7)); - rWrite(baseAddr+0x70,op.d2r&31); - rWrite(baseAddr+0x80,(op.rr&15)|(op.sl<<4)); - rWrite(baseAddr+0x90,op.ssgEnv&15); } - rWrite(chanOffs[c.chan]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3)); - rWrite(chanOffs[c.chan]+0xb4,(chan[c.chan].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4)); + if (chan[c.chan].insChanged) { + rWrite(chanOffs[c.chan]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3)); + rWrite(chanOffs[c.chan]+0xb4,(chan[c.chan].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4)); + } + chan[c.chan].insChanged=false; + chan[c.chan].baseFreq=644.0f*pow(2.0f,((float)c.value/12.0f)); chan[c.chan].freqChanged=true; chan[c.chan].keyOn=true; @@ -196,6 +205,10 @@ int DivPlatformGenesis::dispatch(DivCommand c) { } break; } + case DIV_CMD_GET_VOLUME: { + return chan[c.chan].vol; + break; + } case DIV_CMD_INSTRUMENT: if (chan[c.chan].ins!=c.value) { chan[c.chan].insChanged=true; @@ -256,9 +269,9 @@ int DivPlatformGenesis::dispatch(DivCommand c) { break; } case DIV_CMD_FM_MULT: { - unsigned short baseAddr=chanOffs[c.chan]|opOffs[c.value]; + unsigned short baseAddr=chanOffs[c.chan]|opOffs[orderedOps[c.value]]; DivInstrument* ins=parent->getIns(chan[c.chan].ins); - DivInstrumentFM::Operator op=ins->fm.op[c.value]; + DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]]; rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4)); break; } diff --git a/src/engine/platform/sms.cpp b/src/engine/platform/sms.cpp index f66210440..7e111535d 100644 --- a/src/engine/platform/sms.cpp +++ b/src/engine/platform/sms.cpp @@ -12,7 +12,10 @@ void DivPlatformSMS::acquire(int& l, int& r) { void DivPlatformSMS::tick() { for (int i=0; i<4; i++) { chan[i].std.next(); - if (chan[i].std.hadVol) sn->write(0x90|(i<<5)|(15-((chan[i].vol*chan[i].std.vol)>>4))); + 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)); + } if (chan[i].std.hadArp) { if (chan[i].std.arpMode) { chan[i].baseFreq=round(1712.0f/pow(2.0f,((float)(chan[i].std.arp)/12.0f))); @@ -53,10 +56,20 @@ void DivPlatformSMS::tick() { sn->write(0xc0|(chan[3].freq&15)); sn->write(chan[3].freq>>4); } else { // 3 fixed values - unsigned char value=chan[3].note%12; - if (value>2) value=2; - value=2-value; - sn->write(0xe0|value|((snNoiseMode&1)<<2)); + unsigned char value; + if (chan[3].std.hadArp) { + if (chan[3].std.arpMode) { + value=chan[3].std.arp%12; + } else { + value=(chan[3].note+chan[3].std.arp)%12; + } + } else { + value=chan[3].note%12; + } + if (value<3) { + value=2-value; + sn->write(0xe0|value|((snNoiseMode&1)<<2)); + } } } } @@ -83,9 +96,18 @@ int DivPlatformSMS::dispatch(DivCommand c) { case DIV_CMD_VOLUME: if (chan[c.chan].vol!=c.value) { chan[c.chan].vol=c.value; + if (!chan[c.chan].std.hasVol) { + chan[c.chan].outVol=c.value; + } sn->write(0x90|c.chan<<5|(15-chan[c.chan].vol)); } break; + case DIV_CMD_GET_VOLUME: + if (chan[c.chan].std.hasVol) { + return chan[c.chan].vol; + } + return chan[c.chan].outVol; + break; case DIV_CMD_PITCH: chan[c.chan].pitch=c.value; chan[c.chan].freqChanged=true; diff --git a/src/engine/platform/sms.h b/src/engine/platform/sms.h index 5a1a6fff6..c6e6f261e 100644 --- a/src/engine/platform/sms.h +++ b/src/engine/platform/sms.h @@ -10,9 +10,20 @@ class DivPlatformSMS: public DivDispatch { int freq, baseFreq, pitch; unsigned char ins, note; bool active, insChanged, freqChanged, keyOn, keyOff; - signed char vol; + signed char vol, outVol; DivMacroInt std; - Channel(): freq(0), baseFreq(0), pitch(0), ins(-1), note(0), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), vol(15) {} + Channel(): + freq(0), + baseFreq(0), + pitch(0), + ins(-1), + note(0), + active(false), + insChanged(true), + freqChanged(false), + keyOn(false), + keyOff(false), + vol(15) {} }; Channel chan[4]; unsigned char snNoiseMode; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 7c51c5bce..f1206ead6 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -342,6 +342,7 @@ 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].volSpeed; if (chan[i].volume>0x7f00) chan[i].volume=0x7f00; if (chan[i].volume<0) chan[i].volume=0;