PCE: kind of implement LFO

This commit is contained in:
tildearrow 2021-06-09 01:08:42 -05:00
parent 480ddf489a
commit 99e59278ad
5 changed files with 37 additions and 4 deletions

View file

@ -37,6 +37,9 @@ enum DivDispatchCmds {
DIV_CMD_GB_SWEEP_TIME, DIV_CMD_GB_SWEEP_TIME,
DIV_CMD_GB_SWEEP_DIR, DIV_CMD_GB_SWEEP_DIR,
DIV_CMD_PCE_LFO_MODE,
DIV_CMD_PCE_LFO_SPEED,
DIV_ALWAYS_SET_VOLUME, DIV_ALWAYS_SET_VOLUME,
DIV_CMD_MAX DIV_CMD_MAX

View file

@ -18,13 +18,19 @@ void DivPlatformDummy::tick() {
for (unsigned char i=0; i<chans; i++) { for (unsigned char i=0; i<chans; i++) {
chan[i].amp--; chan[i].amp--;
if (chan[i].amp<0) chan[i].amp=0; if (chan[i].amp<0) chan[i].amp=0;
if (chan[i].freqChanged) {
chan[i].freqChanged=false;
chan[i].freq=(chan[i].baseFreq*(ONE_SEMITONE+chan[i].pitch))/ONE_SEMITONE;
}
} }
} }
int DivPlatformDummy::dispatch(DivCommand c) { int DivPlatformDummy::dispatch(DivCommand c) {
switch (c.cmd) { switch (c.cmd) {
case DIV_CMD_NOTE_ON: case DIV_CMD_NOTE_ON:
chan[c.chan].freq=16.4f*pow(2.0f,((float)c.value/12.0f)); chan[c.chan].baseFreq=16.4f*pow(2.0f,((float)c.value/12.0f));
chan[c.chan].freqChanged=true;
chan[c.chan].active=true; chan[c.chan].active=true;
chan[c.chan].amp=64; chan[c.chan].amp=64;
break; break;
@ -38,6 +44,14 @@ int DivPlatformDummy::dispatch(DivCommand c) {
case DIV_CMD_GET_VOLUME: case DIV_CMD_GET_VOLUME:
return chan[c.chan].vol; return chan[c.chan].vol;
break; break;
case DIV_CMD_PITCH:
chan[c.chan].pitch=c.value;
chan[c.chan].freqChanged=true;
break;
case DIV_CMD_LEGATO:
chan[c.chan].baseFreq=16.4f*pow(2.0f,((float)c.value/12.0f));
chan[c.chan].freqChanged=true;
break;
case DIV_CMD_GET_VOLMAX: case DIV_CMD_GET_VOLMAX:
return 15; return 15;
break; break;

View file

@ -4,12 +4,13 @@
// used when a DivDispatch for a system is not found. // used when a DivDispatch for a system is not found.
class DivPlatformDummy: public DivDispatch { class DivPlatformDummy: public DivDispatch {
struct Channel { struct Channel {
unsigned short freq; unsigned short freq, baseFreq;
short pitch;
unsigned short pos; unsigned short pos;
bool active; bool active, freqChanged;
unsigned char vol; unsigned char vol;
signed char amp; signed char amp;
Channel(): freq(0), pos(0), active(false), vol(0), amp(64) {} Channel(): freq(0), baseFreq(0), pitch(0), pos(0), active(false), freqChanged(false), vol(0), amp(64) {}
}; };
Channel chan[17]; Channel chan[17];
unsigned char chans; unsigned char chans;

View file

@ -186,6 +186,12 @@ int DivPlatformPCE::dispatch(DivCommand c) {
updateWave(c.chan); updateWave(c.chan);
chan[c.chan].keyOn=true; chan[c.chan].keyOn=true;
break; break;
case DIV_CMD_PCE_LFO_MODE:
rWrite(0x09,c.value);
break;
case DIV_CMD_PCE_LFO_SPEED:
rWrite(0x08,c.value);
break;
case DIV_CMD_NOTE_PORTA: { case DIV_CMD_NOTE_PORTA: {
int destFreq=round(FREQ_BASE/pow(2.0f,((float)c.value2/12.0f))); int destFreq=round(FREQ_BASE/pow(2.0f,((float)c.value2/12.0f)));
bool return2=false; bool return2=false;

View file

@ -45,6 +45,9 @@ const char* cmdName[DIV_CMD_MAX]={
"GB_SWEEP_TIME", "GB_SWEEP_TIME",
"GB_SWEEP_DIR", "GB_SWEEP_DIR",
"PCE_LFO_MODE",
"PCE_LFO_SPEED",
"ALWAYS_SET_VOLUME" "ALWAYS_SET_VOLUME"
}; };
@ -117,6 +120,12 @@ bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effe
case 0x11: // noise mode case 0x11: // noise mode
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal)); dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
break; break;
case 0x12: // LFO mode
dispatchCmd(DivCommand(DIV_CMD_PCE_LFO_MODE,ch,effectVal));
break;
case 0x13: // LFO speed
dispatchCmd(DivCommand(DIV_CMD_PCE_LFO_SPEED,ch,effectVal));
break;
case 0x17: // PCM enable case 0x17: // PCM enable
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_MODE,ch,(effectVal>0))); dispatchCmd(DivCommand(DIV_CMD_SAMPLE_MODE,ch,(effectVal>0)));
break; break;