Skip to main content

Crate oxideav_g711

Crate oxideav_g711 

Source
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 / AlawEncoder implementing the oxideav_codec traits. Each encoded byte carries exactly one S16 PCM sample.
mulaw
µ-law (ITU-T G.711 §3) codec — single-sample conversion helpers plus UlawDecoder / UlawEncoder implementing the oxideav_codec traits. 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.