Feat: add triangle lookup table generator

Refs: #2
pull/5/head
rkcf 2023-02-26 16:55:55 -06:00
parent e886b4cac2
commit 916f874a8f
2 changed files with 27 additions and 2 deletions

View File

@ -49,7 +49,28 @@ sample_table_t gen_saw()
return saw_vals;
}
sample_table_t gen_isaw() {
sample_table_t gen_tri()
{
sample_table_t tri_vals = {0};
uint16_t half_samples = DEFAULT_N_SAMPLES / 2;
float_t step = 2.0 / half_samples; // calculate our incremental step size
float_t val = 0; // place to store calculate value
// Start low go high then low [0, 1, 0]
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
tri_vals[i] = val;
if (i < half_samples) {
val += step;
} else {
val -= step;
}
}
return tri_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

View File

@ -25,18 +25,20 @@ static void log(std::string message)
int main()
{
log("Generating wave cycle lookup tables");
Wave sin_wave, squ_wave, saw_wave, isaw_wave;
Wave sin_wave, squ_wave, saw_wave, tri_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 tri_vals = gen_tri();
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);
tri_wave.setTable(tri_vals);
isaw_wave.setTable(isaw_vals);
log("Printing head of sine table");
@ -45,6 +47,8 @@ int main()
squ_wave.print_head();
log("Printing head of saw table");
saw_wave.print_head();
log("Printing head of triangle table");
tri_wave.print_head();
log("Printing head of inverse saw table");
isaw_wave.print_head();