Source

chirp / chirp.ml

Full commit
module Sample = struct
  type t
  external load : string -> t = "sdl_load_wav"
  external set_volume : t -> int -> unit = "sdl_set_wav_volume"
end

external init : unit -> unit = "sdl_init"
external allocate_channels : int -> unit = "sdl_allocate_channels"
external set_volume : int -> int -> unit = "sdl_set_channel_volume"
external play_channel_raw : int -> Sample.t -> int -> unit = "sdl_play_channel"
external play_channel_fade_in_raw : int -> Sample.t -> int -> int -> unit =
  "sdl_play_channel_fade_in"

let play channel ?(repeat=0) sample = play_channel_raw channel sample repeat

let play_fade_in channel ?(repeat=0) sample fade_ms =
  play_channel_fade_in_raw channel sample repeat fade_ms
;;

let () =
  init ();
  allocate_channels 16;
  let sample1 = Sample.load "foo.wav" in
  let sample2 = Sample.load "foo.wav" in
  let sample3 = Sample.load "foo.wav" in
  let sample4 = Sample.load "foo.wav" in
  play 1 ~repeat:5 sample1;
  play 2 ~repeat:5 sample2;
  play 3 ~repeat:5 sample3;
  play 4 ~repeat:5 sample4;