diff --git a/src/generators.cpp b/src/generators.cpp index d226edd..393dd84 100644 --- a/src/generators.cpp +++ b/src/generators.cpp @@ -1,6 +1,8 @@ #include "generators.h" +#include "wave.h" -sample_table_t gen_sin() { +sample_table_t gen_sin() +{ // Make the new Wavetable object sample_table_t sin_vals = {0}; // Make a place to store calculated value @@ -15,3 +17,19 @@ sample_table_t gen_sin() { // Return the completed Wavetable object return sin_vals; } + +sample_table_t gen_squ() +{ + sample_table_t squ_vals = {0}; + + // Start high and go low at halfway + for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) { + if (i < (DEFAULT_N_SAMPLES / 2)) { + squ_vals[i] = 1; + } else { + squ_vals[i] = -1; + } + } + + return squ_vals; +} diff --git a/src/wave.cpp b/src/wave.cpp index 642e59c..f0e5938 100644 --- a/src/wave.cpp +++ b/src/wave.cpp @@ -1,12 +1,10 @@ -#include - #include "wave.h" // Initialize index at 0 for wave cycles and wave tables uint16_t Wave::m_nid = 0; void Wave::print_head() { - for (uint8_t i = 0; i < 10; i++) { + for (uint8_t i = 0; i < 3; i++) { std::cout << m_table[i] << '\n'; } } diff --git a/src/wave.h b/src/wave.h index 1c14139..de12395 100644 --- a/src/wave.h +++ b/src/wave.h @@ -4,6 +4,7 @@ #ifndef WAVE_H_ #define WAVE_H_ +#include #include #include @@ -33,7 +34,7 @@ public: */ void setTable(sample_table_t table) { m_table = table; } - /*! Prints the first 10 values of sample data */ + /*! Prints the first 3 values of sample data */ void print_head(); }; diff --git a/src/wtpp.cpp b/src/wtpp.cpp index cb8df51..f439150 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -24,24 +24,25 @@ static void log(std::string message) int main() { - // Generate basic wave lookup tables log("Generating wave cycle lookup tables"); + Wave sin_wave, squ_wave; - // Generate sine wave cycle object - Wave sin_wave; - - // Calculate sine values + // Calculate fundamental wave values sample_table_t sin_vals = gen_sin(); + sample_table_t squ_vals = gen_squ(); // Set wave lookup table values sin_wave.setTable(sin_vals); - - // Create Wavetable object - Wavetable wt_01{"Basic Sine"}; - log(wt_01.name()); + squ_wave.setTable(squ_vals); log("Printing head of sine table"); sin_wave.print_head(); + log("Printing head of square table"); + squ_wave.print_head(); + + // Create Wavetable object containing fundamental Wave objects + Wavetable wt_01{"Fundamental Waves"}; + log(wt_01.name()); return 0; }