From d766c4aaf0c8584530ea9193b085ddf308469118 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 28 Dec 2021 00:51:38 -0500 Subject: [PATCH] finally do EFxx right took a while to figure out... --- src/engine/engine.cpp | 6 ++++++ src/engine/engine.h | 3 +++ src/engine/platform/c64.cpp | 2 +- src/engine/platform/dummy.cpp | 3 ++- src/engine/platform/gb.cpp | 2 +- src/engine/platform/genesis.cpp | 2 +- src/engine/platform/genesisext.cpp | 2 +- src/engine/platform/nes.cpp | 2 +- src/engine/platform/pce.cpp | 2 +- src/engine/platform/sms.cpp | 4 ++-- src/engine/platform/ym2610.cpp | 4 ++-- src/engine/platform/ym2610ext.cpp | 2 +- src/engine/playback.cpp | 26 +------------------------- 13 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 28ff1373d..9f40c3f84 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1534,6 +1534,12 @@ void DivEngine::playSub(bool preserveDrift) { } } +int DivEngine::calcFreq(int base, int pitch, bool period) { + return period? + int(base*pow(2,-(double)pitch/(12.0*128.0))/(98.0+globalPitch*6.0)*98.0): + (int(base*pow(2,(double)pitch/(12.0*128.0))*(98+globalPitch*6))/98); +} + void DivEngine::play() { isBusy.lock(); playSub(false); diff --git a/src/engine/engine.h b/src/engine/engine.h index a4eae07fc..aeb0cabf7 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -157,6 +157,9 @@ class DivEngine { void setConf(String key, double value); void setConf(String key, String value); + // calculate frequency/period + int calcFreq(int base, int pitch, bool period=false); + // play void play(); diff --git a/src/engine/platform/c64.cpp b/src/engine/platform/c64.cpp index e8a5f65fb..7ec478151 100644 --- a/src/engine/platform/c64.cpp +++ b/src/engine/platform/c64.cpp @@ -69,7 +69,7 @@ void DivPlatformC64::tick() { rWrite(i*7+4,(isMuted[i]?0:(chan[i].wave<<4))|(chan[i].ring<<2)|(chan[i].sync<<1)|chan[i].active); } if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch); if (chan[i].freq>0xffff) chan[i].freq=0xffff; if (chan[i].keyOn) { rWrite(i*7+5,(chan[i].attack<<4)|(chan[i].decay)); diff --git a/src/engine/platform/dummy.cpp b/src/engine/platform/dummy.cpp index d4497ef50..f29524f0e 100644 --- a/src/engine/platform/dummy.cpp +++ b/src/engine/platform/dummy.cpp @@ -1,4 +1,5 @@ #include "dummy.h" +#include "../engine.h" #include #include @@ -25,7 +26,7 @@ void DivPlatformDummy::tick() { if (chan[i].freqChanged) { chan[i].freqChanged=false; - chan[i].freq=(chan[i].baseFreq*pow(2,(double)chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch); } } } diff --git a/src/engine/platform/gb.cpp b/src/engine/platform/gb.cpp index 5441f0fce..01506de5a 100644 --- a/src/engine/platform/gb.cpp +++ b/src/engine/platform/gb.cpp @@ -126,7 +126,7 @@ void DivPlatformGB::tick() { if (i==3) { // noise chan[i].freq=noiseTable[chan[i].baseFreq]; } else { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)-chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].freq>2047) chan[i].freq=2047; } if (chan[i].note>0x5d) chan[i].freq=0x01; diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 055481625..7b11b1b15 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -94,7 +94,7 @@ void DivPlatformGenesis::tick() { for (int i=0; i<6; i++) { if (i==2 && extMode) continue; if (chan[i].freqChanged) { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch); int freqt=toFreq(chan[i].freq); immWrite(chanOffs[i]+0xa4,freqt>>8); immWrite(chanOffs[i]+0xa0,freqt&0xff); diff --git a/src/engine/platform/genesisext.cpp b/src/engine/platform/genesisext.cpp index 4343f8ae3..50669c442 100644 --- a/src/engine/platform/genesisext.cpp +++ b/src/engine/platform/genesisext.cpp @@ -241,7 +241,7 @@ void DivPlatformGenesisExt::tick() { unsigned char writeMask=2; if (extMode) for (int i=0; i<4; i++) { if (opChan[i].freqChanged) { - opChan[i].freq=(opChan[i].baseFreq*pow(2,(double)opChan[i].pitch/(12.0*128.0))); + opChan[i].freq=parent->calcFreq(opChan[i].baseFreq,opChan[i].pitch); if (opChan[i].freq>=82432) { opChan[i].freqH=((opChan[i].freq>>15)&7)|0x38; opChan[i].freqL=(opChan[i].freq>>7)&0xff; diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index f37b25769..82e34df0c 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -121,7 +121,7 @@ void DivPlatformNES::tick() { if (i==3) { // noise chan[i].freq=noiseTable[chan[i].baseFreq]; } else { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)-chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].freq>2047) chan[i].freq=2047; } if (chan[i].keyOn) { diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index a6acb74df..f5213bf3b 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -111,7 +111,7 @@ void DivPlatformPCE::tick() { } if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { //DivInstrument* ins=parent->getIns(chan[i].ins); - chan[i].freq=(chan[i].baseFreq*pow(2,(double)-chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].freq>4095) chan[i].freq=4095; if (chan[i].note>0x5d) chan[i].freq=0x01; chWrite(i,0x02,chan[i].freq&0xff); diff --git a/src/engine/platform/sms.cpp b/src/engine/platform/sms.cpp index bf6ce7167..eff4ef77c 100644 --- a/src/engine/platform/sms.cpp +++ b/src/engine/platform/sms.cpp @@ -37,7 +37,7 @@ void DivPlatformSMS::tick() { } for (int i=0; i<3; i++) { if (chan[i].freqChanged) { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)-chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].note>0x5d) chan[i].freq=0x01; sn->write(0x80|i<<5|(chan[i].freq&15)); sn->write(chan[i].freq>>4); @@ -46,7 +46,7 @@ void DivPlatformSMS::tick() { } if (chan[3].freqChanged || updateSNMode) { updateSNMode=false; - chan[3].freq=(chan[3].baseFreq*pow(2,(double)-chan[3].pitch/(12.0*128.0))); + chan[3].freq=parent->calcFreq(chan[3].baseFreq,chan[3].pitch,true); if (chan[3].note>0x5d) chan[3].freq=0x01; chan[3].freqChanged=false; if (snNoiseMode&2) { // take period from channel 3 diff --git a/src/engine/platform/ym2610.cpp b/src/engine/platform/ym2610.cpp index 538ef30fd..63c70659f 100644 --- a/src/engine/platform/ym2610.cpp +++ b/src/engine/platform/ym2610.cpp @@ -75,7 +75,7 @@ void DivPlatformYM2610::tick() { chan[i].psgMode|=(chan[i].std.wave+1)&3; } if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)-chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].freq>4095) chan[i].freq=4095; if (chan[i].keyOn) { //rWrite(16+i*5+1,((chan[i].duty&3)<<6)|(63-(ins->gb.soundLen&63))); @@ -119,7 +119,7 @@ void DivPlatformYM2610::tick() { for (int i=0; i<4; i++) { if (i==1 && extMode) continue; if (chan[i].freqChanged) { - chan[i].freq=(chan[i].baseFreq*pow(2,(double)chan[i].pitch/(12.0*128.0))); + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch); int freqt=toFreq(chan[i].freq); immWrite(chanOffs[i]+0xa4,freqt>>8); immWrite(chanOffs[i]+0xa0,freqt&0xff); diff --git a/src/engine/platform/ym2610ext.cpp b/src/engine/platform/ym2610ext.cpp index 8a1802025..ad1466313 100644 --- a/src/engine/platform/ym2610ext.cpp +++ b/src/engine/platform/ym2610ext.cpp @@ -217,7 +217,7 @@ void DivPlatformYM2610Ext::tick() { unsigned char writeMask=2; if (extMode) for (int i=0; i<4; i++) { if (opChan[i].freqChanged) { - opChan[i].freq=(opChan[i].baseFreq*pow(2,(double)opChan[i].pitch/(12.0*128.0))); + opChan[i].freq=parent->calcFreq(opChan[i].baseFreq,opChan[i].pitch); int freqt=toFreq(opChan[i].freq); opChan[i].freqH=freqt>>8; opChan[i].freqL=freqt&0xff; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index c15b8fc72..c7d3df89a 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -522,31 +522,7 @@ void DivEngine::processRow(int i, bool afterDelay) { extValuePresent=true; break; case 0xef: // global pitch - for (int i=0; i0x80) { - for (int i=0; i