parent
6a2f2911e7
commit
e886b4cac2
|
|
@ -27,7 +27,7 @@ sample_table_t gen_squ()
|
||||||
if (i < (DEFAULT_N_SAMPLES / 2)) {
|
if (i < (DEFAULT_N_SAMPLES / 2)) {
|
||||||
squ_vals[i] = 1;
|
squ_vals[i] = 1;
|
||||||
} else {
|
} 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 step = 2.0 / DEFAULT_N_SAMPLES; // calculate our incremental step size
|
||||||
float_t val = 0; // place to store calculate value
|
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++) {
|
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
|
||||||
saw_vals[i] = val;
|
saw_vals[i] = val;
|
||||||
val += step;
|
val += step;
|
||||||
|
|
@ -48,3 +48,17 @@ sample_table_t gen_saw()
|
||||||
|
|
||||||
return saw_vals;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,19 @@ static void log(std::string message)
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
log("Generating wave cycle lookup tables");
|
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
|
// Calculate fundamental wave values
|
||||||
sample_table_t sin_vals = gen_sin();
|
sample_table_t sin_vals = gen_sin();
|
||||||
sample_table_t squ_vals = gen_squ();
|
sample_table_t squ_vals = gen_squ();
|
||||||
sample_table_t saw_vals = gen_saw();
|
sample_table_t saw_vals = gen_saw();
|
||||||
|
sample_table_t isaw_vals = gen_isaw();
|
||||||
|
|
||||||
// Set wave lookup table values
|
// Set wave lookup table values
|
||||||
sin_wave.setTable(sin_vals);
|
sin_wave.setTable(sin_vals);
|
||||||
squ_wave.setTable(squ_vals);
|
squ_wave.setTable(squ_vals);
|
||||||
saw_wave.setTable(saw_vals);
|
saw_wave.setTable(saw_vals);
|
||||||
|
isaw_wave.setTable(isaw_vals);
|
||||||
|
|
||||||
log("Printing head of sine table");
|
log("Printing head of sine table");
|
||||||
sin_wave.print_head();
|
sin_wave.print_head();
|
||||||
|
|
@ -43,6 +45,8 @@ int main()
|
||||||
squ_wave.print_head();
|
squ_wave.print_head();
|
||||||
log("Printing head of saw table");
|
log("Printing head of saw table");
|
||||||
saw_wave.print_head();
|
saw_wave.print_head();
|
||||||
|
log("Printing head of inverse saw table");
|
||||||
|
isaw_wave.print_head();
|
||||||
|
|
||||||
// Create Wavetable object containing fundamental Wave objects
|
// Create Wavetable object containing fundamental Wave objects
|
||||||
Wavetable wt_01{"Fundamental Waves"};
|
Wavetable wt_01{"Fundamental Waves"};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue