This commit is contained in:
tildearrow 2023-09-07 23:37:17 -05:00
parent a4698dc911
commit d81a181ba5
3 changed files with 33 additions and 3 deletions

View file

@ -26,6 +26,7 @@ float* DivFilterTables::cubicTable=NULL;
float* DivFilterTables::sincTable=NULL; float* DivFilterTables::sincTable=NULL;
float* DivFilterTables::sincTable8=NULL; float* DivFilterTables::sincTable8=NULL;
float* DivFilterTables::sincIntegralTable=NULL; float* DivFilterTables::sincIntegralTable=NULL;
float* DivFilterTables::sincIntegralSmallTable=NULL;
// portions from Schism Tracker (scripts/lutgen.c) // portions from Schism Tracker (scripts/lutgen.c)
// licensed under same license as this program. // licensed under same license as this program.
@ -106,3 +107,25 @@ float* DivFilterTables::getSincIntegralTable() {
} }
return sincIntegralTable; return sincIntegralTable;
} }
float* DivFilterTables::getSincIntegralSmallTable() {
if (sincIntegralSmallTable==NULL) {
logD("initializing small sinc integral table.");
sincIntegralSmallTable=new float[256];
sincIntegralSmallTable[0]=-0.5f;
for (int i=1; i<256; i++) {
int mapped=((i&31)<<3)|(i>>5);
int mappedPrev=(((i-1)&31)<<3)|((i-1)>>5);
double x=(double)i*M_PI/32.0;
double sinc=sin(x)/x;
sincIntegralSmallTable[mapped]=sincIntegralSmallTable[mappedPrev]+(sinc/32.0);
}
for (int i=0; i<256; i++) {
int mapped=((i&31)<<3)|(i>>5);
sincIntegralSmallTable[mapped]*=pow(cos(M_PI*(double)i/512.0),2.0);
}
}
return sincIntegralSmallTable;
}

View file

@ -23,6 +23,7 @@ class DivFilterTables {
static float* sincTable; static float* sincTable;
static float* sincTable8; static float* sincTable8;
static float* sincIntegralTable; static float* sincIntegralTable;
static float* sincIntegralSmallTable;
/** /**
* get a 1024x4 cubic spline table. * get a 1024x4 cubic spline table.
@ -47,4 +48,10 @@ class DivFilterTables {
* @return the table. * @return the table.
*/ */
static float* getSincIntegralTable(); static float* getSincIntegralTable();
/**
* get a 32x8 one-side sine-windowed sinc integral table.
* @return the table.
*/
static float* getSincIntegralSmallTable();
}; };

View file

@ -55,7 +55,7 @@ void FurnaceGUI::readOsc() {
oscValues[ch]=new float[1024]; oscValues[ch]=new float[1024];
} }
memset(oscValues[ch],0,1024*sizeof(float)); memset(oscValues[ch],0,1024*sizeof(float));
float* sincITable=DivFilterTables::getSincIntegralTable(); float* sincITable=DivFilterTables::getSincIntegralSmallTable();
float posFrac=0.0; float posFrac=0.0;
float factor=(float)oscWidth/(float)winSize; float factor=(float)oscWidth/(float)winSize;
@ -67,11 +67,11 @@ void FurnaceGUI::readOsc() {
posFrac+=1.0; posFrac+=1.0;
while (posFrac>=1.0) { while (posFrac>=1.0) {
unsigned int n=((unsigned int)(posFrac*8192.0))&8191; unsigned int n=((unsigned int)(posFrac*32.0))&31;
posFrac-=factor; posFrac-=factor;
posInt++; posInt++;
float* t1=&sincITable[(8191-n)<<3]; float* t1=&sincITable[(31-n)<<3];
float* t2=&sincITable[n<<3]; float* t2=&sincITable[n<<3];
float delta=e->oscBuf[ch][posInt&0x7fff]-e->oscBuf[ch][(posInt-1)&0x7fff]; float delta=e->oscBuf[ch][posInt&0x7fff]-e->oscBuf[ch][(posInt-1)&0x7fff];