actually implement pitch of C-4

This commit is contained in:
tildearrow 2022-02-04 03:29:40 -05:00
parent 6a29ee63f5
commit 902febe298
7 changed files with 71 additions and 15 deletions

View file

@ -4911,7 +4911,7 @@ void DivEngine::previewSample(int sample, int note) {
blip_clear(samp_bb); blip_clear(samp_bb);
double rate=song.sample[sample]->rate; double rate=song.sample[sample]->rate;
if (note>=0) { if (note>=0) {
rate=(song.tuning*pow(2.0,(double)(note+3)/12.0)); rate=(song.tuning*pow(2.0,(double)(note+3)/12.0)*((double)song.sample[sample]->centerRate/8363.0));
if (rate<=0) rate=song.sample[sample]->rate; if (rate<=0) rate=song.sample[sample]->rate;
} }
blip_set_rates(samp_bb,rate,got.rate); blip_set_rates(samp_bb,rate,got.rate);

View file

@ -11,8 +11,8 @@
#include <map> #include <map>
#include <queue> #include <queue>
#define DIV_VERSION "0.5.2pre1" #define DIV_VERSION "0.5.2pre2"
#define DIV_ENGINE_VERSION 37 #define DIV_ENGINE_VERSION 38
enum DivStatusView { enum DivStatusView {
DIV_STATUS_NOTHING=0, DIV_STATUS_NOTHING=0,

View file

@ -94,18 +94,27 @@ void DivPlatformAmiga::tick() {
if (chan[i].std.hadVol) { if (chan[i].std.hadVol) {
chan[i].outVol=((chan[i].vol%65)*MIN(64,chan[i].std.vol))>>6; chan[i].outVol=((chan[i].vol%65)*MIN(64,chan[i].std.vol))>>6;
} }
double off=1.0;
if (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[i].sample];
if (s->centerRate<1) {
off=1.0;
} else {
off=8363.0/(double)s->centerRate;
}
}
if (chan[i].std.hadArp) { if (chan[i].std.hadArp) {
if (!chan[i].inPorta) { if (!chan[i].inPorta) {
if (chan[i].std.arpMode) { if (chan[i].std.arpMode) {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].std.arp); chan[i].baseFreq=off*NOTE_PERIODIC(chan[i].std.arp);
} else { } else {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note+chan[i].std.arp); chan[i].baseFreq=off*NOTE_PERIODIC(chan[i].note+chan[i].std.arp);
} }
} }
chan[i].freqChanged=true; chan[i].freqChanged=true;
} else { } else {
if (chan[i].std.arpMode && chan[i].std.finishedArp) { if (chan[i].std.arpMode && chan[i].std.finishedArp) {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note); chan[i].baseFreq=off*NOTE_PERIODIC(chan[i].note);
chan[i].freqChanged=true; chan[i].freqChanged=true;
} }
} }
@ -138,10 +147,19 @@ int DivPlatformAmiga::dispatch(DivCommand c) {
switch (c.cmd) { switch (c.cmd) {
case DIV_CMD_NOTE_ON: { case DIV_CMD_NOTE_ON: {
DivInstrument* ins=parent->getIns(chan[c.chan].ins); DivInstrument* ins=parent->getIns(chan[c.chan].ins);
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
}
chan[c.chan].sample=ins->amiga.initSample; chan[c.chan].sample=ins->amiga.initSample;
double off=1.0;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[c.chan].sample];
if (s->centerRate<1) {
off=1.0;
} else {
off=8363.0/(double)s->centerRate;
}
}
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=off*NOTE_PERIODIC(c.value);
}
if (chan[c.chan].sample<0 || chan[c.chan].sample>=parent->song.sampleLen) { if (chan[c.chan].sample<0 || chan[c.chan].sample>=parent->song.sampleLen) {
chan[c.chan].sample=-1; chan[c.chan].sample=-1;
} }
@ -212,11 +230,21 @@ int DivPlatformAmiga::dispatch(DivCommand c) {
} }
break; break;
} }
case DIV_CMD_LEGATO: case DIV_CMD_LEGATO: {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((chan[c.chan].std.willArp && !chan[c.chan].std.arpMode)?(chan[c.chan].std.arp-12):(0))); double off=1.0;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[c.chan].sample];
if (s->centerRate<1) {
off=1.0;
} else {
off=8363.0/(double)s->centerRate;
}
}
chan[c.chan].baseFreq=off*NOTE_PERIODIC(c.value+((chan[c.chan].std.willArp && !chan[c.chan].std.arpMode)?(chan[c.chan].std.arp-12):(0)));
chan[c.chan].freqChanged=true; chan[c.chan].freqChanged=true;
chan[c.chan].note=c.value; chan[c.chan].note=c.value;
break; break;
}
case DIV_CMD_PRE_PORTA: case DIV_CMD_PRE_PORTA:
chan[c.chan].std.init(parent->getIns(chan[c.chan].ins)); chan[c.chan].std.init(parent->getIns(chan[c.chan].ins));
chan[c.chan].inPorta=c.value; chan[c.chan].inPorta=c.value;

