X-Git-Url: https://scm.cri.mines-paristech.fr/git/Faustine.git/blobdiff_plain/8c48d01c4b78dba6159c13438b06cb7e07a1f338..6150323d86c4feb54bc8e994f7a4e52c3b34c6ec:/interpretor/faustio.ml?ds=inline diff --git a/interpretor/faustio.ml b/interpretor/faustio.ml index 3094ce9..7df74a6 100644 --- a/interpretor/faustio.ml +++ b/interpretor/faustio.ml @@ -24,13 +24,13 @@ class virtual io = _basename <- basename; _dir <- dir method virtual read : string array -> beam - method virtual write : int array -> float array array array -> string array + method virtual write : rate array -> data -> string array - method private concat : float array array array -> float array array = - fun (origin : float array array array) -> + method private concat : data -> matrix = + fun (origin : data) -> Array.map Array.concat (Array.map Array.to_list origin) - method private channels : float array array array -> int array = + method private channels : data -> int array = fun data -> let get_channel = fun s -> let l = Array.length s in @@ -51,7 +51,12 @@ class waveio : io_type = let files = Array.map Sndfile.openfile paths in let frames = Array.map Int64.to_int (Array.map Sndfile.frames files) in - let rates = Array.map Sndfile.samplerate files in + let make_rate = + fun (denom : int) -> + fun (num : int) -> + new rate num denom in + let nums = Array.map Sndfile.samplerate files in + let rates = Array.map (make_rate 1) nums 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 @@ -61,20 +66,22 @@ class waveio : io_type = array_map2 (new signal) rates (Array.map stream2func containers) in new beam signals - method write : int array -> float array array array -> string array = - fun (rates : int array) -> - fun (output : float array array array) -> + method write : rate array -> data -> string array = + fun (rates : rate array) -> + fun (output : data) -> let n = Array.length output in let paths = Array.init n (fun i -> _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".wav") in + let get_freq = fun (r : rate) -> r#to_int in + let freqs = Array.map get_freq rates in let files = let channels = self#channels 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, file_format, channel, rate) path in - array_map3 openwr paths channels rates in + let openwr = fun path -> fun channel -> fun freq -> + Sndfile.openfile ~info:(Sndfile.RDWR, file_format, channel, freq) path in + array_map3 openwr paths channels freqs in let data = self#concat output in let _ = array_map2 Sndfile.write files data in @@ -106,7 +113,7 @@ class csvio : io_type = let values = let convertor = new value Zero in Array.map (convertor#of_float_array) data in - new signal 0 (Array.get values) + new signal (new rate 0 1) (Array.get values) method read : string array -> beam = fun (paths : string array) -> @@ -114,9 +121,9 @@ class csvio : io_type = let signals = Array.map self#csvread files in new beam signals - method write : int array -> float array array array -> string array = - fun (rates : int array) -> - fun (data : float array array array) -> + method write : rate array -> data -> string array = + fun (rates : rate array) -> + fun (data : data) -> let paths = let n = Array.length data in let path_pattern = fun i -> @@ -178,9 +185,9 @@ class iomanager = wave#set _dir _basename; csv#set _dir _basename - method write : int array -> float array array array -> string array = - fun (rates : int array) -> - fun (data : float array array array) -> + method write : rate array -> data -> string array = + fun (rates : rate array) -> + fun (data : data) -> if _format = "" then raise (Invalid_argument "output format unset.") else if _format = "wav" then