**Type :** waveshaper

**References :** Posted by Bram de Jong

**Notes :**

This only works for positive values of x. a should be in the range 0..1

**Code :**

x < a:

f(x) = x

x > a:

f(x) = a + (x-a)/(1+((x-a)/(1-a))^2)

x > 1:

f(x) = (a+1)/2

**Comments**

__from__ : graue[AT]oceanbase[DOT]org

__comment__ : This is a most excellent waveshaper.
I have implemented it as an effect for the music tracker Psycle, and so far I am very pleased with the results. Thanks for sharing this knowledge, Bram!

__from__ : brobinson[AT]toptensoftware[DOT]com

__comment__ : I'm wondering about the >1 condition here. If a is 0.8, values <1 approach 0.85 but values >1 are clamped to 0.9 (there's a gap)
If you substitute x=1 to the equation for x>a you get: a+((1-a)/4) not (a+1)/2
Have I missed something or is there a reason for this?
(Go easy I'm new to all of this)

__from__ : kibibu[AT]gmail[DOT]com

__comment__ : Substituting x=1 into equation 2 (taking many steps)
f(x) = a + (x-a)/(1+ ((x-a)/(1-a))^2)
= a + (1-a)/(1+ ((1-a)/(1-a))^2)
= a + (1-a)/(1+ 1^2)
= a + (1-a)/2
= 2a/2 + (1-a)/2
= (2a + 1 - a) /2
= (a+1) / 2

__from__ : musicdsp[at] Nospam dsparsons[dot]co[dot]uk

__comment__ : You can normalise the output:
f(x)'=f(x)*(1/((a+1)/2))
This gives a nice variable shaper with smooth curve upto clipping at 0dBFS