Skip to main content

quantize

Function quantize 

Source
pub const fn quantize<const BITS: u32>(v: Q0_16) -> (u16, i32)
Expand description

Truncate a Q0_16 channel toward zero to a BITS-wide code.

BITS must be in 1..=16. The quantized value q occupies the low BITS bits (0..=2^BITS-1). expand reconstructs the truncated Q0_16 value (zeros in discarded bits). The residual is the signed error in UQ0.16 units: v - expand::<BITS>(q).

For unsigned channels, truncation toward zero never yields a negative residual; the type is i32 so a later dither stage can carry a signed error without this crate choosing a rounding policy.