Skip to content

Commit

Permalink
LOG_OUTPUT: logarithmically map outputs to CV (disabled). Applies to …
Browse files Browse the repository at this point in the history
…all outputs.
  • Loading branch information
giuliomoro committed Dec 9, 2024
1 parent 3d82833 commit 0e1a37e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions TrillRack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern ButtonView performanceBtn;
extern void ledSlidersFixedButtonsProcess(LedSliders& sl, std::vector<bool>& states, std::vector<size_t>& onsets, std::vector<size_t>& offsets, bool onlyUpdateStates);
std::array<float,kNumOutChannels> gManualAnOut;

// #define LOG_OUTPUT
#define STM32_NEOPIXEL
// #define PRINT_CPU_TIME
// Gliss revs:
Expand Down Expand Up @@ -507,6 +508,29 @@ class Smoother
}
};

#ifdef LOG_OUTPUT
static float doLog(float value)
{
static std::array<float,1000> 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];
Expand All @@ -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
Expand Down

0 comments on commit 0e1a37e

Please sign in to comment.