From 0e1a37e38ee99d00cd5d39612e335735a5f7e5be Mon Sep 17 00:00:00 2001 From: Giulio Moro Date: Mon, 9 Dec 2024 02:25:09 +0100 Subject: [PATCH] LOG_OUTPUT: logarithmically map outputs to CV (disabled). Applies to all outputs. --- TrillRack.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/TrillRack.cpp b/TrillRack.cpp index 09c1fc2..582e31e 100644 --- a/TrillRack.cpp +++ b/TrillRack.cpp @@ -30,6 +30,7 @@ extern ButtonView performanceBtn; extern void ledSlidersFixedButtonsProcess(LedSliders& sl, std::vector& states, std::vector& onsets, std::vector& offsets, bool onlyUpdateStates); std::array gManualAnOut; +// #define LOG_OUTPUT #define STM32_NEOPIXEL // #define PRINT_CPU_TIME // Gliss revs: @@ -507,6 +508,29 @@ class Smoother } }; +#ifdef LOG_OUTPUT +static float doLog(float value) +{ + static std::array logTable; + static bool inited = false; + if(!inited) + { + inited = true; + // let's handle log sliders the way Pd does + float min = 1; + float max = 101; + for(size_t n = 0; n < logTable.size(); ++n) { + logTable[n] = (min * exp(log(max/min) * (n / float(logTable.size() - 1))) - 1) / (max - min); + } + } + value = constrain(value, 0, 1); + size_t prevIdx = std::min(logTable.size() - 1, size_t(value * (logTable.size() - 1))); + float prev = logTable[prevIdx]; + float next = logTable[std::min(prevIdx + 1, logTable.size() - 1)]; + return linearInterpolation(fmodf(value, 1), prev, next); +} +#endif // LOG_OUTPUT + static float rescaleOutput(bool ignoreRange, size_t channel, const CalibrationData& cal, float value) { float gnd = cal.values[1]; @@ -518,6 +542,9 @@ static float rescaleOutput(bool ignoreRange, size_t channel, const CalibrationDa getRangeMinMax(false, channel, min, top); // the input can be negative: out of the specified range but possibly still within the capabilities of the module +#ifdef LOG_OUTPUT + value = doLog(value); +#endif // LOG_OUTPUT value = map(value, 0, 1, min, top); value = processRawThroughCalibration(cal, false, value); // we only constrain at the end: can't write outside full scale