diff --git a/src/engine/platform/gb.cpp b/src/engine/platform/gb.cpp index b7b2a3c13..769157163 100644 --- a/src/engine/platform/gb.cpp +++ b/src/engine/platform/gb.cpp @@ -47,8 +47,13 @@ void DivPlatformGB::tick() { } } if (chan[i].std.hadWave) { - chan[i].wave=chan[i].std.wave; - if (i==2) updateWave(); + if (chan[i].wave!=chan[i].std.wave) { + chan[i].wave=chan[i].std.wave; + if (i==2) { + updateWave(); + if (!chan[i].keyOff) chan[i].keyOn=true; + } + } } if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { chan[i].freq=(chan[i].baseFreq*(ONE_SEMITONE-chan[i].pitch))/ONE_SEMITONE; @@ -56,6 +61,10 @@ void DivPlatformGB::tick() { if (chan[i].keyOn) { DivInstrument* ins=parent->getIns(chan[i].ins); if (i==2) { // wave + if (chan[i].wave<0) { + chan[i].wave=0; + updateWave(); + } rWrite(16+i*5,0x80); rWrite(16+i*5+2,gbVolMap[chan[i].vol]); } else { @@ -94,7 +103,6 @@ int DivPlatformGB::dispatch(DivCommand c) { chan[c.chan].note=c.value; chan[c.chan].active=true; chan[c.chan].keyOn=true; - if (c.chan==2) updateWave(); chan[c.chan].std.init(parent->getIns(chan[c.chan].ins)); break; case DIV_CMD_NOTE_OFF: diff --git a/src/engine/platform/gb.h b/src/engine/platform/gb.h index d503726cf..302f7c457 100644 --- a/src/engine/platform/gb.h +++ b/src/engine/platform/gb.h @@ -8,9 +8,9 @@ class DivPlatformGB: public DivDispatch { struct Channel { int freq, baseFreq, pitch; - unsigned char ins, note, duty, wave; + unsigned char ins, note, duty; bool active, insChanged, freqChanged, keyOn, keyOff; - signed char vol, outVol; + signed char vol, outVol, wave; DivMacroInt std; Channel(): freq(0), @@ -19,7 +19,7 @@ class DivPlatformGB: public DivDispatch { ins(-1), note(0), duty(0), - wave(0), + wave(-1), active(false), insChanged(true), freqChanged(false),