Changeset 510
- Timestamp:
- 10/10/07 15:07:10 (1 year ago)
- Files:
-
- ocaml-remix/trunk/Makefile (modified) (1 diff)
- ocaml-remix/trunk/ladspa.ml (modified) (1 diff)
- ocaml-remix/trunk/ladspa_impl.c (modified) (5 diffs)
- ocaml-remix/trunk/ladspa_raw.ml (modified) (1 diff)
- ocaml-remix/trunk/ladspa_raw.mli (modified) (1 diff)
- ocaml-remix/trunk/plugin.ml (modified) (1 diff)
- ocaml-remix/trunk/plugin.mli (modified) (1 diff)
- ocaml-remix/trunk/track_test_sins.ml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ocaml-remix/trunk/Makefile
r508 r510 1 ALL: all 1 ALL: all.opt 2 2 3 3 COMPONENTS = remix time volume sound plugin tone wave envelope transparency \ ocaml-remix/trunk/ladspa.ml
r507 r510 46 46 let out_arr = 47 47 Array.init channels (fun _ -> Ladspa_raw.empty_buffer len) in 48 Ladspa_raw.raw_sound_to_buffers rs out_arr ;48 Ladspa_raw.raw_sound_to_buffers rs out_arr len; 49 49 out_arr 50 50 ) ocaml-remix/trunk/ladspa_impl.c
r507 r510 176 176 } 177 177 178 CAMLprim c_ex_ladspa_raw_sound_to_buffers(value ml_sound, value ml_buffers) { 179 180 CAMLparam2(ml_sound, ml_buffers); 181 182 int length = Wosize_val(ml_sound); 183 int channels = Int_val(ml_buffers); 178 CAMLprim c_ex_ladspa_raw_sound_to_buffers(value ml_sound, value ml_buffers, 179 value ml_length) { 180 181 CAMLparam3(ml_sound, ml_buffers, ml_length); 182 183 int length = Int_val(ml_length); 184 int channels = Wosize_val(ml_buffers); 184 185 int i; 186 187 //printf("copying %d samples into %d channels\n", length, channels); 188 length *= channels; 185 189 186 190 LADSPA_Data **data = malloc(channels * sizeof(LADSPA_Data *)); … … 188 192 for (i = 0; i < channels; i++) { 189 193 value b = (value)Field(ml_buffers, i); 194 //printf("buffer %d is %p\n", i, Field(b, 0)); 190 195 data[i] = (LADSPA_Data *)Field(b, 0); 191 196 } 192 197 198 193 199 for (i = 0; i < length; i++) { 194 200 int v = Int_val(Field(ml_sound, i)); … … 268 274 int size = Int_val(ml_size); 269 275 LADSPA_Data *data = calloc(sizeof(LADSPA_Data), size); 270 276 277 //printf("created buffer of size %d at %p\n", size, data); 278 271 279 CAMLlocal1(block); 272 280 block = alloc(1, Abstract_tag); … … 286 294 int port = Int_val(ml_port); 287 295 296 //printf("connected %p to port %d\n", data, port); 297 288 298 ld->connect_port(h, port, data); 289 299 … … 300 310 long count = Long_val(ml_count); 301 311 312 //printf("running for %d samples\n", count); 313 302 314 ld->run(h, count); 303 315 ocaml-remix/trunk/ladspa_raw.ml
r507 r510 14 14 external activate : plugin -> handle -> unit = "c_ex_ladspa_activate";; 15 15 16 external raw_sound_to_buffers : int array -> buffer array -> unit =16 external raw_sound_to_buffers : int array -> buffer array -> int -> unit = 17 17 "c_ex_ladspa_raw_sound_to_buffers";; 18 18 ocaml-remix/trunk/ladspa_raw.mli
r507 r510 15 15 val activate : plugin -> handle -> unit;; 16 16 17 (* provide sound and output buffer array*)18 val raw_sound_to_buffers : int array -> buffer array -> unit;;17 (* provide sound, output buffer array, and length in samples *) 18 val raw_sound_to_buffers : int array -> buffer array -> int -> unit;; 19 19 20 20 val raw_sound_channel_to_buffer : int array -> int -> int -> buffer -> unit;; ocaml-remix/trunk/plugin.ml
r509 r510 2 2 3 3 let from_sound s = function _ -> s;; 4 5 exception InappropriatePlugin 6 7 let from_ladspa_impl ladspa setup href insound remix extent render_extent = 8 let build_handles _ = 9 let create_f _ = 10 let h = Ladspa_raw.instantiate ladspa (Remix.samplerate remix) in 11 Ladspa_raw.activate ladspa h; 12 setup ladspa h; h in 13 Array.init (Remix.channels remix) create_f in 14 let raw_start, raw_length = Time.extent_to_raw_time remix render_extent in 15 let handles = (match !href with 16 | None -> 17 ( 18 let h = build_handles () in 19 href := Some (h, raw_start + raw_length); 20 h 21 ) 22 | Some (h, t) -> 23 ( 24 if t = raw_start 25 then ( 26 href := Some (h, t + raw_length); 27 h 28 ) else ( 29 let h = build_handles () in 30 href := Some (h, raw_start + raw_length); 31 h 32 ) 33 )) in 34 let ports = Ladspa_raw.port_count ladspa in 35 let rec _portdesc n = 36 if n = ports then [] 37 else (n, Ladspa_raw.port_descriptor ladspa n)::_portdesc (n + 1) in 38 let ports = _portdesc 0 in 39 let inAudioPorts = List.filter (function (a,(b,c)) -> 40 b = Ladspa_raw.Input && c = Ladspa_raw.Audio) ports in 41 let outAudioPorts = List.filter (function (a,(b,c)) -> 42 b = Ladspa_raw.Output && c = Ladspa_raw.Audio) ports in 43 if List.length inAudioPorts = 1 && List.length outAudioPorts = 1 then ( 44 let raw_insound = insound remix extent render_extent in 45 let channels = Remix.channels remix in 46 let buffers = 47 Array.init channels (function _ -> Ladspa_raw.empty_buffer raw_length) in 48 Ladspa_raw.raw_sound_to_buffers raw_insound buffers raw_length; 49 let outbuffers = 50 Array.init channels (function _ -> Ladspa_raw.empty_buffer raw_length) in 51 for i = 0 to (channels - 1) do ( 52 Ladspa_raw.connect_port ladspa handles.(i) (fst (List.hd inAudioPorts)) 53 buffers.(i); 54 Ladspa_raw.connect_port ladspa handles.(i) (fst (List.hd outAudioPorts)) 55 outbuffers.(i); 56 Ladspa_raw.run ladspa handles.(i) raw_length 57 ) done; 58 Ladspa_raw.buffers_to_raw_sound outbuffers raw_length 59 ) else raise InappropriatePlugin;; 60 61 let from_ladspa ladspa setup = 62 let href = ref None in 63 from_ladspa_impl ladspa setup href;; 64 ocaml-remix/trunk/plugin.mli
r509 r510 2 2 3 3 val from_sound : Sound.sound -> plugin;; 4 5 val from_ladspa : Ladspa_raw.plugin -> 6 (Ladspa_raw.plugin -> Ladspa_raw.handle -> unit) -> plugin;; ocaml-remix/trunk/track_test_sins.ml
r508 r510 30 30 Layer.add_plugin layer2 a (Time.Seconds 12.0, Time.Seconds 4.0);; 31 31 32 let set_control_value plugin handle port value = 33 let v = Ladspa_raw.control_value_to_buffer value in 34 Ladspa_raw.connect_port plugin handle port v;; 35 36 let layer3 = Layer.empty();; 37 let ladspa = Ladspa_raw.open_plugin "tap_vibrato:tap_vibrato";; 38 let setup_plugin plugin handle = 39 set_control_value plugin handle 0 5.0; 40 set_control_value plugin handle 1 5.0; 41 set_control_value plugin handle 2 (-90.0); 42 set_control_value plugin handle 3 (0.0); 43 set_control_value plugin handle 4 0.0;; 44 let plugin = Plugin.from_ladspa ladspa setup_plugin;; 45 Layer.add_plugin layer3 plugin (Time.Seconds 2.0, Time.Seconds 7.0);; 46 let trans = Transparency.linear_ramp 1.0 1.0;; 47 Layer.add_transparency layer3 trans (Time.Seconds 0.0, Time.Seconds 2.0);; 48 Layer.add_transparency layer3 trans (Time.Seconds 9.0, Time.Seconds 16.0);; 49 32 50 let track = Track.empty ();; 51 Track.add_layer track layer3;; 33 52 Track.add_layer track layer1;; 34 53 Track.add_layer track layer2;;
