home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 February
/
PCWorld_2008-02_cd.bin
/
audio-video
/
reaper
/
reaper2028-install.exe
/
Effects
/
SStillwell
/
expander
< prev
next >
Wrap
Text File
|
2007-12-03
|
4KB
|
105 lines
// Copyright 2007, 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:downward expander
slider1:-120<-120,0,0.1>Threshold (dB)
slider2:1<1,20,0.1>Ratio
slider3:0<-20,20,0.1>Gain
slider4:0<0,1,1{Normal,Sidechain}>Detector input
slider5:0<0,1,1{Peak,RMS}>Detection
slider6:30<0,200,1>Attack (ms)
slider7:2<0,100,1>Release (ms)
@init
log2db = 8.6858896380650365530225783783321; // 20 / ln(10)
db2log = 0.11512925464970228420089957273422; // ln(10) / 20
attime=slider6 * 0.001;
reltime=slider7 * 0.001;
maxover=0;
ratio=0;
cratio=0;
rundb=0;
overdb=0;
maxover=0;
atcoef=exp(-1/(attime * srate));
relcoef=exp(-1/(reltime * srate));
fbacoef=exp(-1000/(2 * srate)); // 2 msec. opto attack for feedback detection
fbrcoef=exp(-1000/(200 * srate)); // 200 msec. opto release for feedback detection
sidechain = 0;
automakeup = 0;
@slider
thresh = slider1;
threshv = exp(thresh * db2log);
ratio = slider2;
sidechain = slider4;
makeup = slider3;
makeupv = exp((makeup) * db2log);
RMSdet = slider5;
RMSdet ? (
rmscoef=exp(-1000/(10 * srate)); // 10 ms RMS window
) : (
rmscoef=exp(-1000/(0.0025 * srate)); // 2.5 us Peak detector
);
attime=slider6 * 0.001;
reltime=slider7 * 0.001;
atcoef=exp(-1/(attime * srate));
relcoef=exp(-1/(reltime * srate));
@sample
sidechain ? (
aspl0 = abs(spl2);
aspl1 = abs(spl3);
) : (
aspl0 = abs(spl0);
aspl1 = abs(spl1);
);
RMSDet ? (
ave = (aspl0 * aspl0) + (aspl1 * aspl1);
runave = ave + rmscoef * (runave - ave);
det = sqrt(max(0,runave));
) : (
maxspl = max(aspl0, aspl1);
maxspl = maxspl * maxspl;
runave = maxspl + rmscoef * (runave - maxspl);
det = sqrt(max(0,runave));
);
overdb = 2.08136898 * log(det/threshv) * log2db;
overdb = min(0,overdb);
overdb > rundb ? (
rundb = overdb + atcoef * (rundb - overdb);
) : (
rundb = overdb + relcoef * (rundb - overdb);
);
overdb = rundb;
cratio = (softknee ? (1 + (ratio-1) * min(overdb, 6) / 6) : ratio);
gr = overdb * (cratio-1)/cratio;
grv = exp(gr * db2log);
spl0 *= grv * makeupv;
spl1 *= grv * makeupv;