Module Sdlmixer

Define a new exception for loader errors and register it to be callable from C code.

Exception
exception SDLmixer_exception of string


Types
type format =
 | AUDIO_FORMAT_DEFAULT
 | AUDIO_FORMAT_U8
 | AUDIO_FORMAT_S8
 | AUDIO_FORMAT_U16
 | AUDIO_FORMAT_S16


type fade_status =
 | NO_FADING
 | FADING_OUT
 | FADING_IN


type channels = MONO | STEREO


type chunk

type music

type channel = int

type group = int

type specs =
  { frequency : int;
    format : format;
    channels : int }


val open_audio : int -> format -> channels -> unit

open_audio frequency format channels open the mixer with a certain audio format. frequency could be 8000 11025 22050 44100

chuncksize is 4096
val close_audio : unit -> unit

Close the mixer, halting all playing audio
val query_specs : unit -> specs option

This function returns what the actual audio device parameters are.
Loading and freeing sounds
val loadWAV : string -> chunk 

Load a wave file
val load_string : string -> chunk

Load a wave file of the mixer format from a memory buffer
val load_music : string -> music

Load a music file (.mod .s3m .it .xm)
val free_chunk : chunk -> unit

Free an audio chunk previously loaded
val free_music : music -> unit

Free music previously loaded
Hooks
val set_postmix : (string -> unit) -> unit

Set a function string -> unit that is called after all mixing is performed. This can be used to provide real-time visual display of the audio stream or add a custom mixer filter for the stream data.
val set_music : (string -> unit) -> unit

Add your own music player or additional mixer function.
val set_music_finished : (unit -> unit) -> unit

Add your own callback unit -> unit when the music has finished playing.
Groups and channels
val allocate_channels : int -> int

Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels are stopped. This function returns the new number of allocated channels.
val reserve_channels : int -> int

Reserve the first channels (0 -> n-1) for the application, i.e. don't allocate them dynamically to the next sample if requested with a -1 value below. Returns the number of reserved channels.
val group_channel : channel -> group option -> unit

val group_available : group -> channel

Finds the first available channel in a group of channels
val group_count : group -> int

Returns the number of channels in a group. This is also a subtle way to get the total number of channels when group is -1
val group_oldest : group -> channel

Finds the "oldest" sample playing in a group of channels
val group_newer : group -> channel

Finds the "most recent" (i.e. last) sample playing in a group of channels
Playing
val play_sound : chunk -> unit

Play an audio chunk
val play_channel : channel option -> chunk -> int option -> float option -> channel

play_channel channel chunck loops ticks Play an audio chunk If the specified channel is -1, play on the first free channel. If 'loops' is greater than zero, loop the sound that many times. If 'loops' is -1, loop inifinitely (~65000 times). Returns which channel was used to play the sound.
val play_music : music -> int option -> channel

The same as above, but the sound is played at most 'ticks' milliseconds
val fadein_channel : channel option -> chunk -> int option -> float option -> float option -> channel

fadein_channel channel chunck loops ticks Fade in a channel over "ms" milliseconds, same semantics as the play functions
val fadein_music : music -> int option -> float option -> channel

fadein_music music chunck loops ticks Fade in music over "ms" milliseconds, same semantics as the play functions
Volume control
val volume_channel : channel option -> float

val volume_chunk : chunk -> float

val volume_music : music -> float

Returns the original volume of a specific channel, chunk or music
val setvolume_channel : channel option -> float -> unit

val setvolume_chunk : chunk -> float -> unit

val setvolume_music : music -> float -> unit

Set the volume in the range of 0-128 of a specific channel, chunk or music. If the specified channel is -1, set volume for all channels.
Stopping playing
val halt_channel : channel -> unit

val halt_group : group -> unit

val halt_music : unit -> unit


val expire_channel : channel -> float option -> unit

expire_channel channel ticks Change the expiration delay for a particular channel. The sample will stop playing after the 'ticks' milliseconds have elapsed, or remove the expiration if 'ticks' is -1
val fadeout_channel : channel -> float -> unit

fadeout_channel channel ticks Halt a channel, fading it out progressively till it's silent The ms parameter indicates the number of milliseconds the fading will take.
val fadeout_group : group -> float -> unit

fadeout_group group ticks Halt a group of channel, fading it out progressively till it's silent The ms parameter indicates the number of milliseconds the fading will take.
val fadeout_music : float -> unit

fadeout_music ticks Halt the music, fading it out progressively till it's silent The ms parameter indicates the number of milliseconds the fading will take.
val fading_music : unit -> fade_status

Query the fading status of a music
val fading_channel : channel -> fade_status

Query the fading status of a channel
Pausing / resuming
val pause_channel : channel -> unit

val resume_channel : channel -> unit

val paused_channel : channel -> bool

val pause_music : unit -> unit

val resume_music : unit -> unit

val rewind_music : unit -> unit

val paused_music : unit -> bool

val playing : channel option -> bool

val playing_music : unit -> bool