parent
b0c352674d
commit
6ba6d6b09e
|
|
@ -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 */
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "common.h"
|
||||
#include "wave.h"
|
||||
|
||||
using wave_table_t = std::array<Wave, DEFAULT_N_WAVES>; /*!< 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"
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<Wave, 5> 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue