mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-04 20:05:05 +00:00
implement more effects and bugfixes
enough to play time trax intro near flawless
This commit is contained in:
parent
eb692ca9a9
commit
9a97c38cc6
4 changed files with 141 additions and 14 deletions
|
@ -9,8 +9,22 @@ enum DivDispatchCmds {
|
||||||
DIV_CMD_NOTE_PORTA,
|
DIV_CMD_NOTE_PORTA,
|
||||||
DIV_CMD_PITCH,
|
DIV_CMD_PITCH,
|
||||||
DIV_CMD_PANNING,
|
DIV_CMD_PANNING,
|
||||||
|
DIV_CMD_LEGATO,
|
||||||
|
|
||||||
DIV_CMD_SAMPLE_MODE
|
DIV_CMD_SAMPLE_MODE,
|
||||||
|
|
||||||
|
DIV_CMD_FM_TL,
|
||||||
|
DIV_CMD_FM_AR,
|
||||||
|
DIV_CMD_FM_FB,
|
||||||
|
DIV_CMD_FM_MULT,
|
||||||
|
DIV_CMD_FM_EXTCH,
|
||||||
|
|
||||||
|
DIV_CMD_GENESIS_LFO,
|
||||||
|
|
||||||
|
DIV_CMD_ARCADE_LFO,
|
||||||
|
|
||||||
|
DIV_CMD_STD_NOISE_FREQ,
|
||||||
|
DIV_CMD_STD_NOISE_MODE
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DivCommand {
|
struct DivCommand {
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct DivChannelState {
|
||||||
int volume, volSpeed;
|
int volume, volSpeed;
|
||||||
int vibratoDepth, vibratoRate, vibratoPos;
|
int vibratoDepth, vibratoRate, vibratoPos;
|
||||||
int tremoloDepth, tremoloRate, tremoloPos;
|
int tremoloDepth, tremoloRate, tremoloPos;
|
||||||
bool doNote;
|
bool doNote, legato;
|
||||||
|
|
||||||
DivChannelState():
|
DivChannelState():
|
||||||
note(-1),
|
note(-1),
|
||||||
|
@ -26,7 +26,7 @@ struct DivChannelState {
|
||||||
tremoloDepth(0),
|
tremoloDepth(0),
|
||||||
tremoloRate(0),
|
tremoloRate(0),
|
||||||
tremoloPos(0),
|
tremoloPos(0),
|
||||||
doNote(false) {}
|
doNote(false), legato(false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DivEngine {
|
class DivEngine {
|
||||||
|
@ -50,6 +50,7 @@ class DivEngine {
|
||||||
void nextRow();
|
void nextRow();
|
||||||
void nextTick();
|
void nextTick();
|
||||||
bool perSystemEffect(int ch, unsigned char effect, unsigned char effectVal);
|
bool perSystemEffect(int ch, unsigned char effect, unsigned char effectVal);
|
||||||
|
bool perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal);
|
||||||
void renderSamples();
|
void renderSamples();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -68,6 +68,9 @@ static unsigned char dtTable[8]={
|
||||||
static int dacRates[6]={
|
static int dacRates[6]={
|
||||||
160,160,116,80,58,40
|
160,160,116,80,58,40
|
||||||
};
|
};
|
||||||
|
static int orderedOps[4]={
|
||||||
|
0,2,1,3
|
||||||
|
};
|
||||||
|
|
||||||
void DivPlatformGenesis::tick() {
|
void DivPlatformGenesis::tick() {
|
||||||
for (int i=0; i<6; i++) {
|
for (int i=0; i<6; i++) {
|
||||||
|
@ -86,25 +89,25 @@ void DivPlatformGenesis::tick() {
|
||||||
|
|
||||||
for (int i=0; i<6; i++) {
|
for (int i=0; i<6; i++) {
|
||||||
if (chan[i].freqChanged) {
|
if (chan[i].freqChanged) {
|
||||||
if (chan[i].freq>=131072) {
|
if (chan[i].freq>=82432) {
|
||||||
chan[i].freqH=((chan[i].freq>>15)&7)|0x38;
|
chan[i].freqH=((chan[i].freq>>15)&7)|0x38;
|
||||||
chan[i].freqL=(chan[i].freq>>7)&0xff;
|
chan[i].freqL=(chan[i].freq>>7)&0xff;
|
||||||
} else if (chan[i].freq>=65536) {
|
} else if (chan[i].freq>=41216) {
|
||||||
chan[i].freqH=((chan[i].freq>>14)&7)|0x30;
|
chan[i].freqH=((chan[i].freq>>14)&7)|0x30;
|
||||||
chan[i].freqL=(chan[i].freq>>6)&0xff;
|
chan[i].freqL=(chan[i].freq>>6)&0xff;
|
||||||
} else if (chan[i].freq>=32768) {
|
} else if (chan[i].freq>=20608) {
|
||||||
chan[i].freqH=((chan[i].freq>>13)&7)|0x28;
|
chan[i].freqH=((chan[i].freq>>13)&7)|0x28;
|
||||||
chan[i].freqL=(chan[i].freq>>5)&0xff;
|
chan[i].freqL=(chan[i].freq>>5)&0xff;
|
||||||
} else if (chan[i].freq>=16384) {
|
} else if (chan[i].freq>=10304) {
|
||||||
chan[i].freqH=((chan[i].freq>>12)&7)|0x20;
|
chan[i].freqH=((chan[i].freq>>12)&7)|0x20;
|
||||||
chan[i].freqL=(chan[i].freq>>4)&0xff;
|
chan[i].freqL=(chan[i].freq>>4)&0xff;
|
||||||
} else if (chan[i].freq>=8192) {
|
} else if (chan[i].freq>=5152) {
|
||||||
chan[i].freqH=((chan[i].freq>>11)&7)|0x18;
|
chan[i].freqH=((chan[i].freq>>11)&7)|0x18;
|
||||||
chan[i].freqL=(chan[i].freq>>3)&0xff;
|
chan[i].freqL=(chan[i].freq>>3)&0xff;
|
||||||
} else if (chan[i].freq>=4096) {
|
} else if (chan[i].freq>=2576) {
|
||||||
chan[i].freqH=((chan[i].freq>>10)&7)|0x10;
|
chan[i].freqH=((chan[i].freq>>10)&7)|0x10;
|
||||||
chan[i].freqL=(chan[i].freq>>2)&0xff;
|
chan[i].freqL=(chan[i].freq>>2)&0xff;
|
||||||
} else if (chan[i].freq>=2048) {
|
} else if (chan[i].freq>=1288) {
|
||||||
chan[i].freqH=((chan[i].freq>>9)&7)|0x08;
|
chan[i].freqH=((chan[i].freq>>9)&7)|0x08;
|
||||||
chan[i].freqL=(chan[i].freq>>1)&0xff;
|
chan[i].freqL=(chan[i].freq>>1)&0xff;
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,7 +244,47 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case DIV_CMD_LEGATO: {
|
||||||
|
chan[c.chan].baseFreq=644.0f*pow(2.0f,((float)c.value/12.0f));
|
||||||
|
chan[c.chan].freq=(chan[c.chan].baseFreq*(2048+chan[c.chan].pitch))>>11;
|
||||||
|
chan[c.chan].freqChanged=true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DIV_CMD_FM_MULT: {
|
||||||
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[c.value];
|
||||||
|
DivInstrument* ins=parent->song.ins[chan[c.chan].ins];
|
||||||
|
DivInstrumentFM::Operator op=ins->fm.op[c.value];
|
||||||
|
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DIV_CMD_FM_TL: {
|
||||||
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[orderedOps[c.value]];
|
||||||
|
DivInstrument* ins=parent->song.ins[chan[c.chan].ins];
|
||||||
|
if (isOutput[ins->fm.alg][c.value]) {
|
||||||
|
rWrite(baseAddr+0x40,127-(((127-c.value2)*chan[c.chan].vol)/127));
|
||||||
|
} else {
|
||||||
|
rWrite(baseAddr+0x40,c.value2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DIV_CMD_FM_AR: {
|
||||||
|
DivInstrument* ins=parent->song.ins[chan[c.chan].ins];
|
||||||
|
if (c.value<0) {
|
||||||
|
for (int i=0; i<4; i++) {
|
||||||
|
DivInstrumentFM::Operator op=ins->fm.op[i];
|
||||||
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
|
||||||
|
rWrite(baseAddr+0x50,(c.value2&31)|(op.rs<<6));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||||
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[orderedOps[c.value]];
|
||||||
|
rWrite(baseAddr+0x50,(c.value2&31)|(op.rs<<6));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
|
printf("WARNING: unimplemented command %d\n",c.cmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -39,6 +39,58 @@ bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effe
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal) {
|
||||||
|
switch (song.system) {
|
||||||
|
case DIV_SYSTEM_GENESIS:
|
||||||
|
switch (effect) {
|
||||||
|
case 0x11: // FB
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_FB,ch,effectVal&7));
|
||||||
|
break;
|
||||||
|
case 0x12: // TL op1
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_TL,ch,0,effectVal&0x7f));
|
||||||
|
break;
|
||||||
|
case 0x13: // TL op2
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_TL,ch,1,effectVal&0x7f));
|
||||||
|
break;
|
||||||
|
case 0x14: // TL op3
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_TL,ch,2,effectVal&0x7f));
|
||||||
|
break;
|
||||||
|
case 0x15: // TL op4
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_TL,ch,3,effectVal&0x7f));
|
||||||
|
break;
|
||||||
|
case 0x16: // MULT
|
||||||
|
if ((effectVal>>4)>0 && (effectVal>>4)<5) {
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_MULT,ch,(effectVal>>4)-1,effectVal&15));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0x18: // EXT
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_EXTCH,ch,effectVal));
|
||||||
|
break;
|
||||||
|
case 0x19: // AR global
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_AR,ch,-1,effectVal&31));
|
||||||
|
break;
|
||||||
|
case 0x1a: // AR op1
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_AR,ch,0,effectVal&31));
|
||||||
|
break;
|
||||||
|
case 0x1b: // AR op2
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_AR,ch,1,effectVal&31));
|
||||||
|
break;
|
||||||
|
case 0x1c: // AR op3
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_AR,ch,2,effectVal&31));
|
||||||
|
break;
|
||||||
|
case 0x1d: // AR op4
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_FM_AR,ch,3,effectVal&31));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void DivEngine::nextRow() {
|
void DivEngine::nextRow() {
|
||||||
static char pb[4096];
|
static char pb[4096];
|
||||||
static char pb1[4096];
|
static char pb1[4096];
|
||||||
|
@ -173,7 +225,7 @@ void DivEngine::nextRow() {
|
||||||
case 0x04: // vibrato
|
case 0x04: // vibrato
|
||||||
chan[i].vibratoDepth=effectVal&15;
|
chan[i].vibratoDepth=effectVal&15;
|
||||||
chan[i].vibratoRate=effectVal>>4;
|
chan[i].vibratoRate=effectVal>>4;
|
||||||
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4));
|
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4)));
|
||||||
break;
|
break;
|
||||||
case 0x0a: // volume ramp
|
case 0x0a: // volume ramp
|
||||||
if (effectVal!=0) {
|
if (effectVal!=0) {
|
||||||
|
@ -197,16 +249,33 @@ void DivEngine::nextRow() {
|
||||||
break;
|
break;
|
||||||
case 0xe5: // pitch
|
case 0xe5: // pitch
|
||||||
chan[i].pitch=effectVal-0x80;
|
chan[i].pitch=effectVal-0x80;
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>2)));
|
||||||
|
break;
|
||||||
|
case 0xea: // legato mode
|
||||||
|
chan[i].legato=effectVal;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chan[i].doNote) {
|
if (chan[i].doNote) {
|
||||||
chan[i].vibratoPos=0;
|
chan[i].vibratoPos=0;
|
||||||
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>2));
|
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4)));
|
||||||
dispatch->dispatch(DivCommand(DIV_CMD_NOTE_ON,i,chan[i].note));
|
if (chan[i].legato) {
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
||||||
|
} else {
|
||||||
|
dispatch->dispatch(DivCommand(DIV_CMD_NOTE_ON,i,chan[i].note));
|
||||||
|
}
|
||||||
chan[i].doNote=false;
|
chan[i].doNote=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// post effects
|
||||||
|
for (int j=0; j<song.pat[i]->effectRows; j++) {
|
||||||
|
short effect=pat->data[curRow][4+(j<<1)];
|
||||||
|
short effectVal=pat->data[curRow][5+(j<<1)];
|
||||||
|
|
||||||
|
if (effectVal==-1) effectVal=0;
|
||||||
|
perSystemPostEffect(i,effect,effectVal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +309,7 @@ void DivEngine::nextTick() {
|
||||||
if (chan[i].vibratoDepth>0) {
|
if (chan[i].vibratoDepth>0) {
|
||||||
chan[i].vibratoPos+=chan[i].vibratoRate;
|
chan[i].vibratoPos+=chan[i].vibratoRate;
|
||||||
if (chan[i].vibratoPos>=60) chan[i].vibratoPos-=60;
|
if (chan[i].vibratoPos>=60) chan[i].vibratoPos-=60;
|
||||||
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4));
|
dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4)));
|
||||||
}
|
}
|
||||||
if (chan[i].portaSpeed>0) {
|
if (chan[i].portaSpeed>0) {
|
||||||
if (dispatch->dispatch(DivCommand(DIV_CMD_NOTE_PORTA,i,chan[i].portaSpeed,chan[i].portaNote))==2) {
|
if (dispatch->dispatch(DivCommand(DIV_CMD_NOTE_PORTA,i,chan[i].portaSpeed,chan[i].portaNote))==2) {
|
||||||
|
|
Loading…
Reference in a new issue