DaisySP icon indicating copy to clipboard operation
DaisySP copied to clipboard

moogladder tanh incorrect

Open Sin-tel opened this issue 3 years ago • 0 comments

I was just looking at the code of the moogladder out of curiosity, and noticed that the fast tanh implementation seems fairly broken.

https://github.com/electro-smith/DaisySP/blob/4263388e7fa8dfd34fa85c6a1c697362dc6981c7/Source/Filters/moogladder.cpp#L6-L24 The referenced implementation in soundpipe is:

https://github.com/adiog/soundpipe/blob/35d856fcf8a0d85c285818554f569b592d066d10/modules/moogladder.c#L26-L42 Which is clearly not the same thing at all!

Simple correction:

float MoogLadder::my_tanh(float x)
{
    int sign = 1;
    if (x < 0) { 
        sign = -1; 
        x = -x;
    }
    if (x >= 4.0) {
      return sign;
    }
    if (x < 0.5) return x * sign;
    return sign * tanh(x);
}

I did not test any of this, so maybe I'm wrong.

Sin-tel avatar Jul 22 '22 13:07 Sin-tel