Feat: add basic Wave lookup table export to csv

Refs: #3
pull/8/head
rkcf 2023-02-26 18:19:17 -06:00
parent 3673952f0c
commit 7adc6c638d
3 changed files with 35 additions and 1 deletions

View File

@ -1,10 +1,35 @@
#include "wave.h" #include "wave.h"
#include <cstdint>
#include <string>
#include <fstream>
#include <iostream>
// Initialize index at 0 for wave cycles and wave tables // Initialize index at 0 for wave cycles and wave tables
uint16_t Wave::m_nid = 0; uint16_t Wave::m_nid = 0;
void Wave::print_head() { void Wave::print_head()
{
for (uint8_t i = 0; i < 3; i++) { for (uint8_t i = 0; i < 3; i++) {
std::cout << m_table[i] << '\n'; std::cout << m_table[i] << '\n';
} }
} }
uint8_t Wave::export_csv(std::string path)
{
// Open file for writing
std::ofstream outf{path};
// Check if we failed to make file
if (!outf) {
std::cerr << "Failed to write to file\n";
return 1;
}
// put values into file
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
outf << m_table[i] << "\n";
}
// Clean exit
return 0;
}

View File

@ -36,6 +36,12 @@ public:
/*! Prints the first 3 values of sample data */ /*! Prints the first 3 values of sample data */
void print_head(); void print_head();
/*! Exports sample table data to csv
@param path File path to save to
@return uint8_t integer return value for error checking
*/
uint8_t export_csv(std::string path);
}; };
#endif // WAVE_H_ #endif // WAVE_H_

View File

@ -57,5 +57,8 @@ int main()
Wavetable wt_01{"Fundamental Waves", fundies}; Wavetable wt_01{"Fundamental Waves", fundies};
log(wt_01.name()); log(wt_01.name());
// Write sine wave table to file
sin_wave.export_csv("data/sine.csv");
return 0; return 0;
} }