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 boxed Reader
.
Rust
let path = Path::new("some.mp3");
let f = File::open(&path).unwrap();
let decoder = Decoder::new(Box::new(f));
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.
TODO
libmad (FTP: ftp://ftp.mars.org/pub/mpeg/ or SourceForge)
libc
MIT