Symphonium
An unofficial easy-to-use wrapper around Symphonia for loading audio files. It also handles resampling at load-time.
The resulting DecodedAudio resources are stored in their native sample format whenever possible to save on memory, and have convenience methods to fill a buffer with f32 samples from any arbitrary position in the resource in realtime during playback. Alternatively you can use the DecodedAudioF32 resource if you only need samples in the f32 format.
Example
let target_sample_rate = new.unwrap;
// An optional cache to re-use decoders and resamplers.
let cache = default;
// Probe the audio file.
let probed = probe_from_file
.unwrap;
// Decode the probed data.
let audio_data = decode
.unwrap;
// Fill a stereo buffer with samples starting at frame 100.
let mut buf_l = vec!;
let mut buf_r = vec!;
audio_data.fill_stereo;
// Alternatively, if you don't need to save memory, you can
// decode directly to an `f32` format.
let probed = probe_from_file.unwrap;
let audio_data_f32 = decode_f32
.unwrap;
// Print info about the data (`data` is a `Vec<Vec<f32>>`).
println!;
println!;
Cargo Features
Codecs and Container Formats
By default, only wav/pcm and ogg/vorbis is enabled. If you need more formats, enable them as features in your Cargo.toml file like this:
= { = "0.11", = ["mp3", "flac"] }
Available codecs:
aacadpcmalacflacmp1mp2mp3pcm(default)vorbis(default)
Available container formats:
cafisomp4mkvogg(default)aiffwav(default)
Alternatively you can enable these group features:
all- Includes all codecs and container formatsall-codecs- Includes all codecsall-formats- Includes all container formatsopen-standards- Include all royalty-free open standard codecs and formats (adpcm, flac, mkv, ogg, pcm, vorbis, wav)
Resampling
resampler(default) - Enables resampling at load timefft-resampler(default) - Enables the fft-based resampling algorithm (recommended)stretch-sinc-resampler- Enables the "arbitrary sinc" resampler for changing the pitch/length of samples
Performance
opt-simd(default) - Enable all SIMD supportopt-simd-sse(default)opt-simd-avx(default)opt-simd-neon(default)
Other
decode-native(default) - Enables theDecodedAudiotype and methods that attempts to decode the file into its native sample format to save on memory. This can be disabled if you only need theDecodedF32type.tracing(default) - Use thetracingcrate for logginglog- Use thelogcrate for logging
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.