Next  |  Prev  |  Up  |  Top  |  REALSIMPLE Top

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://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


Next  |  Prev  |  Up  |  Top  |  REALSIMPLE Top

Download faust_strings.pdf

``Making Virtual Electric Guitars and Associated Effects Using Faust'', by Julius O. Smith III,
REALSIMPLE Project — work supported in part by the Wallenberg Global Learning Network .
Released 2013-08-22 under the Creative Commons License (Attribution 2.5), by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA