Expand description
Pure-Rust AAC decoder (LC, Main, LTP, HE-AAC v1/v2, ER LC/LTP/LD/ELD) + AAC-LC encoder, no C and no FFI.
Extracted from (and the engine of) the
remade_ffmpeg_rs
project. The crate has zero dependencies.
- Decoder: the MPEG-4 AAC family short of USAC — LC, Main (prediction),
LTP, HE-AAC v1 (SBR) and v2 (Parametric Stereo), ER AAC-LC/LTP, AAC-LD and
AAC-ELD; 1024/960-sample frames, mono to 7.1 and PCE layouts, coupling
channels. Sample-exact (≤1 LSB) against FFmpeg on every non-USAC
ISO/IEC 14496-26 conformance stream (two up to documented FFmpeg
deviations). Entry point:
AacDecoder(ADTS framing and raw MP4 access units alike),latm::LatmDecoderfor LOAS, or the lower-leveldecode::Decoderdriven by a fullconfig::StreamConfig. - Encoder: psychoacoustic Bark-scale masking model, two-phase bitrate
rate loop, transient-driven block switching, per-SFB M/S stereo, and a
frame-parallel
encode_stream(~450× realtime). Entry point:AacEncoderwithAacEncoderConfig. - Framing & config:
AudioSpecificConfig(the MP4esdspayload) andAdtsHeader(the.aacelementary-stream header) parsers plus their serializers (write_audio_specific_config,write_adts_header,audio_specific_config_bytes).
The simd feature (default) enables runtime-detected AVX2 kernels;
--no-default-features gives a 100%-safe scalar build. simd-avx512 adds
an opt-in AVX-512 tier.
Re-exports§
pub use encode::audio_specific_config_bytes;pub use encode::auto_bandwidth_hz;pub use encode::write_adts_header;pub use encode::write_audio_specific_config;pub use encode::AacEncoder;pub use encode::AacEncoderConfig;pub use encode::AacTuning;pub use encode::Bandwidth;pub use encode::EncodedPacket;pub use encode::WindowShape;
Modules§
- config
- The full
AudioSpecificConfig(GA/ELD/PCE/SBR/PS) — what a stream is. The fullAudioSpecificConfig(ISO/IEC 14496-3 §1.6.2.1) and everything it can carry:GASpecificConfig(§4.4.1), theprogram_config_element(§4.4.1.1),ELDSpecificConfig(§4.4.1.2) with its low-delay SBR headers, the error protection selector, and both SBR/PS signalling forms. - decode
- The AAC decoder:
raw_data_block/er_raw_data_block→ channel elements → spectral tools → synthesis → PCM (ISO 14496-3 §4.4 / §4.6). - encode
- In-house AAC-LC encoder (see
docs/finished/codec-aac-encoder.mdfor the brick ledger). Bricks 1–7 are complete: encode-side primitives inverting the decoder (bit writer, spectral-codebook encoder, header/config serializers), the forward filterbank, the quantizer + rate loop, a Bark-spreading psychoacoustic model, block switching, M/S stereo, and container/CLI integration. - latm
- LATM/LOAS transport (ISO 14496-3 §1.7) — the MPEG-TS / broadcast carriage
format, alongside ADTS (
.aac) and MP4esds. LATM / LOAS — the low-overhead transport (ISO 14496-3 §1.7). - prof
- Stage profiler + SIMD-arm census (feature
profile; no-ops without it). Stage profiler + kernel census (featureprofile; zero cost without it). - sbr
- HE-AAC (SBR / Parametric Stereo): signalling, capability reporting, and the reconstruction itself. See the module docs for exactly what is implemented. HE-AAC (SBR / PS) — signalling, detection, and honest capability reporting.
Structs§
- AacDecoder
- Stream-level AAC-LC decoder: accepts either ADTS frames (
.aacelementary streams — the config is read from the header) or bare raw access units (MP4 — configure viaAacDecoder::with_configfrom theesdsAudioSpecificConfig). - Adts
Header - A parsed ADTS frame header (ISO 14496-3 §1.A.2.2.1).
- Audio
Specific Config - Parsed
AudioSpecificConfig(ISO 14496-3 §1.6.2.1). - BitReader
- Reads bits most-significant-first from a byte slice (the order AAC uses).
- Decoded
Audio - One decoded frame of PCM: interleaved
f32samples in [-1, 1].
Enums§
- Error
- All the ways AAC decoding/encoding can fail — or, for
Error::Again/Error::Eof, signal normal stream flow control.
Constants§
- SAMPLE_
RATES - AAC sample-rate table, indexed by
samplingFrequencyIndex(ISO 14496-3).
Functions§
- adts_
raw_ blocks number_of_raw_data_blocks_in_frameof an ADTS header (0 = one block).- is_adts
- True if
databegins with an ADTS syncword (0xFFF, layer 00). - parse_
adts - Parse an ADTS header from the start of
data. - parse_
audio_ specific_ config - Parse an
AudioSpecificConfigfrom its raw bytes (theesds/stsdconfig). - sample_
rate_ for_ index - Map a 4-bit sampling-frequency index to a rate (0 for the reserved/escape values 13-15, which require an explicit 24-bit rate).
- sf_
index_ for_ rate - Map a sampling rate to its 4-bit index, or None if non-standard (the encoder then uses the 0x0F + explicit-24-bit-rate escape).
Type Aliases§
- Result
- Crate-wide result alias.