parent
3673952f0c
commit
7adc6c638d
27
src/wave.cpp
27
src/wave.cpp
|
|
@ -1,10 +1,35 @@
|
|||
#include "wave.h"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
// Initialize index at 0 for wave cycles and wave tables
|
||||
uint16_t Wave::m_nid = 0;
|
||||
|
||||
void Wave::print_head() {
|
||||
void Wave::print_head()
|
||||
{
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ public:
|
|||
|
||||
/*! Prints the first 3 values of sample data */
|
||||
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_
|
||||
|
|
|
|||
|
|
@ -57,5 +57,8 @@ int main()
|
|||
Wavetable wt_01{"Fundamental Waves", fundies};
|
||||
log(wt_01.name());
|
||||
|
||||
// Write sine wave table to file
|
||||
sin_wave.export_csv("data/sine.csv");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue