From a6ab2b19aa6a9638817695f96745d90de8c463d2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 4 Oct 2023 02:20:06 -0400 Subject: [PATCH] Add Quantity evaluation functions gaintodb(), dbtogain(), vtof(), and ftov(). --- src/Quantity.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Quantity.cpp b/src/Quantity.cpp index 5ecc1cc3..7e323b17 100644 --- a/src/Quantity.cpp +++ b/src/Quantity.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace rack { @@ -78,6 +79,20 @@ static void teVarsInit() { // Add custom functions teVars.push_back({"log2", (void*) (double(*)(double)) std::log2, TE_FUNCTION1 | TE_FLAG_PURE, NULL}); + + teVars.push_back({"gaintodb", (void*) (double(*)(double)) [](double x) -> double { + return std::log10(x) * 20; + }, TE_FUNCTION1 | TE_FLAG_PURE, NULL}); + teVars.push_back({"dbtogain", (void*) (double(*)(double)) [](double x) -> double { + return std::pow(10, x / 20); + }, TE_FUNCTION1 | TE_FLAG_PURE, NULL}); + + teVars.push_back({"vtof", (void*) (double(*)(double)) [](double x) -> double { + return std::pow(2, x) * dsp::FREQ_C4; + }, TE_FUNCTION1 | TE_FLAG_PURE, NULL}); + teVars.push_back({"ftov", (void*) (double(*)(double)) [](double x) -> double { + return std::log2(x / dsp::FREQ_C4); + }, TE_FUNCTION1 | TE_FLAG_PURE, NULL}); } void Quantity::setDisplayValueString(std::string s) {