Skip to main content

Module companding

Module companding 

Source
Expand description

Audio companding: the non-linear µ-law and “A”-law compression curves used by the ITU-T G.711 telephony standard to compress a wide-dynamic-range linear audio sample down to a lower bit depth with minimal perceptual loss (Steven W. Smith, “The Scientist and Engineer’s Guide to DSP”, Ch. 22, Eq. 22-1 / 22-2).

All functions operate on samples normalized to -1.0..=1.0.

Functions§

a_law_compress_f32
Compresses a normalized linear sample x (-1.0..=1.0) using “A”-law companding (Eq. 22-2): a linear segment near zero, transitioning to a logarithmic curve.
a_law_expand_f32
Expands an “A”-law-compressed sample y (-1.0..=1.0) back to a normalized linear sample, inverting a_law_compress_f32.
alaw_to_linear
Decode a G.711 A-law byte to 16-bit linear PCM.
linear_to_alaw
Encode a 16-bit linear PCM sample to a G.711 A-law byte.
linear_to_ulaw
Encode a 16-bit linear PCM sample to a G.711 μ-law byte.
mu_law_compress_f32
Compresses a normalized linear sample x (-1.0..=1.0) using µ255-law companding (Eq. 22-1), expanding resolution for small amplitudes at the expense of large ones.
mu_law_expand_f32
Expands a µ-law-compressed sample y (-1.0..=1.0) back to a normalized linear sample, inverting mu_law_compress_f32.
ulaw_to_linear
Decode a G.711 μ-law byte to 16-bit linear PCM.