diff options
Diffstat (limited to 'source/device_formula.cpp')
-rw-r--r-- | source/device_formula.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/device_formula.cpp b/source/device_formula.cpp new file mode 100644 index 0000000..5c1ca16 --- /dev/null +++ b/source/device_formula.cpp @@ -0,0 +1,28 @@ +#include "stmdsp.hpp" +#include "exprtk.hpp" + +#include <algorithm> +#include <string_view> +#include <vector> + +std::vector<stmdsp::dacsample_t> deviceGenLoadFormulaEval(const std::string_view formulaString) +{ + double x = 0; + + exprtk::symbol_table<double> symbol_table; + exprtk::expression<double> expression; + exprtk::parser<double> parser; + + symbol_table.add_variable("x", x); + symbol_table.add_constants(); + expression.register_symbol_table(symbol_table); + parser.compile(std::string(formulaString), expression); + + std::vector<stmdsp::dacsample_t> samples (stmdsp::SAMPLES_MAX); + + std::generate(samples.begin(), samples.end(), + [&] { ++x; return static_cast<stmdsp::dacsample_t>(expression.value()); }); + + return samples; +} + |