X-Git-Url: https://scm.cri.mines-paristech.fr/git/Faustine.git/blobdiff_plain/a891a827a9bad83d44164ffdd7b28f070c439e46..f59ac471aa5a080301d70e7d7e1e81f34151ba2f:/interpretor/faustio.ml diff --git a/interpretor/faustio.ml b/interpretor/faustio.ml index b05f18d..b9c7598 100644 --- a/interpretor/faustio.ml +++ b/interpretor/faustio.ml @@ -6,6 +6,9 @@ *) open Types;; +open Basic;; +open Value;; +open Signal;; open Beam;; open Aux;; @@ -14,13 +17,10 @@ let default_output_path = "../output_sounds/";; class virtual io = object method virtual read : string array -> beam - method virtual write : int array -> value_type array array -> string array - method private to_float : value_type array array -> float array array = - fun (origin : value_type array array) -> - let data = - let value2float = fun (v : value_type) -> v#to_float_array in - Array.map (Array.map value2float) origin in - Array.map Array.concat (Array.map Array.to_list data) + method virtual write : int array -> float array array array -> string array + method private concat : float array array array -> float array array = + fun (origin : float array array array) -> + Array.map Array.concat (Array.map Array.to_list origin) end;; class waveio : io_type = @@ -34,48 +34,52 @@ class waveio : io_type = else let signals = let files = Array.map Sndfile.openfile paths in - let frames = Array.map Int64.to_int (Array.map Sndfile.frames files) in + let frames = Array.map Int64.to_int + (Array.map Sndfile.frames files) in let rates = Array.map Sndfile.samplerate files in let create_container = fun l -> Array.create l 1. in let containers = Array.map create_container frames in let _ = array_map2 Sndfile.read files containers in let _ = Array.map Sndfile.close files in - array_map2 (new signal) rates containers in + let stream2func = + fun stream -> fun t -> new value (R stream.(t)) in + array_map2 (new signal) rates (Array.map stream2func containers) in new beam signals - method write : int array -> value_type array array -> string array = + method write : int array -> float array array array -> string array = fun (rates : int array) -> - fun (output : value_type array array) -> + fun (output : float array array array) -> let () = print_string(" Faustine -> Writing wave files...") in let tic = Sys.time () in let n = Array.length output in let paths = Array.init n (fun i -> - default_output_path ^ "output" ^ (string_of_int i) ^ ".wav") in + default_output_path ^ "output" ^ (string_of_int (i + 1)) ^ ".wav") in let files = let channels = - let get_channel = fun l -> fun s -> - match s.(l - 1)#get with - | Vec vec -> vec#size - | _ -> 1 in - Array.map (get_channel n) output in - let format = Sndfile.format Sndfile.MAJOR_WAV Sndfile.MINOR_PCM_16 in + let get_channel = fun s -> + let l = Array.length s in + Array.length s.(l - 1) in + Array.map get_channel output in + let file_format = Sndfile.format + Sndfile.MAJOR_WAV Sndfile.MINOR_PCM_16 in let openwr = fun path -> fun channel -> fun rate -> - Sndfile.openfile ~info:(Sndfile.RDWR, format, channel, rate) path in - array_map3 openwr paths channels rates in + Sndfile.openfile ~info:(Sndfile.RDWR, file_format, channel, rate) path in + array_map3 openwr paths channels rates in let () = - let data = self#to_float output in + let data = self#concat output in let _ = array_map2 Sndfile.write files data in let _ = Array.map Sndfile.close files in let toc = Sys.time () in let duration = toc -. tic in - Print_endline + print_endline (" Done. (duration: " ^ (string_of_float duration) ^ "s)") in paths end;; + (* class csvio : io_type = object (self) @@ -89,6 +93,8 @@ class csvio : io_type = end;; *) + +(* let csvread = fun (ic : in_channel) -> let string_list = ref [] in try @@ -103,7 +109,7 @@ let csvread = fun (ic : in_channel) -> let read_input_csv = fun argv -> let n_input = (Array.length argv) - 4 in if n_input < 0 then - raise Missing_Expression + raise (Invalid_argument "xxx") else if n_input = 0 then ([], []) else @@ -161,3 +167,4 @@ let write_output_csv = fun channel_int_list -> fun data_float_array_list -> let toc = Sys.time () in print_endline(" Done. (duration: " ^ (string_of_float (toc -. tic)) ^ "s)");; +*)