Module Mad


module Mad: sig .. end
Functions for decoding mp3 files using the libmad.


Author(s): Samuel Mimram



Exceptions


exception Mad_error of string
An error occured with libmad.
exception Read_error of string
An error occured while reading a file.
exception End_of_stream
The end of the mp3 stream was reached.
exception Openfile_error of string
Could not open a file.
exception Closefile_error of string
Could not close a file.

Decoding files


type mad_file 
An mp3 file opened for decoding.
val openfile : string -> mad_file
Open an mp3 file.


Raises Openfile_error if an error occured while trying to open the file.

val openstream : (int -> string * int) -> mad_file
openstream read_func opens a stream where read_func n should be a function which returns n bytes of data or less, the second component of the result being the number of bytes to read in the fist component.
val close : mad_file -> unit
Close an mp3 file previously opened with openfile.


Raises Closefile_error if an error occured while trying to close the file.

val get_current_position : mad_file -> int
Get the current position (in bytes) of the decoder in the mp3 file which should have been opened with openfile.
val decode_frame : mad_file -> string
Decode an mp3 frame. Returned data in interleaved when there are two channels, and mono data when there is only one.
val decode_frame_float : mad_file -> float array array
Decode an mp3 frame.
val get_output_format : mad_file -> int * int * int
Get the samplerate, number of channels and samples per channel currently in the synth. This should be called after decode_frame or decode_frame_float.
val duration : string -> float
Compute the duration of a file, in seconds. Never raises any exception, but returns 0. in case of error. The returned duration is exact but its computation is not efficient, as it proceeds by completely decoding the file.