Skip to main content

Crate rusty_aac

Crate rusty_aac 

Source
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::LatmDecoder for LOAS, or the lower-level decode::Decoder driven by a full config::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: AacEncoder with AacEncoderConfig.
  • Framing & config: AudioSpecificConfig (the MP4 esds payload) and AdtsHeader (the .aac elementary-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::write_adts_header;
pub use encode::write_audio_specific_config;
pub use encode::AacEncoder;
pub use encode::AacEncoderConfig;
pub use encode::EncodedPacket;
pub use encode::WindowShape;

Modules§

config
The full AudioSpecificConfig (GA/ELD/PCE/SBR/PS) — what a stream is. The full AudioSpecificConfig (ISO/IEC 14496-3 §1.6.2.1) and everything it can carry: GASpecificConfig (§4.4.1), the program_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.md for 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 MP4 esds. 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 (feature profile; 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 (.aac elementary streams — the config is read from the header) or bare raw access units (MP4 — configure via AacDecoder::with_config from the esds AudioSpecificConfig).
AdtsHeader
A parsed ADTS frame header (ISO 14496-3 §1.A.2.2.1).
AudioSpecificConfig
Parsed AudioSpecificConfig (ISO 14496-3 §1.6.2.1).
BitReader
Reads bits most-significant-first from a byte slice (the order AAC uses).
DecodedAudio
One decoded frame of PCM: interleaved f32 samples 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_frame of an ADTS header (0 = one block).
is_adts
True if data begins with an ADTS syncword (0xFFF, layer 00).
parse_adts
Parse an ADTS header from the start of data.
parse_audio_specific_config
Parse an AudioSpecificConfig from its raw bytes (the esds/stsd config).
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.