Dplug
Dplug copied to clipboard
Add tanh and rsqrt approximation suitable for sound
// 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
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
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.
Should be the focus of another library I think.