pub fn linear_to_ulaw(sample: i16) -> u8Expand description
Encode one linear PCM16 sample as a μ-law byte (ITU-T G.711).
The rule is ITU-T G.191’s ulaw_compress (the STL reference
implementation of G.711): the 16-bit sample is taken to the 14-bit
domain with an arithmetic shift, a negative sample’s magnitude is its
one’s complement (so -1 encodes as negative zero, 0x7F, and -4 as
the first negative step), the bias of 33 is added, and the segment and
mantissa are read off the biased value. Bit-exact with G.191 for every
input (reference_tests). The Sun g711.c formulation used by sox and
Asterisk negates instead of complementing and differs from G.191 by one
code at negative step boundaries; decoders agree on both.