Compare commits
No commits in common. "a7ce35791f84d61f864ffbd36dadb754329733ed" and "3673952f0c08fb589e8ce967b58dd79650792085" have entirely different histories.
a7ce35791f
...
3673952f0c
27
src/wave.cpp
27
src/wave.cpp
|
|
@ -1,35 +1,10 @@
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
15
src/wave.h
15
src/wave.h
|
|
@ -17,8 +17,7 @@ using sample_table_t = std::array<float_t, DEFAULT_N_SAMPLES>;
|
||||||
/*! @class Wave wave.h "wave.h"
|
/*! @class Wave wave.h "wave.h"
|
||||||
@brief Single cycle wave object with lookup table
|
@brief Single cycle wave object with lookup table
|
||||||
*/
|
*/
|
||||||
class Wave
|
class Wave {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
static uint16_t m_nid; /*!< Unique ID number of NEXT wave */
|
static uint16_t m_nid; /*!< Unique ID number of NEXT wave */
|
||||||
sample_table_t m_table; /*!< Table of sample data */
|
sample_table_t m_table; /*!< Table of sample data */
|
||||||
|
|
@ -30,12 +29,6 @@ public:
|
||||||
/*! ID getter */
|
/*! ID getter */
|
||||||
uint16_t getId() { return m_cid; }
|
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
|
/*! Sample data table setter
|
||||||
@param table Sample data table
|
@param table Sample data table
|
||||||
*/
|
*/
|
||||||
|
|
@ -43,12 +36,6 @@ 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_
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,11 @@
|
||||||
#include "wavetable.h"
|
#include "wavetable.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 Wavetable::m_nid = 0;
|
uint16_t Wavetable::m_nid = 0;
|
||||||
|
|
||||||
std::string Wavetable::name()
|
std::string Wavetable::name() {
|
||||||
{
|
|
||||||
std::string id_str = std::to_string(m_cid);
|
std::string id_str = std::to_string(m_cid);
|
||||||
id_str.append(": ");
|
id_str.append(": ");
|
||||||
id_str.append(m_name);
|
id_str.append(m_name);
|
||||||
return id_str;
|
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,15 +18,14 @@ using wave_table_t = std::array<Wave, DEFAULT_N_WAVES>;
|
||||||
/*! @class Wavetable wavetable.h "wavetable.h"
|
/*! @class Wavetable wavetable.h "wavetable.h"
|
||||||
@brief Object containing a table of single cycle Wave objects
|
@brief Object containing a table of single cycle Wave objects
|
||||||
*/
|
*/
|
||||||
class Wavetable
|
class Wavetable {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
static uint16_t m_nid; /*!< Unique ID of NEXT wavetable */
|
static uint16_t m_nid; /*!< Unique ID number of wavetable */
|
||||||
std::string m_name; /*!< String name of wavetable */
|
std::string m_name; /*!< String name of wavetable */
|
||||||
wave_table_t m_wave_table; /*!< Table of Wave objects */
|
wave_table_t m_wave_table; /*!< Table of Wave objects */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const uint16_t m_cid; /*!< Unique ID of wavetable */
|
const uint16_t m_cid; /*!< Unique ID of NEXT wavetable */
|
||||||
Wavetable(std::string name, wave_table_t wt)
|
Wavetable(std::string name, wave_table_t wt)
|
||||||
: m_name{name}, m_wave_table{wt}, m_cid(m_nid++) {}
|
: m_name{name}, m_wave_table{wt}, m_cid(m_nid++) {}
|
||||||
|
|
||||||
|
|
@ -37,12 +36,6 @@ public:
|
||||||
@return a formatted string in the form "id: name"
|
@return a formatted string in the form "id: name"
|
||||||
*/
|
*/
|
||||||
std::string 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_
|
#endif // WAVETABLE_H_
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,5 @@ 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");
|
|
||||||
|
|
||||||
// Write full Wavetable data to file
|
|
||||||
wt_01.export_csv("data");
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue