Dplug icon indicating copy to clipboard operation
Dplug copied to clipboard

Add tanh and rsqrt approximation suitable for sound

Open p0nce opened this issue 3 years ago • 1 comments

// Courtesy of Urs Heckmann (u-he)
template <typename T>
    INLINE(T) uhTanhPro( const T &x )
    {
        const T C7 = T( 0.2344393379e-3 );
        const T C5 = T( 0.8205501647e-2 );
        const T C3 = T( 0.1667961930e0 );
        const T C1 = T( 0.999972863e0 );
        
        T x2 = x * x;
        T p = C7 * x*x2*x2*x2 + C5 * x*x2*x2 + C3 * x*x2 + C1 * x;
        return p * rsqrteNR( p * p + 1 );
    }

https://www.kvraudio.com/forum/viewtopic.php?p=5638542#p5638542

These people use the builtin rsqrt from x86 / Neon and then improve the result with a Newton-Raphson step!

On ARM/Neon I think one needs to do two NR steps to get the same precision.

  • [ ] Make such a sqrt function and listen to it
  • [ ] See huge discussion on tanh approx with others solutions too

p0nce avatar Nov 16 '21 14:11 p0nce

Could be a separate library, for example we could have best sounding exp / log / pow there In general smoothness is more important that being exact

p0nce avatar Aug 23 '22 11:08 p0nce

Note: some exp/pow/log (fmath2.h) sound better than _mm_pow_ps, would be nice too There is probably a class of better-sounding transcendentals who are low-degree polynomials and wrong.

p0nce avatar Oct 13 '22 18:10 p0nce

Should be the focus of another library I think.

p0nce avatar Dec 07 '22 13:12 p0nce