parent
32f1445862
commit
6a2f2911e7
|
|
@ -33,3 +33,18 @@ sample_table_t gen_squ()
|
||||||
|
|
||||||
return squ_vals;
|
return squ_vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sample_table_t gen_saw()
|
||||||
|
{
|
||||||
|
sample_table_t saw_vals = {0};
|
||||||
|
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]
|
||||||
|
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
|
||||||
|
saw_vals[i] = val;
|
||||||
|
val += step;
|
||||||
|
}
|
||||||
|
|
||||||
|
return saw_vals;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,24 +19,19 @@ sample_table_t gen_sin();
|
||||||
*/
|
*/
|
||||||
sample_table_t gen_squ();
|
sample_table_t gen_squ();
|
||||||
|
|
||||||
/*! Generate triangle wave data
|
|
||||||
@return a table of values
|
|
||||||
*/
|
|
||||||
sample_table_t gen_tri();
|
|
||||||
|
|
||||||
/*! Generate triangle wave data
|
|
||||||
@return a table of values
|
|
||||||
*/
|
|
||||||
sample_table_t gen_tri();
|
|
||||||
|
|
||||||
/*! Generate saw wave data
|
/*! Generate saw wave data
|
||||||
@return a table of values
|
@return a table of values
|
||||||
*/
|
*/
|
||||||
sample_table_t gen_saw();
|
sample_table_t gen_saw();
|
||||||
|
|
||||||
/*! Generate ramp wave data
|
/*! Generate inverse saw wave data
|
||||||
@return a table of values
|
@return a table of values
|
||||||
*/
|
*/
|
||||||
sample_table_t gen_ramp();
|
sample_table_t gen_isaw();
|
||||||
|
|
||||||
|
/*! Generate triangle wave data
|
||||||
|
@return a table of values
|
||||||
|
*/
|
||||||
|
sample_table_t gen_tri();
|
||||||
|
|
||||||
#endif // GENERATORS_H_
|
#endif // GENERATORS_H_
|
||||||
|
|
|
||||||
|
|
@ -25,20 +25,24 @@ 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;
|
Wave sin_wave, squ_wave, saw_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();
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
log("Printing head of sine table");
|
log("Printing head of sine table");
|
||||||
sin_wave.print_head();
|
sin_wave.print_head();
|
||||||
log("Printing head of square table");
|
log("Printing head of square table");
|
||||||
squ_wave.print_head();
|
squ_wave.print_head();
|
||||||
|
log("Printing head of saw table");
|
||||||
|
saw_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