Expand description
A safe rust wrapper of libsndfile. With this crate, you can read or save audio files.
Getting started
With minimal features:
[dependencies]
sndfile = "0.1"
With ndarray supports:
[dependencies.sndfile]
version = "0.1"
features = ["ndarray_features"]
Example
ⓘ
extern crate sndfile;
extern crate ndarray;
fn main() {
use sndfile::*;
let mut snd = sndfile::OpenOptions::ReadOnly(ReadOptions::Auto).from_path(
"./sample_song.flac"
).unwrap();
let data: ndarray::Array2<f32> = snd.read_all_to_ndarray().unwrap();
let samplerate = snd.get_samplerate();
let n_frame = snd.len().unwrap();
let n_channels = snd.get_channels();
let title = snd.get_tag(TagType::Title).unwrap();
println!("Loaded song `{}`:", title);
println!(" Length: {:.2} seconds", n_frame as f64 / samplerate as f64);
println!(" Sample rate: {} Hz", samplerate);
println!(" Channel count: {}", n_channels);
println!(" DC offset = {}", data.mean().unwrap());
}
/*
== Expected output ==
Loaded song `Loow`:
Length: 277.06 seconds
Sample rate: 44100 Hz
Channel count: 2
DC offset = 0.00018921464
*/
Structs
Main struct of this crate.
This struct is unstable.
Options for writing audio files.
Enums
Struct to specify options when opening a audio file.
Options for reading audio files.
Type of tags
Traits
Do I/O operation on slice or iterator.
Do I/O operation on 2D ndarray.
Functions
This function allows the caller to check if a set of parameters before opening a file in write mode.
Returns default audio encoding format for given audio container format
Lock it before interacting with a few raw libsndfile
functions in multithread context.
Get all supported audio container format
Get all supported audio encoding format