package flac

  1. Overview
  2. Docs

Module Flac.EncoderSource

Encode native FLAC data

Usage

A typical use of the FLAC encoder is the following: *

   (* A function to write encoded data *)
* let write = (..a function of type write..) in
* (* Create the encoding callbacks *)
* let callbacks = Flac.Encoder.get_callbacks write in
* (* Define the parameters and comments *)
* let params = (..a value of type params ..) in
* let comments = [("title","FLAC encoding example")] in
* (* Create an encoder *)
* let enc = Flac.Encoder.create ~comments params callbacks in
* (* Encode data *)
* let data = (..a value of type float array array.. in
*  Flac.Encoder.process enc callbacks data ;
* (..repeat encoding process..)
* (* Close encoder *)
* Flac.Encoder.finish enc callbacks

* * Remarks: * - Exceptions raised by the callbacks should be treated * as fatal. The behaviour of the FLAC encoding library is * unknown after interrupted by an exception. * - Encoded data should have the same number of channels as * specified in encoder's parameters and the same number of * samples in each channels. * - See FLAC documentation for informations about the callbacks. * Note in particular that some information about encoded data * such as md5 sum and total samples are only written when a * seek callback is given. * - Variant types for callbacks and encoder are used to make sure * that different type of callbacks (generic, file, ogg) are always * used with the corresponding decoder type.

Types

Sourcetype t

Type of an encoder.

Sourcetype params = {
  1. channels : int;
  2. bits_per_sample : int;
  3. sample_rate : int;
  4. compression_level : int option;
  5. total_samples : int64 option;
}

Type of encoding parameters

Sourcetype comments = (string * string) list

(Vorbis) comments for encoding

Exceptions

Sourceexception Invalid_data

Raised when submiting invalid data to * encode

Sourceexception Invalid_metadata

Raised when initiating an encoder with * invalid metadata. You can use `vorbiscomment_entry_name_is_legal` * and `vorbiscomment_entry_value_is_legal` to check submitted metadata.

Functions

Sourceval vorbiscomment_entry_name_is_legal : string -> bool

Check if a comment label is valid

Sourceval vorbiscomment_entry_value_is_legal : string -> bool

Check if a comment value is valid

Sourceval create : ?comments:comments -> ?seek:(int64 -> unit) -> ?tell:(unit -> int64) -> write:(bytes -> unit) -> params -> t

Create an encoder

Sourceval process : t -> float array array -> unit

Encode some data

Sourceval finish : t -> unit

Terminate an encoder. Causes the encoder to * flush remaining encoded data. The encoder should * not be used anymore afterwards.

Convenience

Sourceval from_s16le : string -> int -> float array array

Convert S16LE pcm data to an audio array for * encoding WAV and raw PCM to flac.

Sourcemodule File : sig ... end

Encode to a local file