package samplerate

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

Bindings for libsamplerate library, which is dedicated to changing the sampling rate of audio data. All offsets and sizes are given in number of samples per channel.

  • author Samuel Mimram
type converter =
  1. | Conv_sinc_best_quality
    (*

    This is a bandlimited interpolator derived from the mathematical sinc function and this is the highest quality sinc based converter, providing a worst case Signal-to-Noise Ratio (SNR) of 97 decibels (dB) at a bandwidth of 97%. All three Conv_sinc_* converters are based on the techniques of Julius O. Smith although this code was developed independantly.

    *)
  2. | Conv_sinc_medium_quality
    (*

    This is another bandlimited interpolator much like the previous one. It has an SNR of 97dB and a bandwidth of 90%. The speed of the conversion is much faster than the previous one.

    *)
  3. | Conv_fastest
    (*

    This is the fastest bandlimited interpolator and has an SNR of 97dB and a bandwidth of 80%.

    *)
  4. | Conv_zero_order_hold
    (*

    A Zero Order Hold converter (interpolated value is equal to the last value). The quality is poor but the conversion speed is blindlingly fast.

    *)
  5. | Conv_linear
    (*

    A linear converter. Again the quality is poor, but the conversion speed is blindingly fast.

    *)

Kind of converter.

val get_conv_name : converter -> string

Name of a converter.

val get_conv_descr : converter -> string

Description of a converter.

Simple API

val convert : converter -> int -> float -> float array -> int -> int -> float array

convert converter channels ratio inbuf offset length converts audio data with given number of channels with the given ratio (output samplerate / input samplerate) reading from given buffer starting at given offset, the given number of audio samples (per channel).

Full API

type t

Internal state for a converter.

val create : converter -> int -> t

Create a converter of given kind with given number of channels.

val process : t -> float -> float array -> int -> int -> float array -> int -> int -> int * int

Convert audio data with given state, at given ratio, reading from given buffer at given offset the given number of samples, writing in output buffer starting at offset the given number of samples. Returns the number of samples (per channel) used from input buffer and produced in output buffer.

val process_ba : t -> float -> (float, Stdlib.Bigarray.float32_elt, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> (float, Stdlib.Bigarray.float32_elt, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> int * int

Similar to process but takes bigarrays to store audio data.

val process_alloc : t -> float -> float array -> int -> int -> float array

Similar to process but allocates a new buffer instead of writing in a specified output buffer.

val reset : t -> unit

Reset the state of the encoder.