Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Ads

Chapters

Chapter Contents:

Search Physical Audio Signal Processing

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

Faust Implementation

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


Order a Hardcopy of Physical Audio Signal Processing

Previous: