Refactor: simplify number typedefs

pull/5/head
rkcf 2023-02-26 03:53:50 -06:00
parent 911f16b63c
commit 3cc6970596
1 changed files with 11 additions and 11 deletions

View File

@ -7,20 +7,20 @@
#include <math.h> #include <math.h>
static const std::uint_fast32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate static const uint32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate
static const std::uint_fast8_t DEFAULT_BIT_DEPTH = 12; static const uint8_t DEFAULT_BIT_DEPTH = 12;
static const std::uint_fast16_t DEFAULT_N_SAMPLES = 1024; static const uint16_t DEFAULT_N_SAMPLES = 1024;
class Wavetable class Wavetable
{ {
private: private:
std::uint_fast16_t m_id {}; // Unique ID number of wavetable uint_fast16_t m_id {}; // Unique ID number of wavetable
std::string m_name {}; // String name of wavetable std::string m_name {}; // String name of wavetable
std::array<std::float_t, DEFAULT_N_SAMPLES> m_table; // table data std::array<float_t, DEFAULT_N_SAMPLES> m_table; // table data
public: public:
Wavetable(std::uint_fast16_t id, std::string name) Wavetable(uint16_t id, std::string name)
: m_id{ id }, m_name{ name }, m_table {} : m_id{ id }, m_name{ name }, m_table {}
{ {
// Do nothing // Do nothing
@ -34,14 +34,14 @@ public:
return id_str; return id_str;
} }
void set_table(std::array<std::float_t, DEFAULT_N_SAMPLES> table) void set_table(std::array<float_t, DEFAULT_N_SAMPLES> table)
{ {
m_table = table; m_table = table;
} }
void print_head() void print_head()
{ {
for(std::uint_fast8_t i = 0; i < 10; i++) { for(uint8_t i = 0; i < 10; i++) {
std::cout << m_table[i] << '\n'; std::cout << m_table[i] << '\n';
} }
} }
@ -59,12 +59,12 @@ static Wavetable gen_sin_tbl()
// Make the new Wavetable object // Make the new Wavetable object
Wavetable table = {0, "sine"}; Wavetable table = {0, "sine"};
// Make an array to hold our values // Make an array to hold our values
std::array<std::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
std::float_t val = 0; float_t val = 0;
// Loop through number of samples and set table values // Loop through number of samples and set table values
for (std::uint_fast16_t i = 0; i < DEFAULT_N_SAMPLES; i++) { for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
// Calculate the value of sin at position // Calculate the value of sin at position
val = std::sin((2 * M_PI * i) / DEFAULT_N_SAMPLES); val = std::sin((2 * M_PI * i) / DEFAULT_N_SAMPLES);
sin_vals[i] = val; sin_vals[i] = val;