// (C) 2009, Lubomir I. Ivanov

// 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.
// 
// Released under GPL:
// <http://www.gnu.org/licenses/>.

desc:Tilt Equalizer
//tags: equalizer
//author: Liteon

slider1:0<0,1,1{Stereo,Mono}>Processing
slider2:50<0,100,0.05>Center Frequency (Scale)
slider3:0<-6,6,0.05>Tilt (Low/High) (dB)
slider4:0<-25,25,0.05>Output Gain (dB)

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

@init
amp = 6/log(2);
denorm = 10^-30;
pi = 22/7;
sr3 = 3*srate;

@slider
mono = slider1; 
gain = slider3;
outgain = exp(slider4/amp);

//conditition
gfactor = 4;
gain > 0 ? (
    g1 = -gfactor*gain;
    g2 = gain;
) : (
    g1 = -gain;
    g2 = gfactor*gain;
);

//two separate gains
lgain = exp(g1/amp)-1;
hgain = exp(g2/amp)-1;

//f0
sx = 16+slider2*1.20103;
f0 = floor(exp(sx*log(1.059))*8.17742);

//filter
omega = 2*pi*f0;
n = 1/(sr3 + omega);
a0 = 2*omega*n;
b1 = (sr3 - omega)*n;

@sample
mono == 1 ? (
//process mono

input = (spl0+spl1)/2;
lp_out = a0*input + b1*lp_out;
output = input + lgain*lp_out + hgain*(input - lp_out);

spl0=spl1=output*outgain+denorm;

) : (
//process stereo

input = spl0;
lp_out = a0*input + b1*lp_out;
output = input + lgain*lp_out + hgain*(input - lp_out);

spl0=output*outgain+denorm;

input_r = spl1;
lp_out_r = a0*input_r + b1*lp_out_r;
output_r = input_r + lgain*lp_out_r + hgain*(input_r - lp_out_r);

spl1=output_r*outgain+denorm;
);

@gfx 100 16
//draw freq scale numbers
gfx_x=gfx_y=5;
gfx_lineto(gfx_x, gfx_y,0);
gfx_r=0;
gfx_b=0.8;
gfx_g=0.6;
gfx_a=1;
gfx_drawchar($'F');
gfx_drawchar($' ');
gfx_drawchar($'=');
gfx_drawchar($' ');
gfx_drawnumber(f0,0);
gfx_drawchar($' ');
gfx_drawchar($'H');
gfx_drawchar($'z');
