Overview
Symphonia provides a pure Rust implementation of the Apple Lossless Audio Codec (ALAC) decoder. ALAC is a lossless audio compression format developed by Apple, commonly used in M4A and CAF containers.Feature Flag
To enable ALAC support, add thealac feature to your Cargo.toml:
Status
Status: Excellent- Decoding: Fully supported
- Gapless Playback: Yes
- Container Support: ISO MP4/M4A, CAF (Core Audio Format)
Codec Type
Decoder
The ALAC decoder is implemented by theAlacDecoder struct:
Container Requirements
ALAC requires a container format:Supported Features
ALAC Version
- ALAC Version 0 (current standard)
Bit Depths
- 16-bit
- 20-bit
- 24-bit
- 32-bit
Sample Rates
All sample rates up to 384 kHz, including:- 8 kHz, 11.025 kHz, 12 kHz
- 16 kHz, 22.05 kHz, 24 kHz
- 32 kHz, 44.1 kHz, 48 kHz
- 88.2 kHz, 96 kHz
- 176.4 kHz, 192 kHz
- 352.8 kHz, 384 kHz
Channel Layouts
Supports standard Apple Core Audio channel layouts:- Mono (1.0): C
- Stereo (2.0): L, R
- MPEG 3.0 B: C, L, R
- MPEG 4.0 B: C, L, R, Cs
- MPEG 5.0 D: C, L, R, Ls, Rs
- MPEG 5.1 D: C, L, R, Ls, Rs, LFE
- AAC 6.1: C, L, R, Ls, Rs, Cs, LFE
- MPEG 7.1 B: C, Lc, Rc, L, R, Ls, Rs, LFE
Codec Parameters
ALAC requires codec-specific configuration (“magic cookie”):Magic Cookie Structure
The magic cookie contains:- Frame length (samples per frame)
- Compatible version
- Bit depth
- Compression parameters (pb, mb, kb)
- Number of channels
- Maximum frame size
- Average bitrate
- Sample rate
- Channel layout information (optional)
Compression Modes
ALAC supports multiple prediction methods:Prediction Types
- Uncompressed: Raw PCM samples
- Linear Prediction: LPC with orders up to 31
- Adaptive Prediction: Automatic coefficient adjustment
Encoding Elements
- SCE: Single Channel Element (mono)
- CPE: Channel Pair Element (stereo pairs)
- LFE: Low Frequency Element (subwoofer)
Usage Example
Sample Format
ALAC decodes to signed 32-bit integer samples:Metadata Support
ALAC files in MP4 containers support iTunes metadata:Rice Coding
ALAC uses adaptive Rice coding for efficient lossless compression:- Dynamic parameter selection
- Run-length encoding for silence
- Efficient representation of prediction residuals
Performance
- Pure Rust implementation with no unsafe code
- Efficient Rice decoder
- Optimized LPC predictor
- Low memory overhead
- Streaming-friendly design
Limitations
- Decode-only (no encoding support)
- Maximum 8 channels
- Requires container format (cannot decode raw ALAC)
- ALAC Version 0 only (latest version)
Comparison with Other Lossless Codecs
| Feature | ALAC | FLAC |
|---|---|---|
| Compression | ~40-50% | ~40-60% |
| Speed | Fast | Fast |
| Max Bit Depth | 32-bit | 32-bit |
| Max Channels | 8 | 8 (Symphonia) |
| iTunes Support | Native | Limited |