diff --git a/src/wave.cpp b/src/wave.cpp index c1fe70d..f2f9bb9 100644 --- a/src/wave.cpp +++ b/src/wave.cpp @@ -1,4 +1,5 @@ #include "wave.h" +#include "common.h" #include #include #include @@ -10,7 +11,15 @@ uint16_t Wave::m_nid = 0; void Wave::print_head() { for (uint8_t i = 0; i < 3; i++) { - std::cout << m_table[i] << '\n'; + std::cout << *(m_tp+i) << '\n'; + } +} + +void Wave::setTable(sample_table_t table) +{ + // Loop through table to load values into sample_table memory + for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) { + *(m_tp + i) = table[i]; } } @@ -27,7 +36,7 @@ uint8_t Wave::export_csv(std::string path) // put values into file for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) { - outf << m_table[i] << "\n"; + outf << *(m_tp+i) << "\n"; } // Clean exit diff --git a/src/wave.h b/src/wave.h index 7ec6ce9..d76e73c 100644 --- a/src/wave.h +++ b/src/wave.h @@ -20,11 +20,15 @@ class Wave { private: static uint16_t m_nid; /*!< Unique ID number of NEXT wave */ - sample_table_t m_table; /*!< Table of sample data */ + float_t *m_tp; /*!< pointer to first element of sample array */ public: const uint16_t m_cid; /*!< Unique ID of current wavetable */ - Wave() : m_cid(m_nid++) {} + Wave() : m_cid(m_nid++) + { + // Allocate sample memory + m_tp = new float_t[DEFAULT_N_SAMPLES]; + } /*! ID getter */ uint16_t getId() { return m_cid; } @@ -33,12 +37,12 @@ public: @param i index of target @return float_t value at index */ - float_t getVal(uint16_t i) { return m_table[i]; } + float_t getVal(uint16_t i) { return (*m_tp+i); } /*! Sample data table setter @param table Sample data table */ - void setTable(sample_table_t table) { m_table = table; } + void setTable(sample_table_t table); /*! Prints the first 3 values of sample data */ void print_head();