simplemad is a simple interface for libmad, the MPEG audio decoding library.
To begin, create a Decoder
from a byte-oriented source using
Decoder::decode
or Decoder::decode_interval
. Fetch results using
get_frame
or the Iterator
interface.
MP3 files often begin with metadata, which will cause libmad to produce errors. It is safe to ignore these errors until libmad reaches audio data and starts producing frames.
```Rust use simplemad::{Decoder, Frame}; use std::fs::File; use std::path::Path;
let path = Path::new("samplemp3s/constantstereo_128.mp3"); let file = File::open(&path).unwrap(); let decoder = Decoder::decode(file).unwrap();
for decodingresult in decoder { match decodingresult { 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]); }, } } ```
Decode the interval from 30 seconds to 60 seconds:
Rust
let mut partial_decoder = Decoder::decode_interval(file, 30_000_f64, 60_000_f64).unwrap();
On Linux, libmad will be built automatically, if it is not installed. On other operating systems, it is necessary to install libmad manually. Links to libmad can be found below. If you are building from source, you will also need to apply the patch found in this guide.
http://bendykst.github.io/doc/simplemad/index.html
libmad (FTP: ftp://ftp.mars.org/pub/mpeg/ or SourceForge)
libc
MIT