View file

@ -370,7 +370,12 @@ void DivPlatformArcade::tick() {
if (chan[i].freqChanged) { if (chan[i].freqChanged) {
chan[i].freq=chan[i].baseFreq+(chan[i].pitch>>1)-64; chan[i].freq=chan[i].baseFreq+(chan[i].pitch>>1)-64;
if (chan[i].furnacePCM) { if (chan[i].furnacePCM) {
chan[i].pcm.freq=MIN(255,((parent->song.tuning*pow(2.0,double(chan[i].freq+256)/(64.0*12.0)))*255)/31250); double off=1.0;
if (chan[i].pcm.sample>=0 && chan[i].pcm.sample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[i].pcm.sample];
off=(double)s->centerRate/8363.0;
}
chan[i].pcm.freq=MIN(255,((off*parent->song.tuning*pow(2.0,double(chan[i].freq+256)/(64.0*12.0)))*255)/31250);
if (dumpWrites && i>=8) { if (dumpWrites && i>=8) {
addWrite(0x10007+((i-8)<<3),chan[i].pcm.freq); addWrite(0x10007+((i-8)<<3),chan[i].pcm.freq);
} }

View file

@ -299,7 +299,16 @@ void DivPlatformGenesis::tick() {
immWrite(chanOffs[i]+ADDR_FREQH,freqt>>8); immWrite(chanOffs[i]+ADDR_FREQH,freqt>>8);
immWrite(chanOffs[i]+ADDR_FREQ,freqt&0xff); immWrite(chanOffs[i]+ADDR_FREQ,freqt&0xff);
if (chan[i].furnaceDac) { if (chan[i].furnaceDac) {
dacRate=(1280000*1.25)/chan[i].baseFreq; double off=1.0;
if (dacSample>=0 && dacSample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[dacSample];
if (s->centerRate<1) {
off=1.0;
} else {
off=8363.0/(double)s->centerRate;
}
}
dacRate=(1280000*1.25*off)/chan[i].baseFreq;
if (dumpWrites) addWrite(0xffff0001,1280000/dacRate); if (dumpWrites) addWrite(0xffff0001,1280000/dacRate);
} }
chan[i].freqChanged=false; chan[i].freqChanged=false;

View file

@ -194,7 +194,12 @@ void DivPlatformNES::tick() {
if (chan[4].freqChanged) { if (chan[4].freqChanged) {
chan[4].freq=parent->calcFreq(chan[4].baseFreq,chan[4].pitch,false); chan[4].freq=parent->calcFreq(chan[4].baseFreq,chan[4].pitch,false);
if (chan[4].furnaceDac) { if (chan[4].furnaceDac) {
dacRate=MIN(chan[4].freq,32000); double off=1.0;
if (dacSample>=0 && dacSample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[dacSample];
off=(double)s->centerRate/8363.0;
}
dacRate=MIN(chan[4].freq*off,32000);
if (dumpWrites) addWrite(0xffff0001,dacRate); if (dumpWrites) addWrite(0xffff0001,dacRate);
} }
chan[4].freqChanged=false; chan[4].freqChanged=false;

View file

@ -154,7 +154,16 @@ void DivPlatformPCE::tick() {
//DivInstrument* ins=parent->getIns(chan[i].ins); //DivInstrument* ins=parent->getIns(chan[i].ins);
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true);
if (chan[i].furnaceDac) { if (chan[i].furnaceDac) {
chan[i].dacRate=(chipClock/2)/chan[i].freq; double off=1.0;
if (chan[i].dacSample>=0 && chan[i].dacSample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[i].dacSample];
if (s->centerRate<1) {
off=1.0;
} else {
off=8363.0/(double)s->centerRate;
}
}
chan[i].dacRate=((double)chipClock/2)/(off*chan[i].freq);
if (dumpWrites) addWrite(0xffff0001+(i<<8),chan[i].dacRate); if (dumpWrites) addWrite(0xffff0001+(i<<8),chan[i].dacRate);
} }
if (chan[i].freq>4095) chan[i].freq=4095; if (chan[i].freq>4095) chan[i].freq=4095;