Merge branch 'master' of https://github.com/tildearrow/furnace into ymf278b
This commit is contained in:
commit
5837575e4a
17 changed files with 216 additions and 69 deletions
|
|
@ -697,6 +697,14 @@ class DivDispatch {
|
|||
*/
|
||||
virtual int mapVelocity(int ch, float vel);
|
||||
|
||||
/**
|
||||
* map chip volume to gain.
|
||||
* @param ch the chip channel. -1 means N/A.
|
||||
* @param vol input volume.
|
||||
* @return output gain fron 0.0 to 1.0.
|
||||
*/
|
||||
virtual float getGain(int ch, int vol);
|
||||
|
||||
/**
|
||||
* get the lowest note in a portamento.
|
||||
* @param ch the channel in question.
|
||||
|
|
|
|||
|
|
@ -181,6 +181,8 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
unsigned short patLen[256];
|
||||
|
||||
unsigned char defVol[256];
|
||||
unsigned char defPan[256];
|
||||
unsigned char defPanIns[256];
|
||||
unsigned char noteMap[256][128];
|
||||
|
||||
bool doesPitchSlide[64];
|
||||
|
|
@ -210,6 +212,8 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
memset(patLen,0,256*sizeof(unsigned short));
|
||||
|
||||
memset(defVol,0,256);
|
||||
memset(defPan,0,256);
|
||||
memset(defPanIns,128,256);
|
||||
memset(noteMap,0,256*128);
|
||||
|
||||
try {
|
||||
|
|
@ -436,9 +440,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
reader.readC();
|
||||
|
||||
insVol=reader.readC();
|
||||
unsigned char defPan=reader.readC();
|
||||
|
||||
logV("defPan: %d",defPan);
|
||||
defPanIns[i]=reader.readC();
|
||||
|
||||
// vol/pan randomization
|
||||
reader.readC();
|
||||
|
|
@ -572,9 +574,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
s->name=reader.readStringLatin1(26);
|
||||
|
||||
unsigned char convert=reader.readC();
|
||||
unsigned char defPan=reader.readC();
|
||||
|
||||
logV("defPan: %d",defPan);
|
||||
defPan[i]=reader.readC();
|
||||
|
||||
if (flags&2) {
|
||||
s->depth=DIV_SAMPLE_DEPTH_16BIT;
|
||||
|
|
@ -946,6 +946,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
bool panSliding[64];
|
||||
bool panSlidingOld[64];
|
||||
bool did[64];
|
||||
unsigned char lastRetrig[64];
|
||||
|
||||
if (patPtr[i]==0) continue;
|
||||
|
||||
|
|
@ -989,6 +990,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
memset(panSliding,0,64*sizeof(bool));
|
||||
memset(panSlidingOld,0,64*sizeof(bool));
|
||||
memset(did,0,64*sizeof(bool));
|
||||
memset(lastRetrig,0,64);
|
||||
|
||||
memset(mask,0,64);
|
||||
memset(note,0,64);
|
||||
|
|
@ -1118,7 +1120,6 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
}
|
||||
|
||||
readRow++;
|
||||
memset(effectCol,4,64);
|
||||
memcpy(vibingOld,vibing,64*sizeof(bool));
|
||||
memcpy(volSlidingOld,volSliding,64*sizeof(bool));
|
||||
memcpy(portingOld,porting,64*sizeof(bool));
|
||||
|
|
@ -1155,6 +1156,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
memset(effectCol,4,64);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1216,6 +1218,29 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
}
|
||||
if (hasIns) {
|
||||
p->data[readRow][2]=ins[chan]-1;
|
||||
if ((note[chan]<120 || ds.insLen==0) && ins[chan]>0) {
|
||||
unsigned char targetPan=0;
|
||||
if (ds.insLen==0) {
|
||||
targetPan=defPan[(ins[chan]-1)&255];
|
||||
} else {
|
||||
targetPan=defPan[noteMap[(ins[chan]-1)&255][note[chan]]];
|
||||
if (!(targetPan&128)) {
|
||||
targetPan=defPanIns[(ins[chan]-1)&255]^0x80;
|
||||
}
|
||||
}
|
||||
if (targetPan&128) {
|
||||
p->data[readRow][effectCol[chan]++]=0x80;
|
||||
p->data[readRow][effectCol[chan]++]=CLAMP((targetPan&127)<<2,0,255);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNote && (note[chan]<120 || ds.insLen==0) && ins[chan]>0) {
|
||||
if (ds.insLen==0) {
|
||||
p->data[readRow][3]=defVol[(ins[chan]-1)&255];
|
||||
} else {
|
||||
p->data[readRow][3]=defVol[noteMap[(ins[chan]-1)&255][note[chan]]];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasVol) {
|
||||
if (vol[chan]<=64) {
|
||||
|
|
@ -1227,7 +1252,23 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
} else if (vol[chan]>=65 && vol[chan]<=74) { // fine vol up
|
||||
} else if (vol[chan]>=75 && vol[chan]<=84) { // fine vol down
|
||||
} else if (vol[chan]>=85 && vol[chan]<=94) { // vol slide up
|
||||
if ((vol[chan]-85)!=0) {
|
||||
volSlideStatus[chan]=(vol[chan]-85)<<4;
|
||||
volSlideStatusChanged[chan]=true;
|
||||
}
|
||||
if (hasNote || hasIns) {
|
||||
volSlideStatusChanged[chan]=true;
|
||||
}
|
||||
volSliding[chan]=true;
|
||||
} else if (vol[chan]>=95 && vol[chan]<=104) { // vol slide down
|
||||
if ((vol[chan]-95)!=0) {
|
||||
volSlideStatus[chan]=vol[chan]-95;
|
||||
volSlideStatusChanged[chan]=true;
|
||||
}
|
||||
if (hasNote || hasIns) {
|
||||
volSlideStatusChanged[chan]=true;
|
||||
}
|
||||
volSliding[chan]=true;
|
||||
} else if (vol[chan]>=105 && vol[chan]<=114) { // pitch down
|
||||
} else if (vol[chan]>=115 && vol[chan]<=124) { // pitch up
|
||||
} else if (vol[chan]>=193 && vol[chan]<=202) { // porta
|
||||
|
|
@ -1242,14 +1283,14 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
portaType[chan]=3;
|
||||
porting[chan]=true;
|
||||
} else if (vol[chan]>=203 && vol[chan]<=212) { // vibrato
|
||||
if ((vol[chan]-203)!=0) {
|
||||
vibStatus[chan]&=0xf0;
|
||||
vibStatus[chan]|=(vol[chan]-203);
|
||||
vibStatusChanged[chan]=true;
|
||||
}
|
||||
vibing[chan]=true;
|
||||
}
|
||||
}
|
||||
} else if (hasNote && hasIns && (note[chan]<120 || ds.insLen==0) && ins[chan]>0) {
|
||||
if (ds.insLen==0) {
|
||||
p->data[readRow][3]=defVol[(ins[chan]-1)&255];
|
||||
} else {
|
||||
p->data[readRow][3]=defVol[noteMap[(ins[chan]-1)&255][note[chan]]];
|
||||
}
|
||||
}
|
||||
if (hasEffect) {
|
||||
switch (effect[chan]+'A'-1) {
|
||||
|
|
@ -1302,7 +1343,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
portaStatus[chan]=effectVal[chan];
|
||||
portaStatusChanged[chan]=true;
|
||||
}
|
||||
if (portaType[chan]!=3) {
|
||||
if (portaType[chan]!=3 || hasNote) {
|
||||
portaStatusChanged[chan]=true;
|
||||
}
|
||||
portaType[chan]=3;
|
||||
|
|
@ -1357,8 +1398,11 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
panSliding[chan]=true;
|
||||
break;
|
||||
case 'Q': // retrigger
|
||||
if (effectVal[chan]!=0) {
|
||||
lastRetrig[chan]=effectVal[chan];
|
||||
}
|
||||
p->data[readRow][effectCol[chan]++]=0x0c;
|
||||
p->data[readRow][effectCol[chan]++]=effectVal[chan]&15;
|
||||
p->data[readRow][effectCol[chan]++]=lastRetrig[chan]&15;
|
||||
break;
|
||||
case 'R': // tremolo
|
||||
if (effectVal[chan]!=0) {
|
||||
|
|
@ -1369,6 +1413,10 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
break;
|
||||
case 'S': // special...
|
||||
switch (effectVal[chan]>>4) {
|
||||
case 0x8:
|
||||
p->data[readRow][effectCol[chan]++]=0x80;
|
||||
p->data[readRow][effectCol[chan]++]=(effectVal[chan]&15)<<4;
|
||||
break;
|
||||
case 0xc:
|
||||
p->data[readRow][effectCol[chan]++]=0xec;
|
||||
p->data[readRow][effectCol[chan]++]=effectVal[chan]&15;
|
||||
|
|
@ -1380,8 +1428,10 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
}
|
||||
break;
|
||||
case 'T': // tempo
|
||||
p->data[readRow][effectCol[chan]++]=0xf0;
|
||||
p->data[readRow][effectCol[chan]++]=effectVal[chan];
|
||||
if (effectVal[chan]>=0x20) {
|
||||
p->data[readRow][effectCol[chan]++]=0xf0;
|
||||
p->data[readRow][effectCol[chan]++]=effectVal[chan];
|
||||
}
|
||||
break;
|
||||
case 'U': // fine vibrato
|
||||
if (effectVal[chan]!=0) {
|
||||
|
|
@ -1471,6 +1521,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
}
|
||||
}
|
||||
ds.systemLen=(maxChan+32)>>5;
|
||||
ds.systemName="PC";
|
||||
|
||||
// find subsongs
|
||||
ds.findSubSongs(maxChan);
|
||||
|
|
|
|||
|
|
@ -1075,6 +1075,10 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
|||
break;
|
||||
case 'S': // special...
|
||||
switch (effectVal>>4) {
|
||||
case 0x8:
|
||||
p->data[readRow][effectCol[chan]++]=0x80;
|
||||
p->data[readRow][effectCol[chan]++]=(effectVal&15)<<4;
|
||||
break;
|
||||
case 0xc:
|
||||
p->data[readRow][effectCol[chan]++]=0xec;
|
||||
p->data[readRow][effectCol[chan]++]=effectVal&15;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,10 @@ void readEnvelope(DivInstrument* ins, int env, unsigned char flags, unsigned cha
|
|||
}
|
||||
}
|
||||
if ((point+1)>=numPoints) {
|
||||
target->len=i;
|
||||
target->len=i-1;
|
||||
if (((flags&4) && (!(flags&2))) || ((flags&6)==0)) {
|
||||
target->rel=i-2;
|
||||
}
|
||||
//target->val[i]=p0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -103,7 +106,7 @@ void readEnvelope(DivInstrument* ins, int env, unsigned char flags, unsigned cha
|
|||
// split L/R
|
||||
if (env==1) {
|
||||
for (int i=0; i<ins->std.panLMacro.len; i++) {
|
||||
int val=ins->std.panLMacro.val[i];
|
||||
int val=ins->std.panLMacro.val[i]-32;
|
||||
if (val==0) {
|
||||
ins->std.panLMacro.val[i]=4095;
|
||||
ins->std.panRMacro.val[i]=4095;
|
||||
|
|
@ -166,7 +169,7 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
ds.noSlidesOnFirstTick=true;
|
||||
ds.rowResetsArpPos=true;
|
||||
ds.ignoreJumpAtEnd=false;
|
||||
ds.pitchSlideSpeed=12;
|
||||
ds.pitchSlideSpeed=8;
|
||||
|
||||
logV("Extended Module");
|
||||
|
||||
|
|
@ -421,6 +424,9 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
}
|
||||
}
|
||||
if (hasEffectVal) {
|
||||
if (!hasEffect) {
|
||||
doesArp[k]=true;
|
||||
}
|
||||
effectVal=reader.readC();
|
||||
if (effect==0xe) {
|
||||
switch (effectVal>>4) {
|
||||
|
|
@ -525,21 +531,40 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
|
||||
if (volType&1) {
|
||||
// add fade-out
|
||||
int cur=64;
|
||||
if (ins->std.volMacro.len>0) {
|
||||
cur=ins->std.volMacro.val[ins->std.volMacro.len-1];
|
||||
}
|
||||
for (int fadeOut=32767; fadeOut>0 && ins->std.volMacro.len<254; fadeOut-=volFade) {
|
||||
ins->std.volMacro.val[ins->std.volMacro.len++]=(cur*fadeOut)>>15;
|
||||
}
|
||||
if (ins->std.volMacro.len<255) {
|
||||
ins->std.volMacro.val[ins->std.volMacro.len++]=0;
|
||||
if (volFade!=0) {
|
||||
int cur=64;
|
||||
int macroLen=ins->std.volMacro.len;
|
||||
int curPos=ins->std.volMacro.len-1;
|
||||
if (ins->std.volMacro.loop<macroLen) {
|
||||
curPos=ins->std.volMacro.loop;
|
||||
}
|
||||
if (ins->std.volMacro.len>0) {
|
||||
cur=ins->std.volMacro.val[curPos];
|
||||
}
|
||||
for (int fadeOut=32767; fadeOut>0 && ins->std.volMacro.len<254; fadeOut-=volFade) {
|
||||
cur=ins->std.volMacro.val[curPos];
|
||||
ins->std.volMacro.val[ins->std.volMacro.len++]=(cur*fadeOut)>>15;
|
||||
if (++curPos>=macroLen) {
|
||||
if (ins->std.volMacro.loop<macroLen) {
|
||||
curPos=ins->std.volMacro.loop;
|
||||
} else {
|
||||
curPos=macroLen-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ins->std.volMacro.len<255) {
|
||||
ins->std.volMacro.val[ins->std.volMacro.len++]=0;
|
||||
}
|
||||
if (ins->std.volMacro.rel<ins->std.volMacro.len && ins->std.volMacro.rel<ins->std.volMacro.loop) {
|
||||
ins->std.volMacro.loop=255;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// add a one-tick macro to make note release happy
|
||||
ins->std.volMacro.val[0]=64;
|
||||
ins->std.volMacro.val[1]=0;
|
||||
ins->std.volMacro.rel=0;
|
||||
ins->std.volMacro.loop=255;
|
||||
ins->std.volMacro.len=2;
|
||||
}
|
||||
|
||||
|
|
@ -908,6 +933,15 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
panSliding[k]=true;
|
||||
break;
|
||||
case 0xf: // porta
|
||||
if ((vol&15)!=0) {
|
||||
portaStatus[k]=(vol&15)<<4;
|
||||
portaStatusChanged[k]=true;
|
||||
}
|
||||
if (portaType[k]!=3 || (hasNote && note>0)) {
|
||||
portaStatusChanged[k]=true;
|
||||
}
|
||||
portaType[k]=3;
|
||||
porting[k]=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -955,7 +989,7 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
portaStatus[k]=effectVal;
|
||||
portaStatusChanged[k]=true;
|
||||
}
|
||||
if (portaType[k]!=3) {
|
||||
if (portaType[k]!=3 || (hasNote && note>0)) {
|
||||
portaStatusChanged[k]=true;
|
||||
}
|
||||
portaType[k]=3;
|
||||
|
|
@ -1006,8 +1040,10 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
writePanning=false;
|
||||
break;
|
||||
case 9: // offset
|
||||
p->data[j][effectCol[k]++]=0x91;
|
||||
p->data[j][effectCol[k]++]=effectVal;
|
||||
if (hasNote) {
|
||||
p->data[j][effectCol[k]++]=0x91;
|
||||
p->data[j][effectCol[k]++]=effectVal;
|
||||
}
|
||||
break;
|
||||
case 0xa: // vol slide
|
||||
if (effectVal!=0) {
|
||||
|
|
@ -1037,19 +1073,25 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
p->data[j][effectCol[k]++]=0xe5;
|
||||
p->data[j][effectCol[k]++]=(effectVal&15)<<4;
|
||||
break;
|
||||
case 0x9:
|
||||
p->data[j][effectCol[k]++]=0x0c;
|
||||
p->data[j][effectCol[k]++]=(effectVal&15);
|
||||
break;
|
||||
case 0xc:
|
||||
p->data[j][effectCol[k]++]=0xec;
|
||||
p->data[j][effectCol[k]++]=effectVal&15;
|
||||
p->data[j][effectCol[k]++]=MAX(1,effectVal&15);
|
||||
break;
|
||||
case 0xd:
|
||||
p->data[j][effectCol[k]++]=0xed;
|
||||
p->data[j][effectCol[k]++]=effectVal&15;
|
||||
p->data[j][effectCol[k]++]=MAX(1,effectVal&15);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0xf: // speed/tempp
|
||||
case 0xf: // speed/tempo
|
||||
if (effectVal>=0x20) {
|
||||
p->data[j][effectCol[k]++]=0xf0;
|
||||
} else if (effectVal==0) {
|
||||
p->data[j][effectCol[k]++]=0xff;
|
||||
} else {
|
||||
p->data[j][effectCol[k]++]=0x0f;
|
||||
}
|
||||
|
|
@ -1128,14 +1170,8 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
}
|
||||
|
||||
if (porting[k]!=portingOld[k] || portaStatusChanged[k]) {
|
||||
if (portaStatus[k]>=0xe0 && portaType[k]!=3 && porting[k]) {
|
||||
p->data[j][effectCol[k]++]=portaType[k]|0xf0;
|
||||
p->data[j][effectCol[k]++]=(portaStatus[k]&15)*((portaStatus[k]>=0xf0)?1:1);
|
||||
porting[k]=false;
|
||||
} else {
|
||||
p->data[j][effectCol[k]++]=portaType[k];
|
||||
p->data[j][effectCol[k]++]=porting[k]?portaStatus[k]:0;
|
||||
}
|
||||
p->data[j][effectCol[k]++]=portaType[k];
|
||||
p->data[j][effectCol[k]++]=porting[k]?portaStatus[k]:0;
|
||||
doesPitchSlide[k]=true;
|
||||
} else if (doesPitchSlide[k] && mustCommitInitial) {
|
||||
p->data[j][effectCol[k]++]=0x01;
|
||||
|
|
@ -1183,7 +1219,6 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
memset(effectCol,4,64);
|
||||
memcpy(vibingOld,vibing,64*sizeof(bool));
|
||||
memcpy(volSlidingOld,volSliding,64*sizeof(bool));
|
||||
memcpy(portingOld,porting,64*sizeof(bool));
|
||||
|
|
@ -1207,6 +1242,7 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
|||
ds.subsong[0]->pat[0].effectCols=(effectCol[0]>>1)-1;
|
||||
}
|
||||
}
|
||||
memset(effectCol,4,64);
|
||||
}
|
||||
|
||||
logV("seeking to %x...",packedSeek);
|
||||
|
|
|
|||
|
|
@ -107,6 +107,11 @@ int DivDispatch::mapVelocity(int ch, float vel) {
|
|||
return round(vel*volMax);
|
||||
}
|
||||
|
||||
float DivDispatch::getGain(int ch, int vol) {
|
||||
const float volMax=MAX(1,dispatch(DivCommand(DIV_CMD_GET_VOLMAX,MAX(ch,0))));
|
||||
return (float)vol/volMax;
|
||||
}
|
||||
|
||||
int DivDispatch::getPortaFloor(int ch) {
|
||||
return 0x00;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue