Decimator

Type : Bit-reducer and sample&hold unit
References : Posted by tobyear[AT]web[DOT]de
Notes :
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;
}

Comments
from : kaleja[AT]estarcion[DOT]com
comment : Nothing wrong with that, but you can also do fractional-bit-depth decimations, allowing smooth degradation from high bit depth to low and back: --------------------------------------- // something like this -- this is // completely off the top of my head // precalculate the quantization level float bits; // effective bit depth float quantum = powf( 2.0f, bits ); // per sample y = floorf( x * quantum ) / quantum; ---------------------------------------

from : dr[DOT]kef[AT]spray[DOT]se
comment : it looks to me like the c-line long int m=1<<(bits-1); doesnt give the correct number of quantisation levels if the number of levels is defined as 2^bits. if bits=2 for instance, the above code line returns a bit pattern of 10 (3) and not 11 (2^2) like one would expect. please, do correct me if im wrong. /heatrof

from : resofactor[AT]hotmail[DOT]com
comment : just getting into coding, i've mainly been working with synthedit...but would really like to move on into the bigger arena? any pointers for a DSP newbie-totally not hip on structured programming...yet! :O)

from : gary[at]dmt uk
comment : great algo, works fine.. many thanks

from : catena[AT]neostrada[DOT]pl
comment : Hey, kilelr job on that one you guys!

from : jacalyn[DOT]neely[AT]wybusiness[DOT]org
comment : You're the one with the brains here. I'm <a href="http://kkwmkktcf.com">wacntihg</a> for your posts.

from : akegley[AT]fbtlaw[DOT]com
comment : d8b3d984d8a7d985 d8afd988d8b3d8aad8a7d986 d985d986 d988d982d8aadb8c d985db8c d8aed988d8a7d987d985 d988d8a7d8b1d8af db8cdaa9 d8b3d8b1d988d8b1 d8a8d8b4d985 d8a8d8a7 d8a7d8b1d988d8b1 server<a href="http://rdxsgcblo.com"> coetncnion</a> time out d985d988d8a7d8acd987 d985db8c d8b4d985 d985d986 d8aad985d8a7d985 dlc d987d8a7 d988 daa9d8b1daa9 d8a8d8a7d8b2db8c d8b1d988 d8b7d8a8d982 d8b1d8a7d987d986d985d8a7 daa9d9bedb8c daa9d8b1d8afd985 d988 d8a7d9bed8afdb8cd8aa d987d985 daa9d8b1d8af d988d984db8c d8a8d8a7d8b2 d987d985 d8a8d8a7 d8a7db8cd986 d8a7d8b1d988d8b1 d985d988d8a7d8acd987 d985db8c d8b4d985 d985d986 d8b9daa9d8b3 d8a8d8a7d984d8a7 d8a7d8b2 d9bed988d8b4d987 main d8b1d988 d8a8d8a7 d9bed988d8b4d987 d8aed988d8afd985 d985d982d8a7db8cd8b3d987 daa9d8b1d8afd985 d8afdb8cd8afd985 d8aad8b9d8afd8a7d8af d981d8a7db8cd987d8a7db8c d9bed988d8b4d987 main d985d986 d8aedb8cd984db8c daa9d985 d987d8b3d8aad986 d8afd8b1 d8add8af dbb3dbb4 d8aad8a7 d988d984db8c da86d8b7d988d8b1 d8aad988 d8b9daa9d8b3 d8a8d8a7d984d8a7 d8a8db8cd8b4 d8a7d8b2 dbb6dbb0 d981d8a7db8cd984 d8a7d8b3d8aa d985d986 daa9d987 dlc d987d8a7 d8b1d988 daa9d9bedb8c daa9d8b1d8afd985 d988d984db8c da86d8b1d8a7 d8aad8b9d8afd8a7d8af d981d8a7db8cd984d987d8a7 daa9d985 d987d8b3d8aad986 d984d8b7d981d8a7 d985d986 d8b1d8a7 d8afd8b1 d8a8d8a7d8b1d987 d8a7db8cd986 d8a7d8b1d988d8b1 d8b1d8a7d987d986d985d8a7db8cdb8c daa9d986db8cd8af.

from : market[AT]ymcasting[DOT]com
comment : Fiaylln! This is just what I was looking for. http://tufqbb.com [url=http://kftggbg.com]kftggbg[/url] [link=http://gxvbsjpvis.com]gxvbsjpvis[/link]

from : o1qtfhdq8p[AT]gmail[DOT]com
comment : Having defined the vital terms of the contract, the contract will set forth the exact terms of the agreement. Most policies are written in outline form and organized around sections. Each section of the QuotesChimp covers one specific topic of the agreement. For example, Section I of a homeowner's insurance policy deals with property coverages, and Section II with liability. Thus, each area of the contract that deals with property coverage in the policy will be labeled as "Section I" material and each part that sets forth the terms of liability coverage will be labeled as "Section II." Most policies have several sections within each insurance agreement.