package mad

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

* Functions for decoding mp3 files using the libmad. * *

  • author 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.

type mpeg_layer =
  1. | Layer_I
  2. | Layer_II
  3. | Layer_III
type emphasis =
  1. | None
  2. | MS_50_15
  3. | CCITT_J_17
  4. | Reserved
type channel_mode =
  1. | Single_channel
  2. | Dual_channel
  3. | Joint_stereo
  4. | Stereo
type frame_format = {
  1. layer : mpeg_layer;
  2. mode : channel_mode;
  3. emphasis : emphasis;
  4. bitrate : int;
  5. samplerate : int;
  6. channels : int;
  7. samples_per_channel : int;
  8. original : bool;
  9. copyright : bool;
  10. private_bit : bool;
}
type read = bytes -> int -> int -> int

Type for abstract reader.

val openfile : string -> mad_file

* Open an mp3 file. * *

  • raises Openfile_error

    if an error occured while trying to open the file.

val openstream : read -> 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 skip_id3tags : read:read -> seek:(int -> int) -> tell:(unit -> int) -> unit

* Skip ID3 tags that may be present at * the beginning of a stream. This function * may be used to a mp3 file opened using openstream. * ID3 tags are always skipped when using openfile. * * seek is a callback to seek to an absolute * position on the encoded data, and tell a callback * to fetch the current position. read is the reading * callback.

val close : mad_file -> unit

* Close an mp3 file previously opened with openfile. * *

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.

type time_unit =
  1. | Hours
  2. | Minutes
  3. | Seconds
  4. | Deciseconds
  5. | Centiseconds
  6. | Milliseconds
val get_current_time : mad_file -> time_unit -> int

* Get the current time position (in the given unit) of the decoder.

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 decode_frame_floatarray : mad_file -> floatarray array

Decode an mp3 frame.

val decode_frame_float_ba : mad_file -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t array
val skip_frame : mad_file -> unit

Skip one frame. The current time/position is * updated but the frame is not decoded.

val get_frame_format : mad_file -> frame_format
val get_output_format : mad_file -> int * int * int
val duration : string -> float

Compute the duration of a file, in seconds. * Never raises any exception, but returns 0. in case of error.

OCaml

Innovation. Community. Security.