Yet another bitcrusher algorithm. But this one has smooth parameter control.

Normfreq goes from 0 to 1.0; (freq/samplerate)

Input is assumed to be between 0 and 1.

Output gain is greater than unity when bits < 1.0;

function output = crusher( input, normfreq, bits );

step = 1/2^(bits);

phasor = 0;

last = 0;

for i = 1:length(input)

phasor = phasor + normfreq;

if (phasor >= 1.0)

phasor = phasor - 1.0;

last = step * floor( input(i)/step + 0.5 ); %quantize

end

output(i) = last; %sample and hold

end

end