Expand description
ITU-T G.711 µ-law / A-law PCM codec.
G.711 is the classic PSTN audio codec — 8 kHz mono, 8-bit samples that round-trip to ~13-bit linear quality via a logarithmic companding curve. Two variants, selected by codec id:
- µ-law (North America / Japan): codec ids
pcm_mulaw,ulaw,g711u. - A-law (rest of the world): codec ids
pcm_alaw,alaw,g711a.
Both variants are byte-for-sample: one encoded byte on input yields one S16 PCM sample on output, and vice versa. The spec defines G.711 at 8 kHz mono but the implementation is stateless per sample and therefore works at any sample rate and any interleaved channel count the caller provides.
§Algorithm
Decoding uses a compile-time 256-entry lookup table generated from the
ITU-T G.711 bit layout (see tables). Encoding is arithmetic: sign
extraction → bias + segment search → mantissa extraction → on-wire
inversion. There is no signal processing state, so each byte /sample
is independent and packets may be arbitrary-length.
§Registration
register wires up both laws under each of their aliases via
CodecRegistry::register_both — i.e. pcm_mulaw, ulaw, and g711u
all resolve to the same mulaw::UlawDecoder / mulaw::UlawEncoder
pair, and likewise for A-law.
Modules§
- alaw
- A-law (ITU-T G.711 §2) codec — single-sample conversion helpers plus
AlawDecoder/AlawEncoderimplementing theoxideav_codectraits. Each encoded byte carries exactly one S16 PCM sample. - mulaw
- µ-law (ITU-T G.711 §3) codec — single-sample conversion helpers plus
UlawDecoder/UlawEncoderimplementing theoxideav_codectraits. Each encoded byte carries exactly one S16 PCM sample. - tables
- ITU-T G.711 conversion tables.
Constants§
- ALAW_
ALIASES - Aliases that resolve to the A-law implementation.
- CODEC_
ID_ ALAW - Canonical codec id for A-law (matches FFmpeg’s
pcm_alaw). - CODEC_
ID_ MULAW - Canonical codec id for µ-law (matches FFmpeg’s
pcm_mulaw). - MULAW_
ALIASES - Aliases that resolve to the µ-law implementation.
Functions§
- register
- Register every G.711 codec id + alias for both decode and encode.