Module Msynth.Stream

Streams.

type sample = float

Type for samples.

The stream monad

type dt = float

Type for time differences.

type 'a t = dt -> 'a

The stream monad.

type 'a stream = 'a t

Alias for the stream monad.

val bind : ('a -> 'b t) -> 'a t -> 'b t

Bind operation of the stream monad.

val apply : ('a -> 'b) t -> 'a t -> 'b t

The stream monad is applicative.

val bind2 : ('a -> 'b -> 'c t) -> 'd t -> 'b t -> 'e t

Bind two arguments.

val bind3 : ('a -> 'b -> 'c -> 'd t) -> 'e t -> 'f t -> 'c t -> 'g t

Bind three arguments.

val bind4 : ('a -> 'b -> 'c -> 'd -> 'e t) -> 'f t -> 'g t -> 'h t -> 'd t -> 'i t

Bind four arguments.

val bind1_2 : ('a -> 'b -> 'c t) -> 'd t -> 'e -> 'c t

Bind the first of two arguments.

val bind_list : ('a list -> 'b t) -> 'c t list -> 'b t

Bind a function taking a list of arguments.

val funct : ('a -> 'b) -> 'a t -> 'b t

Functoriality of the stream monad.

val funct2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

Functoriality in two arguments of the stream monad.

val prod : 'a t -> 'b t -> ('a * 'b) t

Strength of the stream monad.

val dt : float t

Current infinitesimal variation of a stream.

val get : 'a t -> 'a

Current value of a stream (this function might be removed in the future).

module Operations : sig ... end

Notations for usual operations of the stream monad. You usually want to open this module when dealing with streams.

include module type of struct include Operations end

Notations for usual operations of the stream monad. You usually want to open this module when dealing with streams.

val return : 'a -> 'a t

Return.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Bind.

val (>>) : unit t -> 'a t -> 'a t

Bind with unit result.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

Functoriality.

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicativity.

val let* : 'a t -> ('a -> 'b t) -> 'b t

Bind.

val and* : 'a t -> 'b t -> ('a * 'b) t

Strength.

Pure operations

val drop : 'a -> unit t

Forget the result of the stream (this is ignore for streams).

val map : ('a -> 'b) -> 'c -> 'd t

Map a function on every sample of a stream.

val iter : ('a -> unit) -> 'b -> 'c t

Iterate a function on every sample of a stream.

val seq : (unit -> 'a) -> 'b t

Create a stream from a function indicating its value at each call.

val prev : 'a -> 'a0 -> 'a1 t

Value of the stream at previous instant.

val initialize : 'a list -> 'b -> 'c t

Set the first values of a stream. This is useful to allocate the buffers in operators which have some.

val dup : unit -> 'a t -> unit t * ('b -> 'c)

Stream duplication. Once the left part has been evaluated, the right part can be used as many times as wanted. This has to be used if you need to use a stream more than once, in order to avoid each copy asking for a different sample.

val stream_ref : 'a Stdlib.ref -> 'b t

Stream the current value of a reference.

val iterative : (float -> 'a -> 'b) -> 'c -> 'd t

Generate a stream according to dt and previous value.

module StreamList : sig ... end

Operations on lists of streams.

module Event : sig ... end

Event hubs. On those, handlers can be registered and will be called each time a new event is emitted.

Arithmetic

val cst : 'a -> 'b t

Create a constant stream.

val blank : float t

The constantly zero stream.

val bmul : bool -> float -> float t

Multiply a stream by a boolean (interpreted as 0 / 1 for false / true).

val scmul : float -> float t -> float t

Switched multiplication by a constant: if the first is 0, the second stream is not evaluated.

val smulc : float t -> float -> float t
val mul : float -> float -> float t

Multiply two streams.

val amp : float -> float -> float t

Amplify a stream.

val add : float -> float -> float t

Add two streams.

val mix : float list -> float t

Add a list of streams.

val sub : float t -> float t -> float t

Subtract streams.

val clip : float -> float t

Clip a stream in the interval -1., 1..

val soft_clip : float -> float

Softer (and more distorted) version of the clip function.

val octaves : float -> float t

Convert octave numbers to multiplicative coefficient for frequency.

val samples : float -> int t

Number of samples in a given amount of time.

Time

val integrate : ?kind:[< `Euler | `Trapezoidal Euler ] -> ?event:[< `Reset | `Set of float ] Event.t -> ?on_reset:(unit -> unit) -> ?init:float -> ?periodic:bool -> unit -> float -> float t

Integrate a stream.

val now : ?event:[< `Reset | `Set of sample ] Event.t -> unit -> sample t

Current time.

val periodic : ?init:float -> ?on_reset:(unit -> unit) -> unit -> float -> float t

Current time for a periodic function.

val timed : ?tempo:float -> ?loop:bool -> (float * 'a) list -> 'b list t

Create a stream from timed events, supposed to be sorted. If tempo is not specified, time is assumed in seconds (otherwise, in notes).

Control

val activates : unit -> bool -> bool t

When a stream becomes true.

val changes : unit -> bool -> bool t

When a stream changes value.

val zc : unit -> float t -> bool t

Zero-crossing: is true when the stream was negative and becomes positive.

val at : unit -> float -> bool t

Check whether we are at a particular instant.

val after : unit -> sample -> bool t

Check whether we are after a particular instant.

val frequently : unit -> float -> bool t

Generate an event at a given frequency.

val every : unit -> float -> bool t

Generate an event every period of time.

val is_first : unit -> unit -> bool t

Whether this is the first sample of the stream.

val on : (unit -> unit) -> bool -> unit t

Execute an action when a stream is true.

val sample_and_hold : unit -> bool -> 'a -> 'b t

Sample when a condition is true and hold the sample the rest of the time.

val resample : ?mode:[> `Last ] -> float -> 'a t -> 'b t

Resample a source from given sampling rate to master sampling rate. The mode parameter controls the resampling method: `Last means take the last available value.

val on_change : ?first:bool -> ('a -> unit) -> 'b -> 'c t

Execute a function when a stream change its value.

val switch : 'a -> 'b -> bool -> 'c

Switch between two streams depending on a boolean.

val random : unit -> ?min:float -> ?max:float -> float -> float t

Generate a random value at given frequency.

module Sample : sig ... end

Operations with samples as unit time.

Oscillators

module Osc : sig ... end

Oscillators.

include module type of struct include Osc end

Oscillators.

val saw : unit -> float -> sample t
val triangle : unit -> float -> float t
val sine : unit -> float -> sample t
val sine_tabulated : ?freq:float -> unit -> float -> sample t
val square : unit -> ?width:float -> float -> float t
val noise : unit -> float t
val osc : unit -> ?width:float -> [< `Noise | `Saw | `Sine | `Square | `Triangle ] -> float -> float t

Generic oscillator.

val sampler : ?interpolation:[ `Closest ] -> ?freq:float -> 'a array -> float -> 'b t

Play a sample stored in a buffer at various speeds.

module Spectral : sig ... end
val fm : ?carrier:[< `Noise | `Saw | `Sine | `Square | `Triangle Sine ] -> ?modulator:[< `Noise | `Saw | `Sine | `Square | `Triangle Sine ] -> unit -> ?ratio:float -> float -> float -> float t

Frequency modulation synthesis.

val random_zero : unit -> ?attraction:float -> float -> float t
val karplus_strong : ?filter:(sample -> sample t) -> unit -> float -> sample t

Envelopes

module Envelope : sig ... end
val adsr : ?event:[< `Release | `Reset ] Event.t -> ?on_die:(unit -> unit) -> unit -> ?a:float -> ?d:float -> ?s:float -> ?r:float -> ?sustain:bool -> ?release:[< `Exponential | `Linear Linear ] -> unit -> float t
val smooth : ?init:float -> ?kind:[< `Exponential | `Linear Exponential ] -> unit -> float -> float -> float t

Smoothen the stream. This is useful to avoid big jumps in controllers. The parmeter is roughly the time taken to reach the desired value.

Effects

module Filter : sig ... end

Filters.

module Ringbuffer : sig ... end
val delay : unit -> ?dry:float -> ?wet:float -> ?feedback:float -> float -> float -> float t

Delay effect on the stream.

val comb : ?kind:[< `Feedback | `Feedforward Feedback ] -> unit -> float -> float -> sample -> sample t
val schroeder_allpass : unit -> float -> (sample -> sample t) t
val simple_delay : unit -> float -> sample -> sample t

A simple delay with no dry or feedback.

val agc : ?period:float -> ?up:float -> ?down:float -> ?blank:float -> ?target:float -> ?clipping:bool -> unit -> float -> float t

Auto gain control.

module Slicer : sig ... end

Slicers: those regularly mute the stream according to various patterns.

val chorus : unit -> ?wet:float -> float -> sample -> float t

Chorus effect.

val flanger : unit -> float -> ?wet:float -> float -> sample -> float t

Flanger effect.

module Distortion : sig ... end

Distortion effects.

Analysis

val print : ?first:bool -> ?changes:bool -> string -> float -> float t

Print value of stream.

Blink a led on tempo.

val ms : float -> (float -> unit) -> float -> unit t

Power (mean square) of a stream.

val is_blank : float -> float -> float -> bool t

Is a stream blank?

Stereo streams

module Stereo : sig ... end

Operations on stereo streams.

val stereo : 'a -> 'a Stereo.t

Duplicate a mono stream to become a stereo stream.

module B : sig ... end

Binded functions: those operate on streams instead of samples.