In Faust, we can describe the cubic nonlinearity as follows (contained in effect.lib distributed with Faust):
//--------------------- cubicnl(drive,offset) ----------------------- // Cubic nonlinearity distortion // USAGE: cubicnl(drive,offset), where // drive = distortion amount, between 0 and 1 // offset = constant added before nonlinearity to give even harmonics // Reference: // http://ccrma.stanford.edu/~jos/pasp/Nonlinear_Distortion.html#18254 // cubicnl(drive,offset) = +(offset) : *(pregain) : clip(-1,1) : cubic : dcblocker with { pregain = pow(10.0,2*drive); clip(lo,hi) = min(hi) : max(lo); cubic(x) = x - x*x*x/3; };
A simple test program is as follows:
// tcubicnl.dsp import("effect.lib"); // GUI Controls: O = hslider("even_harmonics",0,0,0.5,0.01); D = hslider("distortion [midi: ctrl 0x70]",0.1,0.01,1,0.01); g = hslider("level [midi: ctrl 0x7]",0.1,0,1,0.01); process = ramp(0.01) : cubicnl with { integrator = + ~ _ ; ramp(slope) = slope : integrator - 2.0; }; distortion = cubicnl(O,D); // effect.lib process = ramp(0.01) : -(1.5) : distortion;To plot the output signal, say, in a shell, for example,
faust2octave tcubicnl.dsp