Module Vorbis


module Vorbis: sig .. end
Decode from or encode to the Ogg Vorbis compressed audio format; or get informations about an Ogg Vorbis file.
Author(s): Samuel Mimram, Julien Cristau


Exceptions


exception Invalid_parameters
Some parameters are invalid for this function.
exception Invalid_quality
The given quality in invalid.
exception Invalid_bitrate
The given bitrate is invalid.
exception Invalid_channels
The given number of channels is invalid.
exception Invalid_sample_freq
The given sampling frequency is invalid.
exception Could_not_open_file
The given file could not be opened.
exception Not_a_vorbis_file
The given file is not in ogg/vorbis format.
exception Hole_in_data
There is a hole in the data.
exception Utf8_failure of string
Error while converting utf8.

Encoding


type encoder 
An ogg encoder.

type enc_params = {
   enc_bitrate : int option; (*ouput birate in kbit/s*)
   enc_min_bitrate : int option; (*minimal output bitrate in kbit/s*)
   enc_max_bitrate : int option; (*maximal output bitrate in kbit/s*)
   enc_quality : float; (*quality of encoding between 0.0 and 1.0 (1.0 ~ 160 kbit/s, the higher the better)*)
   enc_channels : int; (*number of channels (should be 1 or 2)*)
   enc_sample_freq : int option; (*sampling frequency*)
   enc_managed : bool; (*shoud libvorbis manage parameters?*)
   enc_in_channels : int; (*number of channels of input*)
   enc_in_sample_freq : int; (*sampling frequency of input*)
   enc_in_sample_size : int; (*sample size of input in bits*)
   enc_in_big_endian : bool; (*is the input data stored in big endian?*)
}
Parameters for encoders, specifying input and output format.
val create_encoder : ?title:string ->
?artist:string ->
?genre:string ->
?date:string ->
?album:string ->
?tracknum:string -> enc_params -> encoder * string
Create a new encoder.
val create_encoder_opt : string option ->
string option ->
string option ->
string option ->
string option ->
string option -> enc_params -> encoder * string
val encode_buffer : encoder -> string -> string
Encode a wav buffer into ogg.

Decoding



type dec_params = {
   channels : int; (*number of channels (WARNING: it isn't taken in account yet)*)
   sample_freq : int; (*sampling frequency in Hertz*)
   sample_size : int; (*sample size in bits*)
   big_endian : bool; (*store data in big endian ? (default is little endian)*)
   signed : bool; (*sign for PCM output ? (default is signed)*)
}
Output wav format parameters for decoders.
type dec_file 
Ogg/vorbis file opened in input (for decoding).
val open_dec_file : string -> dec_params -> dec_file
Open an ogg/vorbis file for decoding. Can raise: Could_not_open_file or Not_a_vorbis_file.
val decode : dec_file -> string -> int -> int -> int
decode dec_file buf ofs len decodes len octets of wav and put them in buf starting at position pos. It can raise: End_of_file when the whole file has been decoded, Hole_in_data, Invalid_parameters if all the data cannot fit in the buffer starting at the given position.
val close_dec_file : dec_file -> unit
Close an ogg/vorbis file opened for decoding. The file descriptor used for the matching open_dec_file is closed (I think).
val encoder_reset : ?title:string ->
?artist:string ->
?genre:string ->
?date:string -> ?album:string -> ?tracknum:string -> encoder -> string
Reset the encoder state to a fresh, initialized state with the given metadata
val encoder_reset_opt : string option ->
string option ->
string option ->
string option -> string option -> string option -> encoder -> string

Informations about files



type info = {
   vorbis_version : int; (*version of vorbis codec, must be 0*)
   audio_channels : int; (*number of audio channels*)
   audio_sample_rate : int; (*samplerate in Hertz*)
   bitrate_maximum : int option; (*maximum bitrate in kbit/s*)
   bitrate_nominal : int option; (*nominal bitrate in kbit/s*)
   bitrate_minimum : int option; (*minimal bitrate in kbit/s*)
   blocksize_0 : int;
   blocksize_1 : int;
   duration : int; (*duration of the file in seconds*)
}
Vorbis informations about a file.
val get_comments : string -> string * (string * string) array
Get the vorbis comments from a file (see Vorbis.Info.get_comments).
val get_info : string -> info
Get the vorbis information from the file header.
val file_size : string -> int
Get the size of a file (in bytes).
module type Iofile = sig .. end
Signature of a module to access to files.
module Info: 
functor (Io : Iofile) -> sig .. end
Get info and comments from a vorbis file via the Io module.