Symphonia provides a comprehensive set of primitives for working with decoded audio data. These primitives handle different sample formats, provide efficient planar audio storage, and enable safe conversion between formats.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pdeljanov/Symphonia/llms.txt
Use this file to discover all available pages before exploring further.
Core Audio Types
Symphonia’s audio system is built around several key types:AudioBuffer and AudioBufferRef
AudioBuffer<S>
AudioBuffer<S> (symphonia-core/src/audio.rs:283) is the fundamental audio container. It stores multi-channel audio in a planar format.
Planar vs Interleaved Layout
- Planar (AudioBuffer)
- Interleaved (SampleBuffer)
Samples are stored channel-by-channel:Benefits:
- Cache-friendly for DSP operations
- Easier to apply per-channel processing
- Native format for most decoders
AudioBufferRef
AudioBufferRef (symphonia-core/src/audio.rs:419) is an any-type wrapper returned by decoders. It hides the specific sample format using an enum:
Decoders return
AudioBufferRef because different codecs produce different sample formats. Your application must handle this polymorphism.Working with AudioBufferRef
Sample Formats
Symphonia supports all common audio sample formats via theSample trait.
Supported Sample Types
- Integer
- Floating Point
- Special
| Type | Bits | Range | Use Case |
|---|---|---|---|
u8 | 8 | 0 to 255 | Legacy formats, WAV |
i8 | 8 | -128 to 127 | Telephony |
u16 | 16 | 0 to 65535 | - |
i16 | 16 | -32768 to 32767 | CD audio, most hardware |
u24 | 24 | 0 to 16777215 | High-res audio |
i24 | 24 | -8388608 to 8388607 | Studio recording |
u32 | 32 | 0 to 4294967295 | - |
i32 | 32 | -2147483648 to 2147483647 | Studio processing |
Sample Trait
All sample types implement theSample trait, which provides:
MID constant represents silence:
- Unsigned: mid-point (128 for u8, 32768 for u16)
- Signed: zero (0)
- Float: zero (0.0)
Sample Conversions
Symphonia provides automatic sample format conversion:SampleBuffer
SampleBuffer<S> (symphonia-core/src/audio.rs:717) converts AudioBufferRef to a typed, interleaved sample buffer.
Creating and Using SampleBuffer
RawSampleBuffer
RawSampleBuffer<S> (symphonia-core/src/audio.rs:997) is like SampleBuffer, but provides samples as raw bytes.
When to Use RawSampleBuffer
UseRawSampleBuffer when:
- Interfacing with C APIs
- Writing to file formats
- Sending over network sockets
- Working with FFI boundaries
SignalSpec
SignalSpec (symphonia-core/src/audio.rs:164) describes the characteristics of an audio signal.
Creating SignalSpec
Channels and Layouts
Channels Bitmask
Channels (symphonia-core/src/audio.rs:36) is a bitmask representing channel configuration:
Channel Layouts
Pre-defined layouts for common configurations:Signal Trait
TheSignal trait (symphonia-core/src/audio.rs:501) provides methods for manipulating audio buffers:
Best Practices
Always Reuse Buffers
Always Reuse Buffers
Create
SampleBuffer and RawSampleBuffer once and reuse them:Prefer f32 for Processing
Prefer f32 for Processing
Use
f32 samples for DSP operations:- Normalized range [-1.0, 1.0]
- No overflow/underflow concerns
- Native format for most audio libraries
- Good precision for audio work
Handle Format Changes
Handle Format Changes
Be prepared for
Error::ResetRequired:Use Direct Access When Possible
Use Direct Access When Possible
If you only need one channel or specific processing, access channels directly:
Next Steps
Media Sources
Learn how Symphonia reads audio data from different sources
Decoding Audio
Complete guide to decoding audio files
Processing Audio
Apply effects and transformations to decoded audio
Exporting Audio
Convert and export audio to different formats