// Envelope-following infinite distortion: Applies infinite clipping to the signal // while keeping the dynamics of the original. // Infinite distortion without infinite compression! // // // Based on envelope-following code found at http://www.musicdsp.org/showone.php?id=136 desc: envelope-following infinite distortion by jeff robertson slider1: 10<1,1000,1> attack slider2: 10<1,1000,1> release slider3:-0<-144,0,1> wet volume (dB) slider4:-144<-144,0,1> dry volume (dB) @init envelope0 = 0.0; envelope1 = 0.0; @slider // i'm really not sure what the best default values for these should be release_in_ms = slider1; attack_in_ms = slider2; attack_coef = exp(log(0.01)/( attack_in_ms * srate * 0.001)); release_coef = exp(log(0.01)/( release_in_ms * srate * 0.001)); wetv=2^(slider3/6); dryv=2^(slider4/6); @sample // first channel 0 tmp = abs(spl0); envelope0 = tmp > envelope0 ? (attack_coef * (envelope0 - tmp) + tmp) : (release_coef * (envelope0 - tmp) + tmp); // at this point envelope0 contains essentially an // ADSR envelope derived from the input signal // infinite clipping. everything becomes // either 1 or -1, a perfect square wave. // multiplying by envelope0 forces this back // down into the volume and attack/decay of the original. spl0= dryv*spl0 + wetv * ((spl0 > 0) ? 1 : -1) * envelope0; // we now do the same thing with channel 1 tmp = abs(spl1); envelope1 = tmp > envelope1 ? (attack_coef * (envelope1 - tmp) + tmp) : (release_coef * (envelope1 - tmp) + tmp); spl1= dryv*spl1 + wetv * ((spl0 > 0) ? 1 : -1) * envelope1;