// This effect Copyright (C) 2004 and later Cockos Incorporated
// License: GPL - http://www.gnu.org/licenses/gpl.html

desc: MDCT filter

slider1:128<32,512,153.6>bands
slider2:4<0,512,1>start band
slider3:8<0,512,1>end band
slider4:0.0<-120,120,1>adjust (dB)

@slider
  slider1=2 ^ (0|(0.5+log10(slider1)/log10(2)))|0; 
  slider1=min(512,max(slider1,32));
  fftsize != slider1*2 ? (fftsize=slider1*2; bufpos=bi1=0; bi2=fftsize*2; halfsize=fftsize*0.5);
  slider2=min(slider3,max(slider2,0)); 
  slider3=max(slider2,min(slider3,slider1));
  adj=2 ^ (slider4/6);

@sample
// bi2 was the previously transformed buffer, and by the time it
// is bi2 we only touch the second half (the first was replaced when
// it was bi1)

// bi1 is the most recently transformed buffer, we only touch the first
// half, because the second will be used for the next overlap


t=bi1+bufpos;
p0=t[0];
t[0]=spl0;

t=bi2+halfsize+bufpos;
p1=t[0];
t[0]=spl0;

spl0 = p0 + p1; // our mdct handles windowing, so we just add

bufpos+=1;

bufpos >= halfsize ? (
  // swap bi1 and bi2
  t=bi1; bi1=bi2; bi2=t;
  // we hit our FFT size here

  mdct(bi1,fftsize);
  bufpos=bi1+slider2;
  loop(slider3-slider2, bufpos[0]*=adj; bufpos+=1);
  imdct(bi1,fftsize);
  bufpos=0;
);

spl1=spl0;
