Making Virtual Electric Guitars and Guitar Effects
Using Faust and Octave
Distortion and Amplifier Feedback
Cubic Nonlinear Distortion
Faust ImplementationSearch Physical Audio Signal Processing
Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?
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://www.dsprelated.com/dspbooks/pasp/ // Nonlinear_Distortion.html#18254 // cubicnl(drive,offset) = +(offset) : *(pregain) : clip(-1,1) : cubic : *(postgain) : dcblocker with { pregain = pow(10.0,2*drive); clip(lo,hi) = min(hi) : max(lo); cubic(x) = x - x*x*x/3; postgain = max(1.0,1.0/pregain); // (unity gain when nearly linear) };
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