/*
De-esser

Reduce excessive sibilants (/s/ /t/ /sh/ etc.) in vocals and speech.

Threshold		Set maximum level for high frequencies
Frequency	Lowest frequency affected
		(a HF shelf is used for stronger de-essing than designs that work on a frequency band)
HSF Drive		Boost high frequencies before de-essing - can be used to enhance breathy vocals
Output		Level trim
Delta		Subtracts the input signal from the processed signal - helps to finetune some of the parameters

For stronger de-essing you may want to use two plug-ins in series, or apply processing twice.
*/

desc: Mono.

slider1:0.15<0,1,0.01>threshold
slider2:0.6<0,1,0.01>frequency
slider3:0.5<0,1,0.01>hsf drive
slider4:0.5<0,1,0.01>output
slider5:0<0,1,1{Off,On}>delta

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

@init
fbuf1=0;
fbuf2=0;
env=0;
att=0.01;
rel=0.992;

@slider
fParam1 = slider1; //thresh
fParam2 = slider2; //freq
fParam3 = slider3; //hsf drive
fParam4 = slider4; //output
fParam5 = slider5; //delta

thresh=pow(10, 3 * fParam1 - 3);
fil=0.05 + 0.94 * fParam2 * fParam2;
gain=pow(10, 2 * fParam3 - 1);

output=pow(10, 2 * fParam4 - 1);

@sample
f1=fbuf1;
f2=fbuf2;
fi=fil;
fo=(1-fil);
gg=gain;
en=env;
th=thresh;

a = spl0;
b = spl1;
tmp = 0.5 * (a + b);
deltatmp = 0.5 * (a + b);

f1 = fo * f1 + fi * tmp;
tmp -= f1;
f2 = fo * f2 + fi * tmp;
tmp = gg * (tmp - f2); //extra HF gain

en = (tmp>en) ? en+att*(tmp-en) : en*rel; //envelope
(en>th) ? ( g = f1+f2+tmp*(th/en); ):( g = f1+f2+tmp; ); //limit

fParam5>0.5 ? (
c = g-deltatmp;
d = g-deltatmp;
):(
c = g;
d = g;
);

spl0 = c * output;
spl1 = d * output;

(abs(f1)<0.0000000001) ? ( fbuf1=0; fbuf2=0; ):( fbuf1=f1; fbuf2=f2; );
(abs(en)<0.0000000001) ? ( env=0; ):( env=en; );

@gfx 0 100
gfx_r=0; gfx_g=0.9; gfx_b=0; gfx_a=1;
gfx_setfont(1,"Arial", 16);

gfx_x =20; gfx_y =10;  gfx_printf("%.1f",(60 * fParam1 - 60) );
gfx_x =70; gfx_y =10;  gfx_printf("dB");
gfx_x =110; gfx_y =10;  gfx_printf("Threshold");

gfx_x =20; gfx_y =30;  gfx_printf("%.0f",(1000 + 11000 * fParam2) );
gfx_x =70; gfx_y =30;  gfx_printf("Hz");
gfx_x =110; gfx_y =30;  gfx_printf("Frequency");

gfx_x =20; gfx_y =50;  gfx_printf("%.1f",(40 * fParam3 - 20) );
gfx_x =70; gfx_y =50;  gfx_printf("dB");
gfx_x =110; gfx_y =50;  gfx_printf("HSF Drive");

gfx_x =20; gfx_y =70;  gfx_printf("%.1f",(40 * fParam4 - 20) );
gfx_x =70; gfx_y =70;  gfx_printf("dB");
gfx_x =110; gfx_y =70;  gfx_printf("Output");
