From 902febe298d6428df333f6ddc8ac6ea95fe41643 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 4 Feb 2022 03:29:40 -0500 Subject: [PATCH] actually implement pitch of C-4 --- src/engine/engine.cpp | 2 +- src/engine/engine.h | 4 +-- src/engine/platform/amiga.cpp | 44 +++++++++++++++++++++++++++------ src/engine/platform/arcade.cpp | 7 +++++- src/engine/platform/genesis.cpp | 11 ++++++++- src/engine/platform/nes.cpp | 7 +++++- src/engine/platform/pce.cpp | 11 ++++++++- 7 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 9e3fec917..395c6e5f2 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -4911,7 +4911,7 @@ void DivEngine::previewSample(int sample, int note) { blip_clear(samp_bb); double rate=song.sample[sample]->rate; 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; } blip_set_rates(samp_bb,rate,got.rate); diff --git a/src/engine/engine.h b/src/engine/engine.h index f851e82c4..fd5fe8e9b 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -11,8 +11,8 @@ #include #include -#define DIV_VERSION "0.5.2pre1" -#define DIV_ENGINE_VERSION 37 +#define DIV_VERSION "0.5.2pre2" +#define DIV_ENGINE_VERSION 38 enum DivStatusView { DIV_STATUS_NOTHING=0, diff --git a/src/engine/platform/amiga.cpp b/src/engine/platform/amiga.cpp index 12ab18a5b..fe63d0817 100644 --- a/src/engine/platform/amiga.cpp +++ b/src/engine/platform/amiga.cpp @@ -94,18 +94,27 @@ void DivPlatformAmiga::tick() { if (chan[i].std.hadVol) { 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].samplesong.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].inPorta) { 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 { - 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; } else { 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; } } @@ -138,10 +147,19 @@ int DivPlatformAmiga::dispatch(DivCommand c) { switch (c.cmd) { case DIV_CMD_NOTE_ON: { 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; + double off=1.0; + if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.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) { chan[c.chan].sample=-1; } @@ -212,11 +230,21 @@ int DivPlatformAmiga::dispatch(DivCommand c) { } break; } - 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))); + case DIV_CMD_LEGATO: { + double off=1.0; + if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.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].note=c.value; break; + } case DIV_CMD_PRE_PORTA: chan[c.chan].std.init(parent->getIns(chan[c.chan].ins)); chan[c.chan].inPorta=c.value; diff --git a/src/engine/platform/arcade.cpp b/src/engine/platform/arcade.cpp index dd6492809..fc77ead23 100644 --- a/src/engine/platform/arcade.cpp +++ b/src/engine/platform/arcade.cpp @@ -370,7 +370,12 @@ void DivPlatformArcade::tick() { if (chan[i].freqChanged) { chan[i].freq=chan[i].baseFreq+(chan[i].pitch>>1)-64; 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.samplesong.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) { addWrite(0x10007+((i-8)<<3),chan[i].pcm.freq); } diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index e1fcd4e4f..4f487bb7f 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -299,7 +299,16 @@ void DivPlatformGenesis::tick() { immWrite(chanOffs[i]+ADDR_FREQH,freqt>>8); immWrite(chanOffs[i]+ADDR_FREQ,freqt&0xff); if (chan[i].furnaceDac) { - dacRate=(1280000*1.25)/chan[i].baseFreq; + double off=1.0; + if (dacSample>=0 && dacSamplesong.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); } chan[i].freqChanged=false; diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index 98d3ea894..d604ded5e 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -194,7 +194,12 @@ void DivPlatformNES::tick() { if (chan[4].freqChanged) { chan[4].freq=parent->calcFreq(chan[4].baseFreq,chan[4].pitch,false); if (chan[4].furnaceDac) { - dacRate=MIN(chan[4].freq,32000); + double off=1.0; + if (dacSample>=0 && dacSamplesong.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); } chan[4].freqChanged=false; diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index a1a08891c..497d46114 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -154,7 +154,16 @@ void DivPlatformPCE::tick() { //DivInstrument* ins=parent->getIns(chan[i].ins); chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].furnaceDac) { - chan[i].dacRate=(chipClock/2)/chan[i].freq; + double off=1.0; + if (chan[i].dacSample>=0 && chan[i].dacSamplesong.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 (chan[i].freq>4095) chan[i].freq=4095;