Bit quantization/reduction effect

Type : Bit-level noise-generating effect
References : Posted by Jon Watte
Notes :
This function, run on each sample, will emulate half the effect of running your signal through a Speak-N-Spell or similar low-bit-depth circuitry.

The other half would come from downsampling with no aliasing control, i e replicating every N-th sample N times in the output signal.
Code :
short keep_bits_from_16( short input, int keepBits ) {
  return (input & (-1 << (16-keepBits)));
}


Comments
from : illdoc[AT]gmail[DOT]com
comment : I add some code to prevent offset. Code : short keep_bits_from_16( short input, int keepBits ) { short prevent_offset = static_cast<unsigned short>(-1) >> keepBits+1; input &= (-1 << (16-keepBits))); return input + prevent_offset }

from : isac[AT]op[DOT]pl
comment :

from : info[AT]leon[DOT]vankammen[DOT]eu
comment : Im having trouble how to use this on floats..any example would be great