Merge branch 'master' into feature/Moar-patch-bank-support-part3

This commit is contained in:
James Alan Nguyen 2022-05-12 09:57:11 +10:00
commit 4354e4064b
68 changed files with 4941 additions and 403 deletions

View file

@ -986,38 +986,66 @@ int DivEngine::calcBaseFreq(double clock, double divider, int note, bool period)
}*/
double DivEngine::calcBaseFreq(double clock, double divider, int note, bool period) {
if (song.linearPitch==2) { // full linear
return (note<<7);
}
double base=(period?(song.tuning*0.0625):song.tuning)*pow(2.0,(float)(note+3)/12.0);
return period?
(clock/base)/divider:
base*(divider/clock);
}
unsigned short DivEngine::calcBaseFreqFNumBlock(double clock, double divider, int note, int bits) {
int bf=calcBaseFreq(clock,divider,note,false);
int block=note/12;
if (block<0) block=0;
if (block>7) block=7;
bf>>=block;
if (bf<0) bf=0;
// octave boundaries
while (bf>0 && bf<644 && block>0) {
bf<<=1;
block--;
}
if (bf>1288) {
while (block<7) {
bf>>=1;
block++;
}
if (bf>((1<<bits)-1)) {
bf=(1<<bits)-1;
}
}
#define CONVERT_FNUM_BLOCK(bf,bits,note) \
double tuning=song.tuning; \
if (tuning<400.0) tuning=400.0; \
if (tuning>500.0) tuning=500.0; \
int boundaryBottom=tuning*pow(2.0,0.25)*(divider/clock); \
int boundaryTop=2.0*tuning*pow(2.0,0.25)*(divider/clock); \
int block=(note)/12; \
if (block<0) block=0; \
if (block>7) block=7; \
bf>>=block; \
if (bf<0) bf=0; \
/* octave boundaries */ \
while (bf>0 && bf<boundaryBottom && block>0) { \
bf<<=1; \
block--; \
} \
if (bf>boundaryTop) { \
while (block<7 && bf>boundaryTop) { \
bf>>=1; \
block++; \
} \
if (bf>((1<<bits)-1)) { \
bf=(1<<bits)-1; \
} \
} \
/* logV("f-num: %d block: %d",bf,block); */ \
return bf|(block<<bits);
int DivEngine::calcBaseFreqFNumBlock(double clock, double divider, int note, int bits) {
if (song.linearPitch==2) { // full linear
return (note<<7);
}
int bf=calcBaseFreq(clock,divider,note,false);
CONVERT_FNUM_BLOCK(bf,bits,note)
}
int DivEngine::calcFreq(int base, int pitch, bool period, int octave, int pitch2) {
if (song.linearPitch) {
int DivEngine::calcFreq(int base, int pitch, bool period, int octave, int pitch2, double clock, double divider, int blockBits) {
if (song.linearPitch==2) {
// do frequency calculation here
int nbase=base+pitch+pitch2;
double fbase=(period?(song.tuning*0.0625):song.tuning)*pow(2.0,(float)(nbase+384)/(128.0*12.0));
int bf=period?
round((clock/fbase)/divider):
round(fbase*(divider/clock));
if (blockBits>0) {
CONVERT_FNUM_BLOCK(bf,blockBits,nbase>>7)
} else {
return bf;
}
}
if (song.linearPitch==1) {
// global pitch multiplier
int whatTheFuck=(1024+(globalPitch<<6)-(globalPitch<0?globalPitch-6:0));
if (whatTheFuck<1) whatTheFuck=1; // avoids division by zero but please kill me
@ -1209,7 +1237,7 @@ void DivEngine::reset() {
chan[i]=DivChannelState();
if (i<chans) chan[i].volMax=(disCont[dispatchOfChan[i]].dispatch->dispatch(DivCommand(DIV_CMD_GET_VOLMAX,dispatchChanOfChan[i]))<<8)|0xff;
chan[i].volume=chan[i].volMax;
if (!song.linearPitch) chan[i].vibratoFine=4;
if (song.linearPitch==0) chan[i].vibratoFine=4;
}
extValue=0;
extValuePresent=0;