home *** CD-ROM | disk | FTP | other *** search
- // Copyright 2006, Thomas Scott Stillwell
- // All rights reserved.
- //
- //Redistribution and use in source and binary forms, with or without modification, are permitted
- //provided that the following conditions are met:
- //
- //Redistributions of source code must retain the above copyright notice, this list of conditions
- //and the following disclaimer.
- //
- //Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- //and the following disclaimer in the documentation and/or other materials provided with the distribution.
- //
- //The name of Thomas Scott Stillwell may not be used to endorse or
- //promote products derived from this software without specific prior written permission.
- //
- //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
- //IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- //FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- //BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- //STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- //THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- desc:FAST attack compressor with prog-dependent release
-
- slider1:0<-60,0,0.1>Threshold (dB)
- slider2:1<0,3,1{4,8,12,20,All}>Ratio
- slider3:0<-20,20,0.1>Gain
- slider4:20<20,2000,10>Attack time (usec.)
- slider5:250<20,1000,1>Release time (msec.)
- slider6:100<0,100,0.1>Mix%
-
- @init
- log2db = 8.6858896380650365530225783783321; // 20 / ln(10)
- db2log = 0.11512925464970228420089957273422; // ln(10) / 20
- dcoffset = 0.0000000000000000000000001;
- attime=0.010;
- reltime=0.100;
- ratio=0;
- cratio=0;
- rundb=0;
- overdb=0;
- ratatcoef = exp(-1/(0.00001 * srate));
- ratrelcoef = exp(-1/(0.5 * srate));
- atcoef=exp(-1/(attime * srate));
- relcoef=exp(-1/(reltime * srate));
- mix=1;
-
- @slider
- thresh = slider1;
- threshv = exp(thresh * db2log);
- ratio = (slider2==0 ? 4 : (slider2==1 ? 8 : (slider2 == 2 ? 12 : (slider2 == 3 ? 20 : 20 ))));
- slider2 == 4 ? (allin=1; cratio=20;) : (allin=0; cratio = ratio;);
- cthresh = (softknee ? (thresh -3) : thresh);
- cthreshv = exp(cthresh * db2log);
- makeup = slider3;
- makeupv = exp((makeup+autogain) * db2log);
- attime = slider4 / 1000000;
- reltime = slider5 / 1000;
- atcoef=exp(-1/(attime * srate));
- relcoef=exp(-1/(reltime * srate));
- mix=slider6/100;
-
- @sample
- ospl0 = spl0;
- ospl1 = spl1;
- aspl0 = abs(spl0);
- aspl1 = abs(spl1);
- maxspl = max(aspl0, aspl1);
- maxspl = maxspl * maxspl;
- runave = maxspl + rmscoef * (runave - maxspl);
- det = sqrt(max(0,runave));
-
- overdb = 2.08136898 * log(det/cthreshv) * log2db;
- overdb = max(0,overdb);
-
- overdb - rundb > 5 ? (averatio = 4;);
-
- overdb > rundb ? (
- rundb = overdb + atcoef * (rundb - overdb);
- runratio = averatio + ratatcoef * (runratio - averatio);
- ) : (
- rundb = overdb + relcoef * (rundb - overdb);
- runratio = averatio + ratrelcoef * (runratio - averatio);
- );
- overdb = rundb;
- averatio = runratio;
-
- allin ? (
- cratio = 12 + averatio;
- ) : (
- cratio = ratio;
- );
-
- gr = -overdb * (cratio-1)/cratio;
- grv = exp(gr * db2log);
-
- runmax = maxover + relcoef * (runmax - maxover); // highest peak for setting att/rel decays in reltime
- maxover = runmax;
-
- spl0 *= grv * makeupv * mix;
- spl1 *= grv * makeupv * mix;
-
- spl0 += ospl0 * (1-mix);
- spl1 += ospl1 * (1-mix);
-