Changeset 512
- Timestamp:
- 10/23/07 08:07:12 (1 year ago)
- Files:
-
- ocaml-remix/trunk/Makefile (modified) (1 diff)
- ocaml-remix/trunk/continuous_sound_test.ml (added)
- ocaml-remix/trunk/deck.ml (added)
- ocaml-remix/trunk/deck.mli (added)
- ocaml-remix/trunk/envelope.ml (modified) (2 diffs)
- ocaml-remix/trunk/layer.ml (modified) (4 diffs)
- ocaml-remix/trunk/layer.mli (modified) (1 diff)
- ocaml-remix/trunk/layer_test_sins.ml (modified) (1 diff)
- ocaml-remix/trunk/note.ml (added)
- ocaml-remix/trunk/note.mli (added)
- ocaml-remix/trunk/noteUtil.ml (added)
- ocaml-remix/trunk/noteUtil.mli (added)
- ocaml-remix/trunk/sound.ml (modified) (1 diff)
- ocaml-remix/trunk/time.ml (modified) (5 diffs)
- ocaml-remix/trunk/time.mli (modified) (2 diffs)
- ocaml-remix/trunk/track.ml (modified) (5 diffs)
- ocaml-remix/trunk/track.mli (modified) (1 diff)
- ocaml-remix/trunk/track_test_sins.ml (modified) (6 diffs)
- ocaml-remix/trunk/volume.ml (modified) (2 diffs)
- ocaml-remix/trunk/volume.mli (modified) (1 diff)
- ocaml-remix/trunk/wave.ml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ocaml-remix/trunk/Makefile
r510 r512 1 1 ALL: all.opt 2 2 3 COMPONENTS = remix time volume sound plugin tone wave envelope transparency \4 layer track instrument ladspa5 TESTS = sound_test_sin layer_test_sins track_test_sins instrument_test\6 ladspa_test 3 COMPONENTS = remix time volume sound envelope note tone wave transparency \ 4 layer track ladspa deck noteUtil 5 TESTS = sound_test_sin layer_test_sins track_test_sins \ 6 ladspa_test continuous_sound_test 7 7 INCLUDES=-I +extlib 8 8 OBJECTS=extLib unix oss ladspa_raw ocaml-remix/trunk/envelope.ml
r493 r512 5 5 let d = Time.time_to_raw_samples remix d in 6 6 let r = Time.time_to_raw_samples remix r in 7 if length = Time.Forever then 8 Printf.printf "can't create a non-terminating adsr envelope\n"; 7 9 let raw_length = Time.time_to_raw_samples remix length in 8 10 if pos <= a … … 15 17 16 18 let apply envelope sound remix sound_extent render_extent = 17 let (ss, sl) = Time.extent_to_raw_samples remix sound_extentin19 let ss = Time.time_to_raw_samples remix (fst sound_extent) in 18 20 let (rs, rl) = Time.extent_to_raw_samples remix render_extent in 19 21 let raw_envelope = envelope remix sound_extent in ocaml-remix/trunk/layer.ml
r508 r512 1 1 (** a layer consists of a list of sounds with start times and lengths, and 2 2 a transparency list (nb: default transparency is 0.0) *) 3 type layer = {mutable la_ plugins:(Time.extent * Plugin.plugin) list;3 type layer = {mutable la_notes:(Time.extent * Note.note) list; 4 4 mutable la_transparency: 5 5 (Time.extent * Transparency.transparency) list};; … … 7 7 exception OverlappingSounds;; 8 8 9 let empty () = {la_ plugins=[]; la_transparency=[]};;9 let empty () = {la_notes=[]; la_transparency=[]};; 10 10 11 let add_ pluginlayer plugin extent =12 layer.la_ plugins <- (extent, plugin)::layer.la_plugins;;11 let add_note layer plugin extent = 12 layer.la_notes <- (extent, plugin)::layer.la_notes;; 13 13 14 14 let add_transparency layer trans extent = … … 31 31 | [] -> () in 32 32 Printf.printf "layer is:\n"; 33 _print_sounds layer.la_ plugins;33 _print_sounds layer.la_notes; 34 34 _print_transparencies layer.la_transparency;; 35 35 … … 57 57 * <----render----> 58 58 *) 59 let to_ sound layer undersound remix layer_extent (render_start, render_length)=60 let raw_render_start = Time.time_to_raw_time remix render_start in61 let raw_render_length = Time.time_to_raw_time remix render_lengthin59 let to_note layer undersound remix _ render_extent = 60 let (raw_render_start, raw_render_length) = 61 Time.extent_to_raw_time remix render_extent in 62 62 let sound = Array.create (raw_render_length * Remix.channels remix) 0 in 63 63 let rec _layer_to_sound laylist = match laylist with 64 64 | [] -> () 65 | ((start,length),s)::t -> ( 66 let raw_start = Time.time_to_raw_time remix start in 67 let raw_length = Time.time_to_raw_time remix length in 68 if (raw_start + raw_length > raw_render_start) && 69 (raw_render_start + raw_render_length > raw_start) 70 then ( 71 let rs = max raw_start raw_render_start in 72 let rl = (min (raw_render_start + raw_render_length) 73 (raw_start + raw_length)) - rs in 74 let raw_sound = (s undersound) remix (start,length) 75 (Time.Samples rs, Time.Samples rl) in 65 | ((start,length),ss)::t -> ( 66 let (s, l) = Time.overlap remix render_extent (start, length) in 67 let (rs, rl) = Time.extent_to_raw_time remix (s, l) in 68 if rl > 0 then ( 69 let raw_sound = (ss undersound) remix (start, length) (s, l) in 76 70 Array.blit raw_sound 0 sound 77 71 ((rs - raw_render_start) * Remix.channels remix) 78 72 (rl * Remix.channels remix)); 79 73 _layer_to_sound t) in 80 _layer_to_sound layer.la_ plugins;74 _layer_to_sound layer.la_notes; 81 75 sound;; 82 83 ocaml-remix/trunk/layer.mli
r508 r512 4 4 5 5 (** add_sound remix layer sound start length *) 6 val add_ plugin : layer -> Plugin.plugin-> Time.extent -> unit;;6 val add_note : layer -> Note.note -> Time.extent -> unit;; 7 7 8 val to_ sound: layer -> Sound.sound -> Sound.sound;;8 val to_note : layer -> Sound.sound -> Sound.sound;; 9 9 10 10 val add_transparency : layer -> Transparency.transparency -> ocaml-remix/trunk/layer_test_sins.ml
r508 r512 7 7 (Time.Seconds 0.1);; 8 8 9 let a = Plugin.from_sound9 let a = Note.from_sound 10 10 (Envelope.apply e (Wave.sin (Volume.constant 30000.) 440.));; 11 let hi_a = Plugin.from_sound11 let hi_a = Note.from_sound 12 12 (Envelope.apply e (Wave.square (Volume.constant 20000.) 880.));; 13 let e = Plugin.from_sound13 let e = Note.from_sound 14 14 (Envelope.apply e (Wave.tri (Volume.constant 20000.) 660.));; 15 15 16 16 let layer = Layer.empty ();; 17 Layer.add_ pluginlayer a (Time.Seconds 2.0, Time.Seconds 4.0);;18 Layer.add_ pluginlayer hi_a (Time.Seconds 6.0, Time.Seconds 2.0);;19 Layer.add_ pluginlayer e (Time.Seconds 12.0, Time.Seconds 3.0);;17 Layer.add_note layer a (Time.Seconds 2.0, Time.Seconds 4.0);; 18 Layer.add_note layer hi_a (Time.Seconds 6.0, Time.Seconds 2.0);; 19 Layer.add_note layer e (Time.Seconds 12.0, Time.Seconds 3.0);; 20 20 21 21 Layer.print layer;; 22 let sound = Layer.to_ soundlayer Sound.silence;;22 let sound = Layer.to_note layer Sound.silence;; 23 23 24 24 Sound.preview remix sound (Time.Seconds 0.0, Time.Seconds 15.0) ocaml-remix/trunk/sound.ml
r508 r512 35 35 36 36 let preview remix sound sound_extent (start,length) = 37 let raw_start = Time.time_to_raw_time remix start in 38 let raw_inc = Time.time_to_raw_time remix (Time.Seconds 0.2) in 37 39 let dev = Oss.sound_open () in 38 40 Oss.sound_set_parms dev (Remix.channels remix) (Remix.samplerate remix); 39 let raw_start = Time.time_to_raw_time remix start in40 let raw_length = Time.time_to_raw_time remix length in41 let raw_inc = Time.time_to_raw_time remix (Time.Seconds 0.2) in42 41 let t = ref raw_start in 43 while !t < raw_length do ( 42 let cond = 43 ( 44 if length = Time.Forever 45 then (fun a -> true) 46 else ( 47 let raw_length = Time.time_to_raw_time remix length in 48 fun a -> a < raw_length 49 ) 50 ) in 51 while cond !t do ( 44 52 Oss.sound_write dev 45 53 (sound remix sound_extent (Time.Samples !t, Time.Samples raw_inc)); ocaml-remix/trunk/time.ml
r494 r512 6 6 | Samples of int 7 7 | Beats of float 8 | Hertz of float;; 8 | Hertz of float 9 | Forever ;; 9 10 10 11 type raw_extent = raw_time * raw_time;; … … 12 13 (* an extent is a start and a length *) 13 14 type extent = time * time;; 15 16 exception ButHowLongIsForever;; 14 17 15 18 let time_to_raw_time r t = … … 19 22 | Samples i -> i 20 23 | Beats f -> sec_to_sam (f /. (Remix.bpm r) *. 60.) 21 | Hertz f -> sec_to_sam (1. /. f);; 24 | Hertz f -> sec_to_sam (1. /. f) 25 | Forever -> raise ButHowLongIsForever;; 22 26 23 27 let time_to_raw_samples r t = time_to_raw_time r t * Remix.channels r;; … … 29 33 (time_to_raw_samples r s, time_to_raw_samples r l);; 30 34 35 let t_max r a b = Samples (max (time_to_raw_time r a) (time_to_raw_time r b));; 36 let t_min r a b = Samples (min (time_to_raw_time r a) (time_to_raw_time r b));; 37 let t_add r a b = 38 if a = Forever || b = Forever then Forever else 39 Samples ((time_to_raw_time r a) + (time_to_raw_time r b));; 40 let t_sub r a b = 41 if a = Forever then Forever else 42 Samples ((time_to_raw_time r a) - (time_to_raw_time r b));; 43 44 let overlap r (astart, alen) (bstart, blen) = 45 let (s, e) = 46 let start = t_max r astart bstart in 47 if alen = Forever then (start, t_add r bstart blen) 48 else if blen = Forever then (start, t_add r astart alen) 49 else (start, t_min r (t_add r astart alen) (t_add r bstart blen)) in 50 (s, t_sub r e s) 51 31 52 let to_string time = 32 53 match time with … … 35 56 | Beats b -> Printf.sprintf "%f beats" b 36 57 | Hertz h -> Printf.sprintf "%f Hz" h 58 | Forever -> Printf.sprintf "Forever!" ocaml-remix/trunk/time.mli
r488 r512 6 6 | Samples of int 7 7 | Beats of float 8 | Hertz of float;; 8 | Hertz of float 9 | Forever;; 9 10 10 11 type raw_extent = raw_time * raw_time;; … … 19 20 val extent_to_raw_samples : Remix.remix -> extent -> (int * int);; 20 21 22 val overlap : Remix.remix -> extent -> extent -> extent;; 23 21 24 val to_string : time -> string;; ocaml-remix/trunk/track.ml
r508 r512 88 88 * case 3,4,5,6: length=min(trans.end, render.end)-start 89 89 *) 90 let to_ sound trackremix extent (start, length) =90 let to_note track undersound remix extent (start, length) = 91 91 let layers = track.tr_layers in 92 92 let rec _render_at pos remix extent (start, length) = 93 93 maybe_gen_tcache track pos remix; 94 94 let olayer = Layer.empty () in 95 let _add_s_to_out sound raw_start raw_length = Layer.add_ pluginolayer96 ( Plugin.from_sound sound)95 let _add_s_to_out sound raw_start raw_length = Layer.add_note olayer 96 (Note.from_sound sound) 97 97 (Time.Samples raw_start, Time.Samples raw_length) in 98 (*let _add_l_to_out layer = _add_s_to_out (Layer.to_sound layer) in*)99 98 let (layer, pretrans) = layers.(pos) in 100 99 let (translist, _) = strip pretrans in … … 103 102 | [] -> ( 104 103 let sound2 = _render_at (pos + 1) in 105 let sound1 = Layer.to_ soundlayer sound2 in104 let sound1 = Layer.to_note layer sound2 in 106 105 _add_s_to_out sound1 raw_start raw_length 107 106 (*_add_l_to_out layer raw_start raw_length*) … … 112 111 let diff = min (elem.tce_raw_start - raw_start) raw_length in 113 112 let sound2 = _render_at (pos + 1) in 114 let sound1 = Layer.to_ soundlayer sound2 in113 let sound1 = Layer.to_note layer sound2 in 115 114 _add_s_to_out sound1 raw_start diff; 116 115 (* _add_l_to_out layer raw_start diff; *) … … 122 121 let l = (min trans_end render_end) - raw_start in 123 122 let sound2 = _render_at (pos + 1) in 124 let sound1 = (Layer.to_ soundlayer sound2) in123 let sound1 = (Layer.to_note layer sound2) in 125 124 let trans = elem.tce_transparency in 126 125 let ext = (Time.Samples raw_start, Time.Samples l) in … … 133 132 let raw_length = Time.time_to_raw_time remix length in 134 133 _render_at_2 raw_start raw_length translist; 135 Layer.to_ sound olayer Sound.silenceremix extent (start, length) in134 Layer.to_note olayer undersound remix extent (start, length) in 136 135 _render_at 0 remix extent (start,length);; 137 136 ocaml-remix/trunk/track.mli
r488 r512 5 5 val add_layer : track -> Layer.layer -> unit;; 6 6 7 val to_ sound : track-> Sound.sound;;7 val to_note : track -> Sound.sound -> Sound.sound;; ocaml-remix/trunk/track_test_sins.ml
r511 r512 2 2 a period of 100 samples *) 3 3 4 let remix = Remix.create 44000 2 120.;;5 4 let env = Envelope.adsr (Time.Seconds 0.2) (Time.Seconds 0.6) 0.7 6 5 (Time.Seconds 0.1);; … … 8 7 let e = Wave.sin (Volume.constant 20000.) (Tone.note Tone.e 1);; 9 8 let [a; e] = List.map (Envelope.apply env) [a; e];; 10 let [a; e] = List.map Plugin.from_sound [a; e];;9 let [a; e] = List.map Note.from_sound [a; e];; 11 10 12 11 … … 18 17 let trans1 = Transparency.linear_ramp 0.0 1.0;; 19 18 let trans2 = Transparency.linear_ramp 1.0 0.0;; 20 Layer.add_ pluginlayer1 a (Time.Seconds 0.0, Time.Seconds 4.0);;21 Layer.add_ pluginlayer1 a (Time.Seconds 6.0, Time.Seconds 4.0);;22 Layer.add_ pluginlayer1 e (Time.Seconds 11.0, Time.Seconds 4.0);;19 Layer.add_note layer1 a (Time.Seconds 0.0, Time.Seconds 4.0);; 20 Layer.add_note layer1 a (Time.Seconds 6.0, Time.Seconds 4.0);; 21 Layer.add_note layer1 e (Time.Seconds 11.0, Time.Seconds 4.0);; 23 22 24 23 let noise = Ladspa_raw.open_plugin "noise:noise_white";; 25 24 let setup_noise _ = 1.0;; 26 let noise_p = Plugin.from_ladspa noise (Plugin.ladspa_init setup_noise);;27 Layer.add_ pluginlayer1 noise_p (Time.Seconds 4.0, Time.Seconds 2.0);;25 let noise_p = Note.from_ladspa noise (Note.ladspa_init setup_noise);; 26 Layer.add_note layer1 noise_p (Time.Seconds 4.0, Time.Seconds 2.0);; 28 27 29 28 Layer.add_transparency layer1 trans1 (Time.Seconds 0.0, Time.Seconds 4.0);; … … 32 31 33 32 let layer2 = Layer.empty ();; 34 Layer.add_ pluginlayer2 e (Time.Seconds 0.0, Time.Seconds 4.0);;35 Layer.add_ pluginlayer2 e (Time.Seconds 5.0, Time.Seconds 6.0);;36 Layer.add_ pluginlayer2 a (Time.Seconds 12.0, Time.Seconds 4.0);;33 Layer.add_note layer2 e (Time.Seconds 0.0, Time.Seconds 4.0);; 34 Layer.add_note layer2 e (Time.Seconds 5.0, Time.Seconds 6.0);; 35 Layer.add_note layer2 a (Time.Seconds 12.0, Time.Seconds 4.0);; 37 36 38 37 let layer3 = Layer.empty();; … … 43 42 | 2 -> -90.0 44 43 | _ -> 0.0;; 45 let plugin = Plugin.from_ladspa ladspa (Plugin.ladspa_init setup_plugin);;46 Layer.add_ pluginlayer3 plugin (Time.Seconds 2.0, Time.Seconds 7.0);;44 let plugin = Note.from_ladspa ladspa (Note.ladspa_init setup_plugin);; 45 Layer.add_note layer3 plugin (Time.Seconds 2.0, Time.Seconds 7.0);; 47 46 let trans = Transparency.linear_ramp 1.0 1.0;; 48 47 Layer.add_transparency layer3 trans (Time.Seconds 0.0, Time.Seconds 2.0);; … … 54 53 Track.add_layer track layer2;; 55 54 56 let sound = Track.to_ sound track;;55 let sound = Track.to_note track Sound.silence;; 57 56 let extent = (Time.Seconds 0.0, Time.Seconds 16.0);; 58 57 58 let remix = Remix.create 44000 2 120.;; 59 59 Sound.preview remix sound extent extent;; ocaml-remix/trunk/volume.ml
r499 r512 1 type volume = Constant of float | Linear of float * float;; 1 type volume = 2 | Constant of float 3 | Linear of float * float;; 2 4 3 5 exception AmplitudeTooHigh … … 10 12 Linear (s, e);; 11 13 12 let amplitude volume position length = match volume with 14 let amplitude remix volume position length = 15 match volume with 13 16 | Constant v -> v 14 | Linear (s, e) -> 15 (position /. length) *. (e -. s) +. s;; 17 | Linear (s, e) -> ( 18 if length = Time.Forever then 19 Printf.printf "I can't ramp forever\n"; 20 let raw_length = Time.time_to_raw_time remix length in 21 (float_of_int position /. float_of_int raw_length) *. (e -. s) +. s 22 );; ocaml-remix/trunk/volume.mli
r499 r512 3 3 val constant : float -> volume;; 4 4 val ramp : float -> float -> volume;; 5 val amplitude : volume -> float -> float-> float;;5 val amplitude : Remix.remix -> volume -> int -> Time.time -> float;; ocaml-remix/trunk/wave.ml
r499 r512 33 33 let raw_start = Time.time_to_raw_samples remix start in 34 34 let raw_ss = Time.time_to_raw_samples remix ss in 35 let raw_slen = Time.time_to_raw_samples remix slen in36 35 let period = float_of_int (Remix.samplerate remix * Remix.channels remix) 37 36 /. rate in 38 37 let offset = (raw_start - raw_ss) in 39 38 let channels = Remix.channels remix in 40 let vfunc = fun p -> Volume.amplitude volume (float_of_int (p + offset)) 41 (float_of_int raw_slen) in 39 let vfunc = fun p -> Volume.amplitude remix volume (p + offset) slen in 42 40 Array.init raw_length 43 41 (fun p -> generator (vfunc p) period raw_start channels p);;
