Skip to main content

Module audio

Module audio 

Source
Expand description

Audio codec framework.

Squad-24 (2026-04-17 PM5): adds the decoder/encoder traits + the wire types Squad-23 (audio mux pipeline) consumes. Decoders cover MP3 and Vorbis (mux already handles AAC/Opus/AC-3 passthrough — no decode needed for those). The encoder side currently exposes Opus only; the user decision on the audio expansion in TODO.md picked Opus over AAC because the libopus binding is BSD/Apache, modern browsers all play Opus-in-MP4, and the iOS-13-and-older floor is acceptable.

§Wire model

  • AudioFrame is the canonical PCM exchange type: f32 in [-1.0, 1.0], interleaved planar layout (LRLRLR for stereo), with the source sample rate and channel count carried alongside the samples and a microsecond-domain PTS.
  • EncodedAudioPacket carries one encoder output packet plus PTS/duration in encoder timescale (Opus = 48000 ticks per second per RFC 7845 §4.1).
  • AudioDecoder / AudioEncoder traits are object-safe so pipeline code can hand out Box<dyn AudioEncoder>.

§Pre-skip + extra_data contract (Opus-specific)

AudioEncoder::pre_skip returns the number of 48 kHz samples of lookahead the libopus encoder injects (queried via OPUS_GET_LOOKAHEAD and reported in 48 kHz ticks no matter the configured rate). Squad-23’s mux side writes this into the dOps body so a conformant decoder discards the lookahead at the start of the file.

AudioEncoder::extra_data returns the dOps body bytes per RFC 7845 §4.5: 11 bytes minimum, channel-mapping family 0 (mono/stereo). Multistream (>2 channels) is out of scope for this sprint and returns AudioError::Unsupported.

Modules§

decode
Audio decoder implementations.
encode
Audio encoder implementations.
resample
Sample-rate conversion using rubato’s SincFixedIn (high-quality windowed-sinc with band-limited interpolation).

Structs§

AudioEncoderConfig
AudioFrame
One decoded audio frame.
EncodedAudioPacket
One encoded audio packet leaving the encoder.

Enums§

AudioCodec
AudioError

Traits§

AudioDecoder
AudioEncoder

Functions§

create_decoder
Construct an audio decoder for the given codec name.
create_encoder
Construct an audio encoder.