fix sample issues - part 5 (final?)

This commit is contained in:
tildearrow 2024-02-02 13:55:42 -05:00
parent 94cce86180
commit 35bca6e90c
12 changed files with 82 additions and 7 deletions

View file

@ -228,21 +228,28 @@ int DivPlatformLynx::dispatch(DivCommand c) {
WRITE_CONTROL(c.chan,0x18); WRITE_CONTROL(c.chan,0x18);
WRITE_BACKUP(c.chan,0); WRITE_BACKUP(c.chan,0);
} else { } else {
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
WRITE_FEEDBACK(c.chan,chan[c.chan].duty.feedback); WRITE_FEEDBACK(c.chan,chan[c.chan].duty.feedback);
WRITE_CONTROL(c.chan,(chan[c.chan].fd.clockDivider|0x18|chan[c.chan].duty.int_feedback7)); WRITE_CONTROL(c.chan,(chan[c.chan].fd.clockDivider|0x18|chan[c.chan].duty.int_feedback7));
WRITE_BACKUP(c.chan,chan[c.chan].fd.backup); WRITE_BACKUP(c.chan,chan[c.chan].fd.backup);
} }
} }
if (c.value!=DIV_NOTE_NULL) { if (chan[c.chan].pcm) {
if (chan[c.chan].pcm) { if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].sample=ins->amiga.getSample(c.value); chan[c.chan].sample=ins->amiga.getSample(c.value);
chan[c.chan].sampleNote=c.value; chan[c.chan].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
chan[c.chan].sampleBaseFreq=NOTE_FREQUENCY(c.value); chan[c.chan].sampleBaseFreq=NOTE_FREQUENCY(c.value);
chan[c.chan].sampleAccum=0; } else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
chan[c.chan].samplePos=0; chan[c.chan].sample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
chan[c.chan].sampleAccum=0;
chan[c.chan].samplePos=0;
}
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
chan[c.chan].freqChanged=true; chan[c.chan].freqChanged=true;
chan[c.chan].note=c.value; chan[c.chan].note=c.value;

View file

@ -181,6 +181,9 @@ int DivPlatformMMC5::dispatch(DivCommand c) {
chan[c.chan].sampleNote=c.value; chan[c.chan].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
dacSample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
if (dacSample<0 || dacSample>=parent->song.sampleLen) { if (dacSample<0 || dacSample>=parent->song.sampleLen) {
dacSample=-1; dacSample=-1;
@ -191,8 +194,8 @@ int DivPlatformMMC5::dispatch(DivCommand c) {
} }
dacPos=0; dacPos=0;
dacPeriod=0; dacPeriod=0;
chan[c.chan].baseFreq=parent->calcBaseFreq(1,1,c.value,false);
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=parent->calcBaseFreq(1,1,c.value,false);
chan[c.chan].freqChanged=true; chan[c.chan].freqChanged=true;
chan[c.chan].note=c.value; chan[c.chan].note=c.value;
} }

View file

