package lame

  1. Overview
  2. Docs

* Bindings to the lame library to encode mp3 files. * *

  • author Samuel Mimram

General informations

val get_lame_version : unit -> string

Get the lame version number.

val get_lame_short_version : unit -> string

Get the lame version number (shorter than get_lame_version).

val get_lame_very_short_version : unit -> string

Get the lame version number (shorter than get_lame_short_version).

val get_lame_url : unit -> string

Get the url of the lame website.

val get_psy_version : unit -> string

Get the version of the psy model.

Encoders

type encoder

Type for lame encoders.

val create_encoder : unit -> encoder

Create a new lame encoder.

Parameters

val set_in_samplerate : encoder -> int -> unit

Input sample rate in Hz (default: 44100).

val set_num_channels : encoder -> int -> unit

Number of channels in input stream (default: 2).

val set_out_samplerate : encoder -> int -> unit

* Output sample rate in Hz (default: 0, which means LAME picks best value * based on the amount of compression). MPEG only allows: * - MPEG1 (32, 44.1, 48 kHz) * - MPEG2 (16, 22.05, 24 kHz) * - MPEG2.5 (8, 11.025, 12 kHz)

val set_quality : encoder -> int -> unit

* Internal algorithm selection. True quality is determined by the bitrate * but this variable will effect quality by selecting expensive or cheap * algorithms. The quality is an integer between 0 and 9, where 0=best (very * slow) and 9=worst. More precisely: * - 2: near-best quality, not too slow (recommended) * - 5: good quality, fast * - 7: ok quality, really fast

type mode =
  1. | Stereo
    (*

    stereo, channels encoded independely

    *)
  2. | Joint_stereo
    (*

    stereo, channels encoded together

    *)
  3. | Dual_channel
    (*

    not supported

    *)
  4. | Mono
    (*

    mono

    *)

Compression mode.

val set_mode : encoder -> mode -> unit

Set the compression mode.

type vbr_mode =
  1. | Vbr_off
    (*

    constant bitrate

    *)
  2. | Vbr_rh
  3. | Vbr_abr
  4. | Vbr_mtrh
  5. | Vbr_max_indicator

VBR (Variable BitRate) mode.

val set_vbr_mode : encoder -> vbr_mode -> unit

Set the VBR mode.

val set_vbr_quality : encoder -> int -> unit

Set the VBR quality level (0:highest, 9: lowest).

val set_vbr_mean_bitrate : encoder -> int -> unit

Set the VBR mean birate in kbps. Only used by Vbr_abr mode.

val set_vbr_min_bitrate : encoder -> int -> unit

Set the minimal VBR bitrate in kbps.

val set_vbr_max_bitrate : encoder -> int -> unit

Set the maximal VBR bitrate in kbps.

val set_vbr_hard_min : encoder -> bool -> unit

If true, enforce the minimal VBR bitrate. Normally it will be violated * for analog silence.

val set_brate : encoder -> int -> unit

Set the bitrate of compressed data. You can either set this or use * set_compression_ratio.

val set_compression_ratio : encoder -> float -> unit

Set the compression ratio (default: 11).

val set_private : encoder -> bool -> unit

Get/set private bit.

val get_private : encoder -> bool

Get/set copyright bit.

val set_original : encoder -> bool -> unit

Get/set original bit.

val get_original : encoder -> bool
exception Init_params_failed

A call to init_params failed for some reason.

val init_params : encoder -> unit

Initialize lame's parameters. Should be called before encoding (and after * having set the parameters). Raises Init_params_failed on error.

val init_bitstream : encoder -> unit

Write id3v2 and Xing headers into the front of the bitstream, and set * frame counters and bitrate histogram data to 0. Normally, this is called by * init_params. You can call this after encode_flush_nogap.

Encoding

exception Init_params_not_called

You should have called init_params.

exception Psychoacoustic_problem

A problem occured with psychoacoustics.

exception Unknown_error of int

This should not have happened. Please report.

val encode_buffer_part : encoder -> string -> int -> int -> string

encode_buffer_part enc buf ofs smpl encodes samples * samples (per channel) of buf starting at position ofs.

val encode_buffer : encoder -> string -> int -> string

Same as encode_buffer_part but with ofs = 0.

val encode_buffer_float_part : encoder -> float array -> float array -> int -> int -> string

encode_buffer_float_part enc left right ofs smpl encodes samples * samples of left and right channels starting at position ofs. * Floats are expected to range over -1;1.

val encode_buffer_float : encoder -> float array -> float array -> int -> string

Same as encode_buffer_float_part but with ofs = 0.

Encode a buffer of samples. The samples follow here lame's convention of having floats in the range -32768.,32768. (yes, this is crazy but that's the way things are).

val encode_flush : encoder -> string

Flush the PCM buffers, padding with zeros if needed to make a complete * frame. Will also write id3v1 tags (if any) into the bitstream.

val encode_flush_nogap : encoder -> string

Flush the PCM buffers, padding with zeros if needed to make a complete * frame. This function will not write id3v1 tags into the bitstream.

Id3 tags

module Id3tag : sig ... end

Informations about encoding

type mpeg_version =
  1. | Mpeg_1
    (*

    MPEG v1

    *)
  2. | Mpeg_2
    (*

    MPEG v2

    *)
  3. | Mpeg_2_5
    (*

    MPEG v2.5

    *)

MPEG version.

val get_version : encoder -> mpeg_version

The MPEG version used by the encoder.

val get_encoder_delay : encoder -> int

Get the encoder delay.

val get_framesize : encoder -> int

Size of an mpeg frame in bytes.

val get_nb_samples_to_encode : encoder -> int

Number of PCM samples buffered, but not yet encoded to mp3 data.

val get_nb_encoded_frames : encoder -> int

Number of frames encoded so far.

val get_nb_frames : encoder -> int

Estimate of the total number of frames to be encoded * (only valid if set_nb_samples was called).

OCaml

Innovation. Community. Security.