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§
- Major
Info - SndFile
- Main struct of this crate.
- Subtype
Info - Unsafe
SndFile - This struct is unstable.
- VIOFile
- Write
Options - Options for writing audio files.
Enums§
- Endian
- Major
Format - Open
Options - Struct to specify options when opening a audio file.
- Read
Options - Options for reading audio files.
- SndFile
Error - Subtype
Format - TagType
- Type of tags
Traits§
- SndFileIO
- Do I/O operation on slice or iterator.
- SndFileND
ArrayIO - Do I/O operation on 2D ndarray.
Functions§
- check_
format - This function allows the caller to check if a set of parameters before opening a file in write mode.
- default_
subtype - Returns default audio encoding format for given audio container format
- get_
sf_ global_ lock - Lock it before interacting with a few raw
libsndfile
functions in multithread context. - get_
supported_ major_ format_ dict - Get all supported audio container format
- get_
supported_ subtype_ format_ dict - Get all supported audio encoding format