slider1:0<-30,0,0.1>Threshold (dB)
slider2:-12<-30,0,0.1>Ceiling (dB)
slider3:0<-24,24,0.1>Output (dB)

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

@init
function fmod(x,y) ( x - floor(x/y)*y );

threshold=10^(slider1/20);
function foldback(in, threshold)
(
(in>threshold || in<-threshold) ? (
in= abs(abs(fmod(in - threshold, threshold*4)) - threshold*2) - threshold;
);
in;
);

@slider
threshold=10^(slider1/20);
ceiling=10^(slider2/20);
makeup=ceiling/threshold;
output=10^(slider3/20);

@sample
in0=spl0*makeup;
in1=spl1*makeup;

spl0=foldback(in0,threshold)*makeup*output;
spl1=foldback(in1,threshold)*makeup*output;