@ -411,6 +411,11 @@ int DivPlatformNES::dispatch(DivCommand c) {
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} }
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
dacSample=ins->amiga.getSample(chan[c.chan].sampleNote);
if (ins->type==DIV_INS_AMIGA) {
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
}
} }
if (dacSample<0 || dacSample>=parent->song.sampleLen) { if (dacSample<0 || dacSample>=parent->song.sampleLen) {
dacSample=-1; dacSample=-1;

View file

@ -278,6 +278,8 @@ int DivPlatformPCE::dispatch(DivCommand c) {
chan[c.chan].pcm=true; chan[c.chan].pcm=true;
} else if (chan[c.chan].furnaceDac) { } else if (chan[c.chan].furnaceDac) {
chan[c.chan].pcm=false; chan[c.chan].pcm=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
if (chan[c.chan].pcm) { if (chan[c.chan].pcm) {
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) {
@ -288,6 +290,9 @@ int DivPlatformPCE::dispatch(DivCommand c) {
chan[c.chan].sampleNote=c.value; chan[c.chan].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
chan[c.chan].dacSample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
if (chan[c.chan].dacSample<0 || chan[c.chan].dacSample>=parent->song.sampleLen) { if (chan[c.chan].dacSample<0 || chan[c.chan].dacSample>=parent->song.sampleLen) {
chan[c.chan].dacSample=-1; chan[c.chan].dacSample=-1;
@ -314,6 +319,8 @@ int DivPlatformPCE::dispatch(DivCommand c) {
//chan[c.chan].keyOn=true; //chan[c.chan].keyOn=true;
} else { } else {
chan[c.chan].furnaceDac=false; chan[c.chan].furnaceDac=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
if (skipRegisterWrites) break; if (skipRegisterWrites) break;
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].note=c.value; chan[c.chan].note=c.value;
@ -336,6 +343,8 @@ int DivPlatformPCE::dispatch(DivCommand c) {
} }
break; break;
} }
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
chan[c.chan].freqChanged=true; chan[c.chan].freqChanged=true;

View file

@ -314,6 +314,8 @@ int DivPlatformPCMDAC::dispatch(DivCommand c) {
case DIV_CMD_NOTE_ON: { case DIV_CMD_NOTE_ON: {
DivInstrument* ins=parent->getIns(chan[0].ins,DIV_INS_AMIGA); DivInstrument* ins=parent->getIns(chan[0].ins,DIV_INS_AMIGA);
if (ins->amiga.useWave) { if (ins->amiga.useWave) {
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
chan[0].useWave=true; chan[0].useWave=true;
chan[0].audLen=ins->amiga.waveLen+1; chan[0].audLen=ins->amiga.waveLen+1;
if (chan[0].insChanged) { if (chan[0].insChanged) {
@ -329,6 +331,9 @@ int DivPlatformPCMDAC::dispatch(DivCommand c) {
chan[c.chan].sampleNote=c.value; chan[c.chan].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
chan[c.chan].sample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
chan[0].useWave=false; chan[0].useWave=false;
} }
@ -337,6 +342,8 @@ int DivPlatformPCMDAC::dispatch(DivCommand c) {
} }
if (chan[0].useWave || chan[0].sample<0 || chan[0].sample>=parent->song.sampleLen) { if (chan[0].useWave || chan[0].sample<0 || chan[0].sample>=parent->song.sampleLen) {
chan[0].sample=-1; chan[0].sample=-1;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
if (chan[0].setPos) { if (chan[0].setPos) {
chan[0].setPos=false; chan[0].setPos=false;

View file

@ -333,6 +333,8 @@ int DivPlatformSNES::dispatch(DivCommand c) {
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_SNES); DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_SNES);
if (ins->amiga.useWave) { if (ins->amiga.useWave) {
chan[c.chan].useWave=true; chan[c.chan].useWave=true;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
chan[c.chan].wtLen=ins->amiga.waveLen+1; chan[c.chan].wtLen=ins->amiga.waveLen+1;
if (chan[c.chan].insChanged) { if (chan[c.chan].insChanged) {
if (chan[c.chan].wave<0) { if (chan[c.chan].wave<0) {

View file

@ -286,6 +286,9 @@ int DivPlatformSoundUnit::dispatch(DivCommand c) {
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} }
} else {
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_SU(c.chan,c.value); chan[c.chan].baseFreq=NOTE_SU(c.chan,c.value);

View file

@ -257,6 +257,8 @@ int DivPlatformSwan::dispatch(DivCommand c) {
pcm=true; pcm=true;
} else if (furnaceDac) { } else if (furnaceDac) {
pcm=false; pcm=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
if (pcm) { if (pcm) {
if (skipRegisterWrites) break; if (skipRegisterWrites) break;
@ -268,6 +270,9 @@ int DivPlatformSwan::dispatch(DivCommand c) {
chan[c.chan].sampleNote=c.value; chan[c.chan].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
dacSample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
if (dacSample<0 || dacSample>=parent->song.sampleLen) { if (dacSample<0 || dacSample>=parent->song.sampleLen) {
dacSample=-1; dacSample=-1;
@ -334,6 +339,8 @@ int DivPlatformSwan::dispatch(DivCommand c) {
dacSample=-1; dacSample=-1;
if (dumpWrites) postWrite(0xffff0002,0); if (dumpWrites) postWrite(0xffff0002,0);
pcm=false; pcm=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
chan[c.chan].active=false; chan[c.chan].active=false;
chan[c.chan].keyOff=true; chan[c.chan].keyOff=true;
@ -414,7 +421,13 @@ int DivPlatformSwan::dispatch(DivCommand c) {
} }
break; break;
case DIV_CMD_SAMPLE_MODE: case DIV_CMD_SAMPLE_MODE:
if (c.chan==1) pcm=c.value; if (c.chan==1) {
pcm=c.value;
if (!pcm) {
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
}
}
break; break;
case DIV_CMD_SAMPLE_BANK: case DIV_CMD_SAMPLE_BANK:
sampleBank=c.value; sampleBank=c.value;

View file

@ -299,12 +299,15 @@ int DivPlatformVERA::dispatch(DivCommand c) {
if (c.chan<16) { if (c.chan<16) {
rWriteLo(c.chan,2,chan[c.chan].vol); rWriteLo(c.chan,2,chan[c.chan].vol);
} else { } else {
DivInstrument* ins=parent->getIns(chan[16].ins,DIV_INS_VERA);
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
DivInstrument* ins=parent->getIns(chan[16].ins,DIV_INS_VERA);
chan[16].pcm.sample=ins->amiga.getSample(c.value); chan[16].pcm.sample=ins->amiga.getSample(c.value);
chan[16].sampleNote=c.value; chan[16].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[16].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[16].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
chan[16].pcm.sample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
if (chan[16].pcm.sample<0 || chan[16].pcm.sample>=parent->song.sampleLen) { if (chan[16].pcm.sample<0 || chan[16].pcm.sample>=parent->song.sampleLen) {
chan[16].pcm.sample=-1; chan[16].pcm.sample=-1;

View file

@ -236,6 +236,8 @@ int DivPlatformVRC6::dispatch(DivCommand c) {
chan[c.chan].pcm=true; chan[c.chan].pcm=true;
} else if (chan[c.chan].furnaceDac) { } else if (chan[c.chan].furnaceDac) {
chan[c.chan].pcm=false; chan[c.chan].pcm=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
if (chan[c.chan].pcm) { if (chan[c.chan].pcm) {
if (skipRegisterWrites) break; if (skipRegisterWrites) break;
@ -245,6 +247,9 @@ int DivPlatformVRC6::dispatch(DivCommand c) {
chan[c.chan].sampleNote=c.value; chan[c.chan].sampleNote=c.value;
c.value=ins->amiga.getFreq(c.value); c.value=ins->amiga.getFreq(c.value);
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
chan[c.chan].dacSample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
} }
if (chan[c.chan].dacSample<0 || chan[c.chan].dacSample>=parent->song.sampleLen) { if (chan[c.chan].dacSample<0 || chan[c.chan].dacSample>=parent->song.sampleLen) {
chan[c.chan].dacSample=-1; chan[c.chan].dacSample=-1;
@ -272,6 +277,8 @@ int DivPlatformVRC6::dispatch(DivCommand c) {
//chan[c.chan].keyOn=true; //chan[c.chan].keyOn=true;
chan[c.chan].furnaceDac=true; chan[c.chan].furnaceDac=true;
} else { } else {
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].note=c.value; chan[c.chan].note=c.value;
} }
@ -316,6 +323,8 @@ int DivPlatformVRC6::dispatch(DivCommand c) {
chan[c.chan].dacSample=-1; chan[c.chan].dacSample=-1;
if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0);
chan[c.chan].pcm=false; chan[c.chan].pcm=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
chan[c.chan].active=false; chan[c.chan].active=false;
chan[c.chan].keyOff=true; chan[c.chan].keyOff=true;
chan[c.chan].macroInit(NULL); chan[c.chan].macroInit(NULL);
@ -384,6 +393,10 @@ int DivPlatformVRC6::dispatch(DivCommand c) {
case DIV_CMD_SAMPLE_MODE: case DIV_CMD_SAMPLE_MODE:
if (c.chan!=2) { // pulse if (c.chan!=2) { // pulse
chan[c.chan].pcm=c.value; chan[c.chan].pcm=c.value;
if (!chan[c.chan].pcm) {
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
}
} }
break; break;
case DIV_CMD_SAMPLE_BANK: case DIV_CMD_SAMPLE_BANK:

View file

@ -536,6 +536,8 @@ int DivPlatformX1_010::dispatch(DivCommand c) {
chan[c.chan].furnacePCM=true; chan[c.chan].furnacePCM=true;
} else { } else {
chan[c.chan].furnacePCM=false; chan[c.chan].furnacePCM=false;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
} }
if (skipRegisterWrites) break; if (skipRegisterWrites) break;
if (chan[c.chan].furnacePCM) { if (chan[c.chan].furnacePCM) {
@ -610,6 +612,8 @@ int DivPlatformX1_010::dispatch(DivCommand c) {
} }
} else if (c.value!=DIV_NOTE_NULL) { } else if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].note=c.value; chan[c.chan].note=c.value;
chan[c.chan].sampleNote=DIV_NOTE_NULL;
chan[c.chan].sampleNoteDelta=0;
chan[c.chan].baseFreq=NoteX1_010(c.chan,chan[c.chan].note); chan[c.chan].baseFreq=NoteX1_010(c.chan,chan[c.chan].note);
chan[c.chan].fixedFreq=0; chan[c.chan].fixedFreq=0;
chan[c.chan].freqChanged=true; chan[c.chan].freqChanged=true;

View file

@ -196,6 +196,12 @@ int DivPlatformZXBeeperQuadTone::dispatch(DivCommand c) {
// TODO support offset commands // TODO support offset commands
curSamplePos=0; curSamplePos=0;
curSamplePeriod=0; curSamplePeriod=0;
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) {
curSample=ins->amiga.getSample(chan[c.chan].sampleNote);
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote);
// TODO support offset commands
curSamplePos=0;
curSamplePeriod=0;
} }
chan[c.chan].active=true; chan[c.chan].active=true;
chan[c.chan].keyOn=true; chan[c.chan].keyOn=true;