desc: Guitar distortion

slider1:0<0,100,1>Boost (%)
slider2:0<0,100,1>Drive (%)
slider3:12000<1000,12000,1>LowPass (Hz)
slider4:0<-24,12,0.1>Gain (dB)

in_pin:L in
in_pin:R in
out_pin:L out
out_pin:R out

@slider
boost=(slider1+100)/100;
amount=max(min(slider2,99),0);
a = sin(((amount+1)/101)*($pi/2));
k = 2*a/(1-a);

f= 2*$pi * min(slider3, 0.49 * srate) / srate;
q=0.707;
outvol=10^(slider4/20);

w0 = f;
cos_w0 = cos(w0);
alpha = sin(w0) / (2*q);

b1 = 1 - cos_w0;
b0 = b2 = 0.5 * b1;
a0 = 1 + alpha;
a1 = -2 * cos_w0;
a2 = 1 - alpha;

a1 /= a0;
a2 /= a0;
b0 /= a0;
b1 /= a0;
b2 /= a0;

@sample
spl0 *= boost;
spl1 *= boost;

spl0 = (1+k)*(spl0)/(1+k*abs(spl0));
spl1 = (1+k)*(spl1)/(1+k*abs(spl1));

inA=spl0;
inB=spl1;

//Left
x2A = x1A;
x1A = x0A;
x0A = inA;

y2A = y1A;
y1A = y0A;
y0A = b0*x0A + b1*x1A + b2*x2A - a1*y1A - a2*y2A;

//Right
x2B = x1B;
x1B = x0B;
x0B = inB;

y2B = y1B;
y1B = y0B;
y0B = b0*x0B + b1*x1B + b2*x2B - a1*y1B - a2*y2B;

//Output
spl0=y0A;
spl1=y0B;

spl0*=outvol;
spl1*=outvol;
