parent
3cc6970596
commit
4a274f4618
62
src/wtpp.cpp
62
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 uint8_t DEFAULT_BIT_DEPTH = 12;
|
||||||
static const uint16_t DEFAULT_N_SAMPLES = 1024;
|
static const uint16_t DEFAULT_N_SAMPLES = 1024;
|
||||||
|
|
||||||
|
/* Single cycle wave object with lookup table */
|
||||||
class Wavetable
|
class Wave
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint_fast16_t m_id {}; // Unique ID number of wavetable
|
uint16_t m_id{}; // Unique ID number of wave
|
||||||
std::string m_name {}; // String name of wavetable
|
|
||||||
std::array<float_t, DEFAULT_N_SAMPLES> m_table; // table data
|
std::array<float_t, DEFAULT_N_SAMPLES> m_table; // table data
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Wavetable(uint16_t id, std::string name)
|
Wave(uint16_t id) : m_id{id}, m_table{}
|
||||||
: m_id{ id }, m_name{ name }, m_table {}
|
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t id() {
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_table(std::array<float_t, DEFAULT_N_SAMPLES> 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<Wave, DEFAULT_N_SAMPLES> m_table; // table data
|
||||||
|
|
||||||
|
public:
|
||||||
std::string name()
|
std::string name()
|
||||||
{
|
{
|
||||||
std::string id_str = std::to_string(m_id);
|
std::string id_str = std::to_string(m_id);
|
||||||
|
|
@ -34,17 +55,10 @@ public:
|
||||||
return id_str;
|
return id_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_table(std::array<float_t, DEFAULT_N_SAMPLES> table)
|
void set_table(std::array<Wave, DEFAULT_N_SAMPLES> table)
|
||||||
{
|
{
|
||||||
m_table = table;
|
m_table = table;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_head()
|
|
||||||
{
|
|
||||||
for(uint8_t i = 0; i < 10; i++) {
|
|
||||||
std::cout << m_table[i] << '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Logs a message */
|
/* Logs a message */
|
||||||
|
|
@ -53,11 +67,11 @@ static void log(std::string message)
|
||||||
std::cout << "wtpp: " << message << '\n';
|
std::cout << "wtpp: " << message << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generates basic sine Wavetable object */
|
/* Generates basic sine Wave object */
|
||||||
static Wavetable gen_sin_tbl()
|
static Wave gen_sine()
|
||||||
{
|
{
|
||||||
// Make the new Wavetable object
|
// Make the new Wavetable object
|
||||||
Wavetable table = {0, "sine"};
|
Wave wave = {0};
|
||||||
// Make an array to hold our values
|
// Make an array to hold our values
|
||||||
std::array<float_t, DEFAULT_N_SAMPLES> sin_vals {};
|
std::array<float_t, DEFAULT_N_SAMPLES> sin_vals {};
|
||||||
// Make a place to store calculated value
|
// Make a place to store calculated value
|
||||||
|
|
@ -70,10 +84,10 @@ static Wavetable gen_sin_tbl()
|
||||||
sin_vals[i] = val;
|
sin_vals[i] = val;
|
||||||
}
|
}
|
||||||
// Store values in new Wavetable.table
|
// Store values in new Wavetable.table
|
||||||
table.set_table(sin_vals);
|
wave.set_table(sin_vals);
|
||||||
|
|
||||||
// Return the completed Wavetable object
|
// Return the completed Wavetable object
|
||||||
return table;
|
return wave;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
@ -81,12 +95,12 @@ int main()
|
||||||
// Generate wavetables
|
// Generate wavetables
|
||||||
log("Generating wavetables");
|
log("Generating wavetables");
|
||||||
|
|
||||||
// Generate sine table
|
// Generate sine wave cycle object
|
||||||
Wavetable sin_tbl = gen_sin_tbl();
|
Wave sin_wave = gen_sine();
|
||||||
log(sin_tbl.name());
|
log(std::to_string(sin_wave.id()));
|
||||||
|
|
||||||
log("Printing head of sine table");
|
log("Printing head of sine table");
|
||||||
sin_tbl.print_head();
|
sin_wave.print_head();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue