mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-27 15:03:01 +00:00
finally do EFxx right
took a while to figure out...
This commit is contained in:
parent
b246000f0e
commit
d766c4aaf0
13 changed files with 23 additions and 37 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "dummy.h"
|
||||
#include "../engine.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -522,31 +522,7 @@ void DivEngine::processRow(int i, bool afterDelay) {
|
|||
extValuePresent=true;
|
||||
break;
|
||||
case 0xef: // global pitch
|
||||
for (int i=0; i<chans; i++) {
|
||||
chan[i].pitch-=globalPitch;
|
||||
}
|
||||
// what is this mess?
|
||||
// are you for real? how does this effect even work?!
|
||||
if (effectVal>0x80) {
|
||||
for (int i=0; i<effectVal-0x80; i++) {
|
||||
if (globalPitch<=0) {
|
||||
globalPitch+=(120-(8*globalPitch)/55);
|
||||
} else {
|
||||
globalPitch+=(120-globalPitch/32);
|
||||
}
|
||||
}
|
||||
} else if (effectVal<0x80) {
|
||||
for (int i=0; i<0x80-effectVal; i++) {
|
||||
if (globalPitch<=0) {
|
||||
globalPitch-=(120-(8*globalPitch)/55);
|
||||
} else {
|
||||
globalPitch-=(120-globalPitch/32);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=0; i<chans; i++) {
|
||||
chan[i].pitch+=globalPitch;
|
||||
}
|
||||
globalPitch+=(signed char)(effectVal-0x80);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue