Crate simplemad [] [src]

This crate provides an interface to libmad, allowing the decoding of MPEG audio files, including MP3s.

simplemad::decode takes a byte-oriented source and returns a channel that yields Result<Frame, MadError>. Frame and MadError correspond to libmad's struct types mad_pcm and mad_error, respectively. Samples are signed 32 bit integers and are organized into channels. For stereo, the left channel is channel 0.

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.

Examples

use simplemad::decode;
use std::fs::File;
use std::path::Path;

let path = Path::new("sample_mp3s/constant_stereo_128.mp3");
let file = File::open(&path).unwrap();
let mut decoder = decode(file);

for item in decoder.iter() {
    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]);
        }
    }
}

Structs

Frame

A decoded frame

Enums

MadError

Errors generated by libmad

Functions

decode

Decode a file in full

decode_interval

Decode part of a file from start_time to end_time, measured in milliseconds