Main Archive Specials Wiki | FAQ Links Submit Forum

 DecimatorType : Bit-reducer and sample&hold unitReferences : Posted by tobyear[AT]web[DOT]deNotes : This is a simple bit and sample rate reduction code, maybe some of you can use it. The parameters are bits (1..32) and rate (0..1, 1 is the original samplerate). Call the function like this: y=decimate(x); A VST plugin implementing this algorithm (with full Delphi source code included) can be downloaded from here: http://tobybear.phreque.com/decimator.zip Comments/suggestions/improvements are welcome, send them to: tobybear@web.de Code : // bits: 1..32 // rate: 0..1 (1 is original samplerate) ********** Pascal source ********** var m:longint; y,cnt,rate:single; // call this at least once before calling // decimate() the first time procedure setparams(bits:integer;shrate:single); begin m:=1 shl (bits-1); cnt:=1; rate:=shrate; end; function decimate(i:single):single; begin cnt:=cnt+rate; if (cnt>1) then begin cnt:=cnt-1; y:=round(i*m)/m; end; result:=y; end; ********** C source ********** int bits=16; float rate=0.5; long int m=1<<(bits-1); float y=0,cnt=0; float decimate(float i) { cnt+=rate; if (cnt>=1) { cnt-=1; y=(long int)(i*m)/(float)m; } return y; }