Expand description
§Project Symphonia
Symphonia is a 100% pure Rust audio decoding and multimedia format demuxing framework.
§Support
Supported formats, codecs, and metadata tags are listed below. By default Symphonia only enables royalty-free open standard media formats and codecs. Other formats and codecs must be enabled using feature flags.
Tip: All formats and codecs can be enabled with the all feature flag.
§Formats
The following container formats are supported.
| Format | Feature Flag | Gapless* | Default |
|---|---|---|---|
| AIFF | aiff | Yes | No |
| CAF | caf | No | No |
| ISO/MP4 | isomp4 | No | No |
| MKV/WebM | mkv | No | Yes |
| OGG | ogg | Yes | Yes |
| Wave | wav | Yes | Yes |
* Gapless playback requires support from both the demuxer and decoder.
Tip: All formats can be enabled with the all-formats feature flag.
§Codecs
The following codecs are supported.
| Codec | Feature Flag | Gapless | Default |
|---|---|---|---|
| AAC-LC | aac | No | No |
| ADPCM | adpcm | Yes | Yes |
| ALAC | alac | Yes | No |
| FLAC | flac | Yes | Yes |
| MP1 | mp1, mpa | No | No |
| MP2 | mp2, mpa | No | No |
| MP3 | mp3, mpa | Yes | No |
| PCM | pcm | Yes | Yes |
| Vorbis | vorbis | Yes | Yes |
Tip: All codecs can be enabled with the all-codecs feature flag. Similarly, all MPEG
audio codecs can be enabled with the mpa feature flag.
§Metadata
The following metadata tagging formats are supported. These are always enabled.
- ID3v1
- ID3v2
- ISO/MP4
- RIFF
- Vorbis Comment (in OGG & FLAC)
§Optimizations
SIMD optimizations are not enabled by default. They may be enabled on a per-instruction
set basis using the following feature flags. Enabling any SIMD support feature flags will pull
in the rustfft dependency.
| Instruction Set | Feature Flag | Default |
|---|---|---|
| SSE | opt-simd-sse | No |
| AVX | opt-simd-avx | No |
| Neon | opt-simd-neon | No |
Tip: All SIMD optimizations can be enabled with the opt-simd feature flag.
§Usage
The following steps describe a basic usage of Symphonia:
- Instantiate a
CodecRegistryand register all the codecs that are of interest. Alternatively, you may usedefault::get_codecsto get the default registry with all the enabled codecs pre-registered. The registry will be used to instantiate aDecoderlater. - Instantiate a
Probeand register all the formats that are of interest. Alternatively, you may usedefault::get_probeto get a default format probe with all the enabled formats pre-registered. The probe will be used to automatically detect the media format and instantiate a compatibleFormatReader. - Make sure the
MediaSourcetrait is implemented for whatever source you are using. This trait is already implemented forstd::fs::Fileandstd::io::Cursor. - Instantiate a
MediaSourceStreamwith theMediaSourceabove. - Using the
Probe, callformatand pass it theMediaSourceStream. - If the probe successfully detects a compatible format, a
FormatReaderwill be returned. This is an instance of a demuxer that can read and demux the provided source intoPackets. - At this point it is possible to interrogate the
FormatReaderfor general information about the media and metadata. Examine theTracklisting usingtracksand select one or more tracks of interest to decode. - To instantiate a
Decoderfor a selectedTrack, call theCodecRegistry’smakefunction and pass it theCodecParametersfor that track. This step is repeated once per selected track. - To decode a track, obtain a packet from the
FormatReaderby callingnext_packetand then pass thePacketto theDecoderfor that track. Thedecodefunction will read a packet and return anAudioBufferRef(an “any-type”AudioBuffer). - The
AudioBufferRefmay be used to access the decoded audio samples directly, or it can be copied into aSampleBufferorRawSampleBufferto export the audio out of Symphonia. - Repeat step 9 and 10 until the end-of-stream error is returned.
An example implementation of a simple audio player (symphonia-play) can be found in the Project Symphonia git repository.
§Gapless Playback
Gapless playback is disabled by default. To enable gapless playback, set
FormatOptions::enable_gapless to true.
§Adding new formats and codecs
Simply implement the Decoder trait for a decoder or the
FormatReader trait for a demuxer trait and register with
the appropriate registry or probe!
Re-exports§
pub use symphonia_core as core;
Modules§
- default
- The
defaultmodule provides convenience functions and registries to get an implementer up-and-running as quickly as possible, and to reduce boiler-plate. Using thedefaultmodule is completely optional and incurs no overhead unless actually used.