desc:Time Adjustment Delay
desc:Time Adjustment Delay or Negative Delay
//tags: delay time PDC
//author: Cockos

slider1:0<-1000,1000,1>Delay Amount (ms)
slider2:0<-120,12,1>Wet Mix (dB)
slider3:-120<-120,12,1>Dry Mix (dB)
slider4:0<-40000,40000,1>Additional Delay Amount (spls)

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

@init
bpos=0;

@slider
wet=2^(slider2/6);
dry=2^(slider3/6);
delaylen = (slider1*srate*0.001 + slider4)|0;
delaylen<0?(
  pdc_delay=-delaylen;  
  pdc_top_ch=2;
  pdc_bot_ch=0;
  delaylen=0;
):(
delaylen+=pdc_delay;
//pdc_delay=0;
);
bufsize=srate*4.0; // extra in case the user wants to go over

@sample
bpos[0]=spl0;
bpos[1]=spl1;

rdpos=bpos-delaylen*2;
rdpos<0 ? rdpos+=bufsize*2;
spl0=spl0*dry+rdpos[0]*wet;
spl1=spl1*dry+rdpos[1]*wet;

bpos+=2;
bpos>=bufsize*2 ? bpos=0;
