diff --git a/src/wtpp.cpp b/src/wtpp.cpp index c17efbd..379f290 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -11,21 +11,42 @@ static const uint32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate static const uint8_t DEFAULT_BIT_DEPTH = 12; static const uint16_t DEFAULT_N_SAMPLES = 1024; - -class Wavetable +/* Single cycle wave object with lookup table */ +class Wave { private: - uint_fast16_t m_id {}; // Unique ID number of wavetable - std::string m_name {}; // String name of wavetable + uint16_t m_id{}; // Unique ID number of wave std::array m_table; // table data - public: - Wavetable(uint16_t id, std::string name) - : m_id{ id }, m_name{ name }, m_table {} + Wave(uint16_t id) : m_id{id}, m_table{} { // Do nothing } + uint16_t id() { + return m_id; + } + + void set_table(std::array table) { + m_table = table; + } + + void print_head() { + for (uint8_t i = 0; i < 10; i++) { + std::cout << m_table[i] << '\n'; + } + } +}; + +/* Table of single cycle wave lookup tables */ +class Wavetable +{ +private: + uint16_t m_id {}; // Unique ID number of wavetable + std::string m_name {}; // String name of wavetable + std::array m_table; // table data + +public: std::string name() { std::string id_str = std::to_string(m_id); @@ -34,17 +55,10 @@ public: return id_str; } - void set_table(std::array table) + void set_table(std::array table) { m_table = table; } - - void print_head() - { - for(uint8_t i = 0; i < 10; i++) { - std::cout << m_table[i] << '\n'; - } - } }; /* Logs a message */ @@ -53,11 +67,11 @@ static void log(std::string message) std::cout << "wtpp: " << message << '\n'; } -/* Generates basic sine Wavetable object */ -static Wavetable gen_sin_tbl() +/* Generates basic sine Wave object */ +static Wave gen_sine() { // Make the new Wavetable object - Wavetable table = {0, "sine"}; + Wave wave = {0}; // Make an array to hold our values std::array sin_vals {}; // Make a place to store calculated value @@ -70,10 +84,10 @@ static Wavetable gen_sin_tbl() sin_vals[i] = val; } // Store values in new Wavetable.table - table.set_table(sin_vals); + wave.set_table(sin_vals); // Return the completed Wavetable object - return table; + return wave; } int main() @@ -81,12 +95,12 @@ int main() // Generate wavetables log("Generating wavetables"); - // Generate sine table - Wavetable sin_tbl = gen_sin_tbl(); - log(sin_tbl.name()); + // Generate sine wave cycle object + Wave sin_wave = gen_sine(); + log(std::to_string(sin_wave.id())); log("Printing head of sine table"); - sin_tbl.print_head(); + sin_wave.print_head(); return 0; }