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
This commit is contained in:
tildearrow 2021-05-17 03:06:45 -05:00
parent 53975349e5
commit 67847d79cf
6 changed files with 69 additions and 18 deletions

View file

@ -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,

View file

@ -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;
}

View file

@ -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 {
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);
}
}
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;
}

View file

@ -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,13 +56,23 @@ 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;
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));
}
}
}
}
int DivPlatformSMS::dispatch(DivCommand c) {
switch (c.cmd) {
@ -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;

View file

@ -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;

View file

@ -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;