simplemad is a simple interface for libmad, the MPEG audio decoding library. simplemad is useful for those who need to decode MP3 or other MPEG audio files in full.
Create a Decoder
from a Reader
.
Rust
let path = Path::new("some.mp3");
let file = File::open(&path).unwrap();
let decoder = Decoder::new(file);
Decoder
implements Iterator
and yields a sequence of Result<Frame, MadError>
.
Rust
for item in decoder {
match item {
Err(e) => {
println!("Error: {:?}", e);
},
Ok(frame) => {
println!("Frame sample rate: {}", frame.sample_rate);
println!("First audio sample (left channel): {}", frame.samples[0][0]);
println!("First audio sample (right channel): {}", frame.samples[1][0]);
}
}
}
libmad samples are signed 32-bit integers. MP3 files often begin with metadata, which will cause libmad to complain. It is safe to ignore errors until libmad reaches audio data and starts producing frames.
First, install libmad. Links to the source can be found below. It might be necessary to apply the patch found in this guide. Then add simplemad = "0.2.1"
to the list of dependencies in your Cargo.toml.
TODO
libmad (FTP: ftp://ftp.mars.org/pub/mpeg/ or SourceForge)
libc
MIT