diff --git a/src/common.h b/src/common.h index b8eb0a0..23076a8 100644 --- a/src/common.h +++ b/src/common.h @@ -10,9 +10,9 @@ /*! Constants */ -const uint32_t DEFAULT_SAMPLE_RATE = 22050; /*!< 22.05 kHz sampling rate */ -const uint8_t DEFAULT_BIT_DEPTH = 12; /*!< 12bit samples */ -const uint16_t DEFAULT_N_SAMPLES = 1024; /*!< 1024 samples per wave cycle */ +const uint32_t DEFAULT_SAMPLE_RATE = 22050; /*!< Sampling rate */ +const uint8_t DEFAULT_BIT_DEPTH = 12; /*!< Bit depth of samples */ +const uint16_t DEFAULT_N_SAMPLES = 256; /*!< Number of samples per wave cycle */ const uint16_t DEFAULT_N_WAVES = 64; /*!< Number of Wave cycle objects in Wavetable */ /*! diff --git a/src/wave.h b/src/wave.h index d76e73c..5914bfc 100644 --- a/src/wave.h +++ b/src/wave.h @@ -23,13 +23,20 @@ private: float_t *m_tp; /*!< pointer to first element of sample array */ public: - const uint16_t m_cid; /*!< Unique ID of current wavetable */ + uint16_t m_cid; /*!< Unique ID of current wavetable */ Wave() : m_cid(m_nid++) { // Allocate sample memory m_tp = new float_t[DEFAULT_N_SAMPLES]; } + Wave(Wave& newWave) + { + m_nid = newWave.m_nid; + m_cid = newWave.m_cid; + m_tp = newWave.m_tp; + } + /*! ID getter */ uint16_t getId() { return m_cid; } diff --git a/src/wavetable.cpp b/src/wavetable.cpp index f98ef2d..1b6e4d7 100644 --- a/src/wavetable.cpp +++ b/src/wavetable.cpp @@ -8,6 +8,11 @@ // Initialize index at 0 for wave cycles and wave tables uint16_t Wavetable::m_nid = 0; +void Wavetable::setWave(uint16_t i, Wave wave) +{ + *(m_wtp+i) = wave; +} + std::string Wavetable::name() { std::string id_str = std::to_string(m_cid); @@ -36,7 +41,8 @@ uint8_t Wavetable::export_csv(std::string data_path) for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) { // For each Wave in table for (uint16_t j = 0; j < DEFAULT_N_WAVES; j++) { - outf << m_wave_table[j].getVal(i) << ","; + Wave w = *(m_wtp+j); + outf << w.getVal(i) << ","; } outf << "\n"; } diff --git a/src/wavetable.h b/src/wavetable.h index 3eefe27..90ca0a9 100644 --- a/src/wavetable.h +++ b/src/wavetable.h @@ -8,6 +8,7 @@ #include #include +#include "common.h" #include "wave.h" using wave_table_t = std::array; /*!< Array of Wave objects */ @@ -20,16 +21,22 @@ class Wavetable private: static uint16_t m_nid; /*!< Unique ID of NEXT wavetable */ std::string m_name; /*!< String name of wavetable */ - wave_table_t m_wave_table; /*!< Table of Wave objects */ + Wave *m_wtp; /*!< Pointer to table of Waves */ public: const uint16_t m_cid; /*!< Unique ID of wavetable */ - Wavetable(std::string name, wave_table_t wt) - : m_name{name}, m_wave_table{wt}, m_cid(m_nid++) {} + Wavetable(std::string name) : m_name{name}, m_cid(m_nid++) + { + // Allocate Wavetable memory + m_wtp = new Wave[DEFAULT_N_WAVES]; + } /*! ID getter */ uint16_t getId() { return m_cid; } + /*! Set index i to provided Wave */ + void setWave(uint16_t i, Wave wave); + /*! Makes formatted name and id string @return a formatted string in the form "id: name" */ diff --git a/src/wtpp.cpp b/src/wtpp.cpp index a1534ab..864c242 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -42,8 +42,8 @@ int main() isaw_wave.print_head(); // Create wave table of all fundamental Wave objects - wave_table_t fundies = {sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave}; - Wavetable wt_01{"Fundamental Waves", fundies}; + std::array fundies = {sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave}; + Wavetable wt_01{"Fundamental Waves"}; clog(wt_01.name()); // Write sine wave table to file