//gkc: simple sample-wise Limiter //translated from p100 of DAFX-Zolzer public class Limiter extends delayp { //ugens UGen @ in; //constants for the algorithm 1.0 => float slope; 0.5 => float tresh; 0.01 => float rt; //release const 0.4 => float at; //attack const //maybe delay should be nonzero? //run the limiter public void limit() { float xd; //sidechain - tracks the signal volume while( true ) { float f; //the gain function //'a' is signal left after subtracting xd math.fabs( in.last() )-xd => float a; //a is a positive diff, don't let it be negative if ( a < 0 ) 0=>a; //the attack/release exponential filter xd*(1-rt)+at*a => xd; //this implements the function f if ( xd > tresh ) { //math.pow( 10, -slope*(math.log10(xd)-math.log10(tresh)) ) //=> f; //this should be the same thing math.pow( xd/tresh, -slope ) => f; } else { 1.0 => f; } //set the gain on this this.gain( f ); //move time forward 1::samp => now; } } public void input( UGen in ) { in @=> this.in; //capture the in ref in => this; //connect input } }