From 0ea53fdae5039c928fd06923956f1ed4b6dd09ff Mon Sep 17 00:00:00 2001 From: LTVA1 <87536432+LTVA1@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:36:45 +0300 Subject: [PATCH] phase reset effects & fix wavetable change --- src/engine/dispatch.h | 4 ++ src/engine/platform/sid3.cpp | 86 +++++++++++++++++++++++++++++++++--- src/engine/platform/sid3.h | 10 ++++- src/engine/playback.cpp | 8 +++- src/engine/sysDef.cpp | 4 ++ src/gui/guiConst.cpp | 6 +-- 6 files changed, 105 insertions(+), 13 deletions(-) diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 4c85ca138..bf7c50df3 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -282,6 +282,10 @@ enum DivDispatchCmds { DIV_CMD_C64_PW_SLIDE, DIV_CMD_C64_CUTOFF_SLIDE, + DIV_CMD_SID3_PHASE_RESET, + DIV_CMD_SID3_NOISE_PHASE_RESET, + DIV_CMD_SID3_ENVELOPE_RESET, + DIV_CMD_MAX }; diff --git a/src/engine/platform/sid3.cpp b/src/engine/platform/sid3.cpp index e18d977b0..63b4ab629 100644 --- a/src/engine/platform/sid3.cpp +++ b/src/engine/platform/sid3.cpp @@ -258,7 +258,7 @@ void DivPlatformSID3::updatePanning(int channel) rWrite(SID3_REGISTER_PAN_RIGHT + channel*SID3_REGISTERS_PER_CHANNEL,chan[channel].panRight); } -void DivPlatformSID3::updateWave() +void DivPlatformSID3::updateWave() { int channel = SID3_NUM_CHANNELS - 1; @@ -272,10 +272,16 @@ void DivPlatformSID3::updateWave() void DivPlatformSID3::tick(bool sysTick) { + bool doUpdateWave = false; + for (int i=0; i= 0) + { + if(chan[i].phase_reset_counter == 0) + { + chan[i].phaseReset = true; + flagsChanged = true; + } + chan[i].phase_reset_counter--; + } + if(chan[i].noise_phase_reset_counter >= 0) + { + if(chan[i].noise_phase_reset_counter == 0) + { + chan[i].phaseResetNoise = true; + flagsChanged = true; + } + chan[i].noise_phase_reset_counter--; + } + if(chan[i].envelope_reset_counter >= 0) + { + if(chan[i].envelope_reset_counter == 0) + { + chan[i].envReset = true; + flagsChanged = true; + } + chan[i].envelope_reset_counter--; + } + } if (chan[i].std.vol.had) { @@ -337,7 +367,8 @@ void DivPlatformSID3::tick(bool sysTick) if(i == SID3_NUM_CHANNELS - 1 && ins->sid3.doWavetable) { chan[i].wavetable = chan[i].std.wave.val & 0xff; - ws.changeWave1(chan[i].wave); + ws.changeWave1(chan[i].wavetable, true); + doUpdateWave = true; } else { @@ -653,9 +684,15 @@ void DivPlatformSID3::tick(bool sysTick) { if (ws.tick()) { - updateWave(); + doUpdateWave = true; } } + + if(doUpdateWave) + { + updateWave(); + doUpdateWave = false; + } } int DivPlatformSID3::dispatch(DivCommand c) { @@ -1026,6 +1063,15 @@ int DivPlatformSID3::dispatch(DivCommand c) { filter = abs(c.value2) - 1; chan[c.chan].filt[filter].cutoff_slide = c.value * (c.value2 > 0 ? 1 : -1) * 16; break; + case DIV_CMD_SID3_PHASE_RESET: + chan[c.chan].phase_reset_counter = c.value; + break; + case DIV_CMD_SID3_NOISE_PHASE_RESET: + chan[c.chan].noise_phase_reset_counter = c.value; + break; + case DIV_CMD_SID3_ENVELOPE_RESET: + chan[c.chan].envelope_reset_counter = c.value; + break; case DIV_CMD_SAMPLE_POS: chan[c.chan].dacPos=c.value; break; @@ -1147,6 +1193,10 @@ void DivPlatformSID3::reset() { chan[i].noiseLFSRMask = (1 << 29) | (1 << 5) | (1 << 3) | 1; //https://docs.amd.com/v/u/en-US/xapp052 for 30 bits: 30, 6, 4, 1 chan[i].pw_slide = 0; + + chan[i].phase_reset_counter = -1; + chan[i].noise_phase_reset_counter = -1; + chan[i].envelope_reset_counter = -1; } sampleTick = 0; @@ -1194,6 +1244,28 @@ void DivPlatformSID3::setFlags(const DivConfig& flags) { } } +DivChannelPair DivPlatformSID3::getPaired(int ch) +{ + if(chan[ch].phase) + { + return DivChannelPair("phase", chan[ch].phaseSrc); + } + if(chan[ch].ring) + { + if(chan[ch].ringSrc == SID3_NUM_CHANNELS) + { + return DivChannelPair("ring", ch); + } + + return DivChannelPair("ring", chan[ch].ringSrc); + } + if(chan[ch].sync) + { + return DivChannelPair("sync", chan[ch].syncSrc); + } + return DivChannelPair(); +} + int DivPlatformSID3::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { parent=p; dumpWrites=false; diff --git a/src/engine/platform/sid3.h b/src/engine/platform/sid3.h index 7216a5db0..699c32ac3 100644 --- a/src/engine/platform/sid3.h +++ b/src/engine/platform/sid3.h @@ -84,6 +84,10 @@ class DivPlatformSID3: public DivDispatch { short pw_slide; + short phase_reset_counter; + short noise_phase_reset_counter; + short envelope_reset_counter; + void handleArpNoise(int offset=0) { DivMacroStruct& m = this->std.op[3].am; @@ -182,7 +186,10 @@ class DivPlatformSID3: public DivDispatch { dacSample(-1), phaseInv(0), feedback(0), - pw_slide(0) {} + pw_slide(0), + phase_reset_counter(-1), + noise_phase_reset_counter(-1), + envelope_reset_counter(-1) {} }; Channel chan[SID3_NUM_CHANNELS]; DivDispatchOscBuffer* oscBuf[SID3_NUM_CHANNELS]; @@ -243,6 +250,7 @@ class DivPlatformSID3: public DivDispatch { const char** getRegisterSheet(); int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); int getOutputCount(); + DivChannelPair getPaired(int ch); void quit(); ~DivPlatformSID3(); }; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 62ea44820..dea89066e 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -279,8 +279,12 @@ const char* cmdName[]={ "SID3_FILTER_MATRIX", "SID3_FILTER_ENABLE", - "DIV_CMD_C64_PW_SLIDE", - "DIV_CMD_C64_CUTOFF_SLIDE", + "C64_PW_SLIDE", + "C64_CUTOFF_SLIDE", + + "SID3_PHASE_RESET", + "SID3_NOISE_PHASE_RESET", + "SID3_ENVELOPE_RESET", }; static_assert((sizeof(cmdName)/sizeof(void*))==DIV_CMD_MAX,"update cmdName!"); diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index b16cbb31b..fec11c92b 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -761,6 +761,10 @@ void DivEngine::registerSystems() { {0xAB, {DIV_CMD_C64_CUTOFF_SLIDE, _("ABxx: Filter 3 cutoff slide down"), effectVal, constVal<-3>}}, {0xAC, {DIV_CMD_C64_CUTOFF_SLIDE, _("ACxx: Filter 4 cutoff slide up"), effectVal, constVal<4>}}, {0xAD, {DIV_CMD_C64_CUTOFF_SLIDE, _("ADxx: Filter 4 cutoff slide down"), effectVal, constVal<-4>}}, + + {0xAE, {DIV_CMD_SID3_PHASE_RESET, _("AExx: Phase reset on tick xx")}}, + {0xAF, {DIV_CMD_SID3_NOISE_PHASE_RESET, _("AFxx: Noise phase reset on tick xx")}}, + {0xB0, {DIV_CMD_SID3_ENVELOPE_RESET, _("B0xx: Envelope reset on tick xx")}}, }; const EffectHandler SID3FineDutyHandler(DIV_CMD_C64_FINE_DUTY, _("5xxx: Set pulse width (0 to FFF)"), effectValLong<12>); diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 9a376aa85..a23ac03d7 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -431,11 +431,11 @@ const FurnaceGUIColors fxColors[256]={ GUI_COLOR_PATTERN_EFFECT_SYS_PRIMARY, GUI_COLOR_PATTERN_EFFECT_SYS_PRIMARY, GUI_COLOR_PATTERN_EFFECT_SYS_PRIMARY, - GUI_COLOR_PATTERN_EFFECT_INVALID, - GUI_COLOR_PATTERN_EFFECT_INVALID, + GUI_COLOR_PATTERN_EFFECT_SYS_PRIMARY, + GUI_COLOR_PATTERN_EFFECT_SYS_PRIMARY, // B0-BF - GUI_COLOR_PATTERN_EFFECT_INVALID, + GUI_COLOR_PATTERN_EFFECT_SYS_PRIMARY, GUI_COLOR_PATTERN_EFFECT_INVALID, GUI_COLOR_PATTERN_EFFECT_INVALID, GUI_COLOR_PATTERN_EFFECT_INVALID,