Main Archive Specials Wiki | FAQ Links Submit Forum

 rational tanh approximationType : saturationReferences : Posted by cschuelerNotes : This is a rational function to approximate a tanh-like soft clipper. It is based on the pade-approximation of the tanh function with tweaked coefficients. The function is in the range x=-3..3 and outputs the range y=-1..1. Beyond this range the output must be clamped to -1..1. The first to derivatives of the function vanish at -3 and 3, so the transition to the hard clipped region is C2-continuous. Code : float rational_tanh(x) { if( x < -3 ) return -1; else if( x > 3 ) return 1; else return x * ( 27 + x * x ) / ( 27 + 9 * x * x ); }

 CommentsAdded on : 24/11/06 by scoofy[ AT ]inf[ DOT ]elte[ DOT ]huComment : Works fine. If you want only a little overdrive, you don't even need the clipping, just the last line for faster processing. float rational_tanh_noclip(x) {   return x * ( 27 + x * x ) / ( 27 + 9 * x * x ); } The maximum error of this function in the -4.5 .. 4.5 range is about 2.6%. Added on : 30/11/06 by scoofy[ AT ]inf[ DOT ]elte[ DOT ]huComment : By the way this is the fastest tanh() approximation in the archive so far.Added on : 08/12/06 by cschuelerComment : Yep, I thought so. That's why I thought it would be worth sharing. Especially fast when using SSE you can do a 4-way parallel implementation, with MIN/MAX and the RCP instruction. Added on : 26/01/07 by mdspComment : nice one BTW if you google about "pade-approximation" you'll find a nice page with many solutions for common functions. there's exp, log, sin, cos, tan, gaussian...Added on : 17/02/07 by scoofy[ AT ]inf[ DOT ]elte[ DOT ]huComment : Yep, but the RCP increases the noise floor somewhat, giving a quantized sound, so I'd refrain from using it for high quality audio.

 Add your own comment Comments are displayed in fixed width, no HTML code allowed! Email: Comment: Are you human?

Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion