Skip to content

Instantly share code, notes, and snippets.

@jayrhynas
Last active October 30, 2019 19:35
Show Gist options
  • Save jayrhynas/5648cd21eafabb2570fba47d2c2a3349 to your computer and use it in GitHub Desktop.
Save jayrhynas/5648cd21eafabb2570fba47d2c2a3349 to your computer and use it in GitHub Desktop.
#include <vector>
#include <unordered_map>
#include <memory>
#include <stdio.h>
typedef enum : int {
TableKindSine, TableKindTriangle, TableKindSaw, TableKindSquare,
TableKindCount
} TableKind;
struct FunctionTable {
std::vector<float> table;
float sampleRate;
FunctionTable(TableKind kind, size_t size, float sampleRate)
: table(size, 0), sampleRate(sampleRate)
{
// generate table based on kind
}
};
typedef std::unordered_map<TableKind, std::shared_ptr<FunctionTable>> TableMap;
typedef std::vector<std::shared_ptr<FunctionTable>> TableList;
struct OscParams {
TableList tables;
std::vector<TableKind> kinds;
};
struct Parameters {
TableMap builtinTables;
std::vector<TableKind> initialTableKinds;
OscParams osc[2];
Parameters(TableMap builtinTables, std::vector<TableKind> initialTableKinds)
: builtinTables(std::move(builtinTables)), initialTableKinds(std::move(initialTableKinds))
{
for (int i = 0; i < 2; i++) {
for (TableKind kind : this->initialTableKinds) {
auto table = this->builtinTables[kind];
this->osc[i].tables.push_back(table); /* CRASHES HERE */
this->osc[i].kinds.push_back(kind);
}
}
}
};
int main(int argc, char const *argv[])
{
TableMap builtinTables;
builtinTables.reserve(TableKindCount);
for (int t = 0; t < TableKindCount; t++) {
TableKind kind = (TableKind)t;
builtinTables[kind] = std::make_shared<FunctionTable>(kind, 1024, 44100);
}
auto kinds = {TableKindSine, TableKindTriangle};
auto params = std::make_unique<Parameters>(builtinTables, kinds);
printf("done\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment