Feat: add square wave lookup table generation

Refs: #2
pull/5/head
rkcf 2023-02-26 16:28:16 -06:00
parent 6b36df77e1
commit 32f1445862
4 changed files with 32 additions and 14 deletions

View File

@ -1,6 +1,8 @@
#include "generators.h"
#include "wave.h"
sample_table_t gen_sin() {
sample_table_t gen_sin()
{
// Make the new Wavetable object
sample_table_t sin_vals = {0};
// Make a place to store calculated value
@ -15,3 +17,19 @@ sample_table_t gen_sin() {
// Return the completed Wavetable object
return sin_vals;
}
sample_table_t gen_squ()
{
sample_table_t squ_vals = {0};
// Start high and go low at halfway
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
if (i < (DEFAULT_N_SAMPLES / 2)) {
squ_vals[i] = 1;
} else {
squ_vals[i] = -1;
}
}
return squ_vals;
}

View File

@ -1,12 +1,10 @@
#include <iostream>
#include "wave.h"
// Initialize index at 0 for wave cycles and wave tables
uint16_t Wave::m_nid = 0;
void Wave::print_head() {
for (uint8_t i = 0; i < 10; i++) {
for (uint8_t i = 0; i < 3; i++) {
std::cout << m_table[i] << '\n';
}
}

View File

@ -4,6 +4,7 @@
#ifndef WAVE_H_
#define WAVE_H_
#include <iostream>
#include <array>
#include <cstdint>
@ -33,7 +34,7 @@ public:
*/
void setTable(sample_table_t table) { m_table = table; }
/*! Prints the first 10 values of sample data */
/*! Prints the first 3 values of sample data */
void print_head();
};

View File

@ -24,24 +24,25 @@ static void log(std::string message)
int main()
{
// Generate basic wave lookup tables
log("Generating wave cycle lookup tables");
Wave sin_wave, squ_wave;
// Generate sine wave cycle object
Wave sin_wave;
// Calculate sine values
// Calculate fundamental wave values
sample_table_t sin_vals = gen_sin();
sample_table_t squ_vals = gen_squ();
// Set wave lookup table values
sin_wave.setTable(sin_vals);
// Create Wavetable object
Wavetable wt_01{"Basic Sine"};
log(wt_01.name());
squ_wave.setTable(squ_vals);
log("Printing head of sine table");
sin_wave.print_head();
log("Printing head of square table");
squ_wave.print_head();
// Create Wavetable object containing fundamental Wave objects
Wavetable wt_01{"Fundamental Waves"};
log(wt_01.name());
return 0;
}