phase reset effects & fix wavetable change

This commit is contained in:
LTVA1 2024-08-13 20:36:45 +03:00
parent cc87178e41
commit 0ea53fdae5
6 changed files with 105 additions and 13 deletions

View file

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

View file

@ -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<SID3_NUM_CHANNELS; i++)
{
chan[i].std.next();
bool panChanged = false;
bool flagsChanged = false;
bool envChanged = false;
if(sysTick)
{
if(chan[i].pw_slide != 0)
@ -293,11 +299,35 @@ void DivPlatformSID3::tick(bool sysTick)
updateFilter(i, j);
}
}
}
bool panChanged = false;
bool flagsChanged = false;
bool envChanged = false;
if(chan[i].phase_reset_counter >= 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;

View file

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

View file

@ -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!");

View file

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

View file

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