// (C) 2006, Michael Gruhn.

// NO WARRANTY IS GRANTED. THIS PLUG-IN IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
// WARRANTY OF ANY KIND. NO LIABILITY IS GRANTED, INCLUDING, BUT NOT LIMITED TO,
// ANY DIRECT OR INDIRECT,  SPECIAL,  INCIDENTAL OR CONSEQUENTIAL DAMAGE ARISING
// OUT OF  THE  USE  OR INABILITY  TO  USE  THIS PLUG-IN,  COMPUTER FAILTURE  OF
// MALFUNCTION INCLUDED.  THE USE OF THE SOURCE CODE,  EITHER  PARTIALLY  OR  IN
// TOTAL, IS ONLY GRANTED,  IF USED IN THE SENSE OF THE AUTHOR'S INTENTION,  AND
// USED WITH ACKNOWLEDGEMENT OF THE AUTHOR. FURTHERMORE IS THIS PLUG-IN A  THIRD
// PARTY CONTRIBUTION,  EVEN IF INCLUDED IN REAPER(TM),  COCKOS INCORPORATED  OR
// ITS AFFILIATES HAVE NOTHING TO DO WITH IT.  LAST BUT NOT LEAST, BY USING THIS
// PLUG-IN YOU RELINQUISH YOUR CLAIM TO SUE IT'S AUTHOR, AS WELL AS THE CLAIM TO
// ENTRUST SOMEBODY ELSE WITH DOING SO.

desc:4-Band EQ
desc:4-Band EQ [LOSER]
//tags: equalizer
//author: LOSER

slider1:0<-24,24,1>Low (dB)
slider2:200<0,22000,1>Frequency (Hz)
slider3:0<-24,24,1>Low Mid (dB)
slider4:2000<0,22000,1>Frequency (Hz)
slider5:0<-24,24,1>High Mid (dB)
slider6:5000<0,22000,1>Frequency (Hz)
slider7:0<-24,24,1>High (dB)
slider8:0<-24,24,1>Output (dB)

in_pin:left input
in_pin:right input
out_pin:left output
out_pin:right output

@init
cDenorm=10^-30;
cAmpDB = 8.65617025;

@slider

lVol = exp(slider1/cAmpDB); 
lmVol = exp(slider3/cAmpDB); 
hmVol = exp(slider5/cAmpDB); 
hVol = exp(slider7/cAmpDB); 
outVol = exp(slider8/cAmpDB); 

freqHI = max(min(slider6,srate),slider4);
xHI = exp(-2.0*$pi*freqHI/srate);
a0HI = 1.0-xHI;
b1HI = -xHI;

freqMID = max(min(min(slider4,srate),slider6),slider2);
xMID = exp(-2.0*$pi*freqMID/srate);
a0MID = 1.0-xMID;
b1MID = -xMID;

freqLOW = min(min(slider2,srate),slider4);
xLOW = exp(-2.0*$pi*freqLOW/srate);
a0LOW = 1.0-xLOW;
b1LOW = -xLOW;

@sample

s0 = spl0;
s1 = spl1;

low0 = (tmplMID = a0MID*s0 - b1MID*tmplMID + cDenorm);
low1 = (tmprMID = a0MID*s1 - b1MID*tmprMID + cDenorm);

spl0 = (tmplLOW = a0LOW*low0 - b1LOW*tmplLOW + cDenorm);
spl1 = (tmprLOW = a0LOW*low1 - b1LOW*tmprLOW + cDenorm);

lowS0 = low0 - spl0;
lowS1 = low1 - spl1;

hi0 = s0 - low0;
hi1 = s1 - low1;

midS0 = (tmplHI = a0HI*hi0 - b1HI*tmplHI + cDenorm);
midS1 = (tmprHI = a0HI*hi1 - b1HI*tmprHI + cDenorm);

highS0 = hi0 - midS0;
highS1 = hi1 - midS1;

spl0 = (spl0*lVol + lowS0*lmVol + midS0*hmVol + highS0*hVol)*outVol;
spl1 = (spl1*lVol + lowS1*lmVol + midS1*hmVol + highS1*hVol)*outVol;

