Since you can do it for the range [0,max]
but not [a,b]
, shift the sample and range. (Note, this assumes that the quantization is linear.)
// from question.
byte quantize(double sample, double max_value)
{
return (byte)((sample / max_value) * 255.0);
}
byte quantize( double sample, double min, double max )
{
return quantize( sample - min, max - min );
}