parent
7adc6c638d
commit
37c859c8dd
|
|
@ -17,7 +17,8 @@ using sample_table_t = std::array<float_t, DEFAULT_N_SAMPLES>;
|
|||
/*! @class Wave wave.h "wave.h"
|
||||
@brief Single cycle wave object with lookup table
|
||||
*/
|
||||
class Wave {
|
||||
class Wave
|
||||
{
|
||||
private:
|
||||
static uint16_t m_nid; /*!< Unique ID number of NEXT wave */
|
||||
sample_table_t m_table; /*!< Table of sample data */
|
||||
|
|
@ -29,6 +30,12 @@ public:
|
|||
/*! ID getter */
|
||||
uint16_t getId() { return m_cid; }
|
||||
|
||||
/*! Get single value at index
|
||||
@param i index of target
|
||||
@return float_t value at index
|
||||
*/
|
||||
float_t getVal(uint16_t i) { return m_table[i]; }
|
||||
|
||||
/*! Sample data table setter
|
||||
@param table Sample data table
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,11 +1,46 @@
|
|||
#include "wavetable.h"
|
||||
#include "wave.h"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
// Initialize index at 0 for wave cycles and wave tables
|
||||
uint16_t Wavetable::m_nid = 0;
|
||||
|
||||
std::string Wavetable::name() {
|
||||
std::string Wavetable::name()
|
||||
{
|
||||
std::string id_str = std::to_string(m_cid);
|
||||
id_str.append(": ");
|
||||
id_str.append(m_name);
|
||||
return id_str;
|
||||
}
|
||||
|
||||
uint8_t Wavetable::export_csv(std::string data_path)
|
||||
{
|
||||
// Make the full name path
|
||||
std::string fname = data_path.append("/");
|
||||
fname.append(std::to_string(m_cid));
|
||||
fname.append(".csv");
|
||||
|
||||
// Open file for writing
|
||||
std::ofstream outf{fname};
|
||||
|
||||
// Check if we failed to make file
|
||||
if (!outf) {
|
||||
std::cerr << "Failed to write to file\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// For each value in the Wave lookup table
|
||||
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
|
||||
// For each Wave in table
|
||||
for (uint16_t j = 0; j < DEFAULT_N_WAVES; j++) {
|
||||
outf << m_wave_table[j].getVal(i) << ",";
|
||||
}
|
||||
outf << "\n";
|
||||
}
|
||||
|
||||
// Clean exit
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,14 +18,15 @@ using wave_table_t = std::array<Wave, DEFAULT_N_WAVES>;
|
|||
/*! @class Wavetable wavetable.h "wavetable.h"
|
||||
@brief Object containing a table of single cycle Wave objects
|
||||
*/
|
||||
class Wavetable {
|
||||
class Wavetable
|
||||
{
|
||||
private:
|
||||
static uint16_t m_nid; /*!< Unique ID number of wavetable */
|
||||
static uint16_t m_nid; /*!< Unique ID of NEXT wavetable */
|
||||
std::string m_name; /*!< String name of wavetable */
|
||||
wave_table_t m_wave_table; /*!< Table of Wave objects */
|
||||
|
||||
public:
|
||||
const uint16_t m_cid; /*!< Unique ID of NEXT wavetable */
|
||||
const uint16_t m_cid; /*!< Unique ID of wavetable */
|
||||
Wavetable(std::string name, wave_table_t wt)
|
||||
: m_name{name}, m_wave_table{wt}, m_cid(m_nid++) {}
|
||||
|
||||
|
|
@ -36,6 +37,12 @@ public:
|
|||
@return a formatted string in the form "id: name"
|
||||
*/
|
||||
std::string name();
|
||||
|
||||
/*! exports a complete info csv of the Wavetable named after wavetable
|
||||
@param data_path directory where wavetable is exported
|
||||
@result uint8_t integer return value for error checking
|
||||
*/
|
||||
uint8_t export_csv(std::string data_path);
|
||||
};
|
||||
|
||||
#endif // WAVETABLE_H_
|
||||
|
|
|
|||
|
|
@ -60,5 +60,8 @@ int main()
|
|||
// Write sine wave table to file
|
||||
sin_wave.export_csv("data/sine.csv");
|
||||
|
||||
// Write full Wavetable data to file
|
||||
wt_01.export_csv("data");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue