root/ocaml-remix/trunk/envelope.ml

Revision 529, 1.1 kB (checked in by shans, 4 years ago)

Replacing sound implementation - WAS ocaml int arrays, IS native float
arrays. This has not yet been completely been debugged!

Line 
1 type envelope = Remix.remix -> Time.time -> int -> float;;
2
3 let _adsr a d s r raw_length pos =
4   if pos <= a
5   then float_of_int pos /. float_of_int a
6   else if pos <= (a + d)
7   then 1.0 -. (1.0 -. s) *. float_of_int (pos - a) /. float_of_int d
8   else if pos <= raw_length - r
9   then s
10   else s *. float_of_int (raw_length - pos) /. float_of_int r;;
11
12 let adsr length a d s r remix start =
13   let a = Time.time_to_raw_time remix a in
14   let d = Time.time_to_raw_time remix d in
15   let r = Time.time_to_raw_time remix r in
16   if length = Time.Forever then
17     Printf.printf "can't create a non-terminating adsr envelope\n%!";
18   let raw_length = Time.time_to_raw_time remix length in
19   _adsr a d s r raw_length;;
20
21 let apply envelope sound remix sound_start render_extent =
22   let ss = Time.time_to_raw_time remix sound_start in
23   let (rs, rl) = Time.extent_to_raw_time remix render_extent in
24   let raw_envelope = FB.create rl (Remix.channels remix) in
25   let env_func t = envelope remix sound_start (t + rs - ss) in
26   let raw_sound = sound remix sound_start render_extent in
27   FB.fill raw_envelope env_func;
28   FB.mult raw_sound raw_envelope;;
Note: See TracBrowser for help on using the browser.