diff --git a/Makefile b/Makefile index 1c659d6..a37b48e 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CFLAGS = -Wall -std=c++17 $(OLEVEL) -o $(PROJ) OBJECTS = src/wtpp.cpp -build: clean +build: $(CC) $(CFLAGS) $(OBJECTS) clean: diff --git a/src/wtpp.cpp b/src/wtpp.cpp index 53c209d..3c73dfb 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -1,19 +1,23 @@ #include +#include #include #include #include #include +#include + static const std::uint_fast32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate static const std::uint_fast8_t DEFAULT_BIT_DEPTH = 12; +static const std::uint_fast16_t DEFAULT_N_SAMPLES = 1024; class Wavetable { private: - std::uint_fast16_t m_id {}; - std::string m_name {}; - std::array m_table; + std::uint_fast16_t m_id {}; // Unique ID number of wavetable + std::string m_name {}; // String name of wavetable + std::array m_table; // table data public: Wavetable(std::uint_fast16_t id, std::string name) @@ -29,6 +33,18 @@ public: id_str.append(m_name); return id_str; } + + void set_table(std::array table) + { + m_table = table; + } + + void print_head() + { + for(std::uint_fast8_t i = 0; i < 10; i++) { + std::cout << m_table[i] << '\n'; + } + } }; /* Logs a message */ @@ -37,10 +53,26 @@ static void log(std::string message) std::cout << "wtpp: " << message << '\n'; } -/* Generates basic sine wave table */ +/* Generates basic sine Wavetable object */ static Wavetable gen_sin_tbl() { + // Make the new Wavetable object Wavetable table = {0, "sine"}; + // Make an array to hold our values + std::array sin_vals {}; + // Make a place to store calculated value + std::float_t val = 0; + + // Loop through number of samples and set table values + for (std::uint_fast16_t i = 0; i < DEFAULT_N_SAMPLES; i++) { + // Calculate the value of sin at position + val = std::sin((2 * M_PI * i) / DEFAULT_N_SAMPLES); + sin_vals[i] = val; + } + // Store values in new Wavetable.table + table.set_table(sin_vals); + + // Return the completed Wavetable object return table; } @@ -53,5 +85,8 @@ int main() Wavetable sin_tbl = gen_sin_tbl(); log(sin_tbl.name()); + log("Printing head of sine table"); + sin_tbl.print_head(); + return 0; }