Module g711

Source
Expand description

G.711 Audio Codec Implementation

This module implements the G.711 codec with both μ-law (PCMU) and A-law (PCMA) variants. G.711 is the standard codec for telephony systems.

§Features

  • ITU-T G.711 compliant implementation
  • Both A-law and μ-law encoding/decoding
  • Simple single-sample functions
  • Lookup table optimized for performance

§Usage

§Direct Function Calls

use codec_core::codecs::g711::{alaw_compress, alaw_expand, ulaw_compress, ulaw_expand};

// Single sample processing
let sample = 1024i16;
let alaw_encoded = alaw_compress(sample);
let alaw_decoded = alaw_expand(alaw_encoded);

let ulaw_encoded = ulaw_compress(sample);
let ulaw_decoded = ulaw_expand(ulaw_encoded);

§Processing Multiple Samples

use codec_core::codecs::g711::{alaw_compress, alaw_expand};

let samples = vec![0i16, 100, -100, 1000, -1000];
let encoded: Vec<u8> = samples.iter().map(|&s| alaw_compress(s)).collect();
let decoded: Vec<i16> = encoded.iter().map(|&e| alaw_expand(e)).collect();

§Using the G711Codec Struct

use codec_core::codecs::g711::{G711Codec, G711Variant};
use codec_core::types::{AudioCodec, CodecConfig, CodecType, SampleRate};

// Create μ-law codec
let config = CodecConfig::new(CodecType::G711Pcmu)
    .with_sample_rate(SampleRate::Rate8000)
    .with_channels(1);
let mut codec = G711Codec::new_pcmu(config)?;

// Or create A-law codec directly
let mut alaw_codec = G711Codec::new(G711Variant::ALaw);

// Encode/decode
let samples = vec![0i16; 160]; // 20ms at 8kHz
let encoded = codec.encode(&samples)?;
let decoded = codec.decode(&encoded)?;

Structs§

G711Codec
G.711 codec implementation

Enums§

G711Variant
G.711 codec variants

Functions§

alaw_compress
A-law compression according to ITU-T G.711
alaw_expand
A-law expansion according to ITU-T G.711
init_tables
Initialize G.711 lookup tables (stub for compatibility)
ulaw_compress
μ-law compression according to ITU-T G.711
ulaw_expand
μ-law expansion according to ITU-T G.711