You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.3 KiB

#include <cstdio>
#include <cmath>
#define USE_LUTS
#include "synth/dsp/filter.h"
#include "synth/dsp/util.h"
void dumpLUT(const char * filename, const char * identifier, float *lut, size_t size) {
FILE * f = fopen(filename, "w");
fprintf(f, "float %s[] = {\n", identifier);
for(int i = 0; i < size; ++i) {
if(i % 8 == 0) {
fputs(" ", f);
}
fprintf(f, "%13.7f", lut[i]);
if(i < size - 1) {
fputs(", ", f);
}
if(i % 8 == 7) {
putc('\n', f);
}
}
fputs("};\n", f);
fclose(f);
}
int main(int argc, char** argv) {
float kLUT[K_LUT_SIZE];
for(int i = 0; i < K_LUT_SIZE; ++i) {
kLUT[i] = tan(M_PI_4 * 0.002 * exp(i / (K_LUT_SIZE - 1.0) * FILTER_K_BASE));
}
dumpLUT("src/synth/dsp/filterlut.cpp", "kLUT", kLUT, K_LUT_SIZE);
float noteLUT[NOTE_LUT_SIZE];
for(int i = 0; i < NOTE_LUT_SIZE; ++i) {
noteLUT[i] = 440 * pow(2, (i - 69) / 12.0);
}
dumpLUT("src/synth/dsp/notelut.cpp", "noteLUT", noteLUT, NOTE_LUT_SIZE);
float centLUT[CENT_LUT_SIZE];
for(int i = 0; i < CENT_LUT_SIZE; ++i) {
centLUT[i] = pow(2, (float) i / ((CENT_LUT_SIZE - 1) * 12.0));
}
dumpLUT("src/synth/dsp/centlut.cpp", "centLUT", centLUT, CENT_LUT_SIZE);
}