PeakEater icon indicating copy to clipboard operation
PeakEater copied to clipboard

Investigate DSP formula for Custom Algorithm

Open vvvar opened this issue 2 years ago • 1 comments

[R&D] "Custom" type of algorithm

Goal is to give user ability to adjust curving angle of waveshaper manually by introducing new type of algorithm called "Custom". It should display additional UI element that will give opportunity to change "level of curve" for the function, from "hard" which is 90 degrees angle to reasonable soft clip.

vvvar avatar Sep 17 '22 14:09 vvvar

Just for me to not lost. Here are two possible implementations.

// Based on sigmoid algo
template <typename T>
static T sigmoid (T x) noexcept
{
    // params
    auto const smoothing = static_cast<T> (2);
    // function
    auto const exponent = -2 * x * smoothing;
    auto const expVal = std::exp (exponent);
    auto const numerator = static_cast<T> (2);
    auto const denominator = static_cast<T> (1);
    auto const subtractValue = static_cast<T> (1);
    return (numerator / (denominator + expVal)) - subtractValue;
}
// Based on tanh algo
template <typename T>
static T tanh (T x) noexcept
{
    return std::tanh (x);
}

template <typename T>
static T smoothTanh (T x) noexcept
{
    auto const smoothing = static_cast<T> (1);
    return (1.0 + std::tanh (smoothing * x)) / 2.0;
}

Next step - compare performance. clock() is a potentially useful function to do that.

vvvar avatar Jul 05 '23 17:07 vvvar