Feat: add inverse saw lookup table generation

Refs: #2
pull/5/head
rkcf 2023-02-26 16:45:02 -06:00
parent 6a2f2911e7
commit e886b4cac2
2 changed files with 21 additions and 3 deletions

View File

@ -27,7 +27,7 @@ sample_table_t gen_squ()
if (i < (DEFAULT_N_SAMPLES / 2)) {
squ_vals[i] = 1;
} else {
squ_vals[i] = -1;
squ_vals[i] = 0;
}
}
@ -40,7 +40,7 @@ sample_table_t gen_saw()
float_t step = 2.0 / DEFAULT_N_SAMPLES; // calculate our incremental step size
float_t val = 0; // place to store calculate value
// Start low go high [-1, 1]
// Start low go high [0, 1]
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
saw_vals[i] = val;
val += step;
@ -48,3 +48,17 @@ sample_table_t gen_saw()
return saw_vals;
}
sample_table_t gen_isaw() {
sample_table_t isaw_vals = {0};
float_t step = 2.0 / DEFAULT_N_SAMPLES; // calculate our incremental step size
float_t val = 1; // place to store calculate value
// Start high go low [1, 0]
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
isaw_vals[i] = val;
val -= step;
}
return isaw_vals;
}

View File

@ -25,17 +25,19 @@ static void log(std::string message)
int main()
{
log("Generating wave cycle lookup tables");
Wave sin_wave, squ_wave, saw_wave;
Wave sin_wave, squ_wave, saw_wave, isaw_wave;
// Calculate fundamental wave values
sample_table_t sin_vals = gen_sin();
sample_table_t squ_vals = gen_squ();
sample_table_t saw_vals = gen_saw();
sample_table_t isaw_vals = gen_isaw();
// Set wave lookup table values
sin_wave.setTable(sin_vals);
squ_wave.setTable(squ_vals);
saw_wave.setTable(saw_vals);
isaw_wave.setTable(isaw_vals);
log("Printing head of sine table");
sin_wave.print_head();
@ -43,6 +45,8 @@ int main()
squ_wave.print_head();
log("Printing head of saw table");
saw_wave.print_head();
log("Printing head of inverse saw table");
isaw_wave.print_head();
// Create Wavetable object containing fundamental Wave objects
Wavetable wt_01{"Fundamental Waves"};