mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-05 04:15:05 +00:00
potentially breaking change: better freq formula
now using a 4096-entry-long table for calculating final period/frequency see issue #303
This commit is contained in:
parent
03da02711a
commit
ed857b20c4
3 changed files with 22 additions and 5 deletions
|
@ -832,9 +832,17 @@ double DivEngine::calcBaseFreq(double clock, double divider, int note, bool peri
|
|||
|
||||
int DivEngine::calcFreq(int base, int pitch, bool period, int octave) {
|
||||
if (song.linearPitch) {
|
||||
pitch+=2048;
|
||||
if (pitch<0) pitch=0;
|
||||
if (pitch>4095) pitch=4095;
|
||||
return period?
|
||||
(base*reversePitchTable[pitch])>>10:
|
||||
(base*pitchTable[pitch])>>10;
|
||||
/*
|
||||
return period?
|
||||
base*pow(2,-(double)pitch/(12.0*128.0))/(98.0+globalPitch*6.0)*98.0:
|
||||
(base*pow(2,(double)pitch/(12.0*128.0))*(98+globalPitch*6))/98;
|
||||
*/
|
||||
}
|
||||
return period?
|
||||
base-pitch:
|
||||
|
@ -2850,6 +2858,10 @@ bool DivEngine::init() {
|
|||
for (int i=0; i<64; i++) {
|
||||
vibTable[i]=127*sin(((double)i/64.0)*(2*M_PI));
|
||||
}
|
||||
for (int i=0; i<4096; i++) {
|
||||
reversePitchTable[i]=round(1024.0*pow(2.0,(2048.0-(double)i)/(12.0*128.0)));
|
||||
pitchTable[i]=round(1024.0*pow(2.0,((double)i-2048.0)/(12.0*128.0)));
|
||||
}
|
||||
|
||||
for (int i=0; i<DIV_MAX_CHANS; i++) {
|
||||
isMuted[i]=0;
|
||||
|
|
|
@ -227,6 +227,8 @@ class DivEngine {
|
|||
} sPreview;
|
||||
|
||||
short vibTable[64];
|
||||
int reversePitchTable[4096];
|
||||
int pitchTable[4096];
|
||||
|
||||
blip_buffer_t* samp_bb;
|
||||
size_t samp_bbInLen;
|
||||
|
|
|
@ -22,10 +22,12 @@
|
|||
#include <math.h>
|
||||
|
||||
#define rWrite(a,v) {regPool[(a)]=(v)&0xff; vic_sound_machine_store(vic,a,(v)&0xff);}
|
||||
|
||||
#define CHIP_DIVIDER 32
|
||||
#define SAMP_DIVIDER 4
|
||||
|
||||
const int chipDividers[4]={
|
||||
128, 64, 32, 64
|
||||
};
|
||||
|
||||
const char* regCheatSheetVIC[]={
|
||||
"CH1_Pitch", "0A",
|
||||
"CH2_Pitch", "0B",
|
||||
|
@ -93,6 +95,7 @@ void DivPlatformVIC20::writeOutVol(int ch) {
|
|||
|
||||
void DivPlatformVIC20::tick() {
|
||||
for (int i=0; i<4; i++) {
|
||||
int CHIP_DIVIDER=chipDividers[i];
|
||||
chan[i].std.next();
|
||||
if (chan[i].std.hadVol) {
|
||||
int env=chan[i].std.vol;
|
||||
|
@ -121,10 +124,9 @@ void DivPlatformVIC20::tick() {
|
|||
}
|
||||
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
|
||||
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true);
|
||||
if (i<3) chan[i].freq>>=(2-i);
|
||||
else chan[i].freq>>=1;
|
||||
printf("%d freq: %d\n",i,chan[i].freq);
|
||||
if (chan[i].freq<1) chan[i].freq=1;
|
||||
if (chan[i].freq>127) chan[i].freq=0;
|
||||
if (chan[i].freq>127) chan[i].freq=127;
|
||||
if (isMuted[i]) chan[i].keyOn=false;
|
||||
if (chan[i].keyOn) {
|
||||
if (i<3) {
|
||||
|
@ -150,6 +152,7 @@ void DivPlatformVIC20::tick() {
|
|||
}
|
||||
|
||||
int DivPlatformVIC20::dispatch(DivCommand c) {
|
||||
int CHIP_DIVIDER=chipDividers[c.chan];
|
||||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
||||
|
|
Loading…
Reference in a new issue