From: WANG Date: Thu, 22 Aug 2013 14:31:05 +0000 (+0200) Subject: Options are implemented and fft2d.dsp test success. X-Git-Url: https://scm.cri.mines-paristech.fr/git/Faustine.git/commitdiff_plain/c0ac16bdf3099698bb61bb8183f047381a6c713e?hp=5ffc68ce0ca4af8e3139f8df236b19edae9e4cd5 Options are implemented and fft2d.dsp test success. --- diff --git a/dsp_files/fft.dsp b/dsp_files/fft.dsp index 34a795e..bbe62ad 100644 --- a/dsp_files/fft.dsp +++ b/dsp_files/fft.dsp @@ -7,8 +7,8 @@ import ( "mrfaustlib/complex.lib" ) ; //fft_test(n,m) = _ : overlap(n,m) : fft(n) : stops(n/2), pcplx_moduls(n/2) : nconcat(n/2); fft_test(n,m) = vectorize(n) : fft(n) : pcplx_moduls(n) : nconcat(n); -//process = +, _ : + : fft_test(128); -process = fft_test(128,128); +process = +, _ : + : fft_test(128,128); +//process = fft_test(128,128); //process = (0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7) <: shuffle(8); diff --git a/dsp_files/fft2d-svg/process.svg b/dsp_files/fft2d-svg/process.svg index 407aa9e..5dc643f 100644 --- a/dsp_files/fft2d-svg/process.svg +++ b/dsp_files/fft2d-svg/process.svg @@ -1,7 +1,7 @@ - - - + + + @@ -27,74 +27,76 @@ normalize(256) - - - + + +32 + + + +vectorize + + + + + + + + - -matricize(32)(32) + +lines_fft(32)(32) - - - - - - + + + + + + - -lines_fft(32)(32) + +matrix_transpose(32)(32) - - - - - - + + + + + + - -matrix_transpose(32)(32) + +lines_fftc(32)(32) - - - - - - + + + + + + - -lines_fftc(32)(32) + +matrix_transpose(32)(32) - - - - - - + + + + + + - -matrix_transpose(32)(32) + +norm_out(32)(32) - - - - - - - - -norm_out(32)(32) - - - - + + + - - + + - + process - - + + @@ -109,23 +111,33 @@ + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dsp_files/fft2d.dsp b/dsp_files/fft2d.dsp index 3498eba..870c1e2 100644 --- a/dsp_files/fft2d.dsp +++ b/dsp_files/fft2d.dsp @@ -25,7 +25,8 @@ matrix_pcplx2modul(n, m) = _ <: picks(n) : par(i, n, ( _ <: picks(m) : pcplx_mod matrix_real2pcplx(n, m) = _ <: picks(n) : par(i, n, ( _ <: picks(m) : real2pcplx(m) : nconcat(m))) : nconcat(n); -normalize(n) = _ , n : /; +//normalize(n) = _ , n : /; +normalize(n, m) = _, (m : vectorize(n)) : /; unnormalize(n) = par(i, n, ( _ , GREY_MAX : *)); @@ -39,7 +40,7 @@ output(n, m) = serialize; //fft2d(x, y) = matricize(x, y) : output(x, y); fft2d(x, y) = normalize(GREY_MAX) : matricize(x, y) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : norm_out(x, y); -new_fft2d(x, y) = normalize(GREY_MAX) : vectorize(x) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : norm_out(x, y); +new_fft2d(x, y) = normalize(y, GREY_MAX) : vectorize(x) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : norm_out(x, y); //safer with x=y because tests and zero padding are still to implement //process = fft2d(32,32); diff --git a/interpretor/beam.ml b/interpretor/beam.ml index f9ea667..b66ac2b 100644 --- a/interpretor/beam.ml +++ b/interpretor/beam.ml @@ -72,9 +72,6 @@ class beam : signal_type array -> beam_type = method output : int -> float array array array = fun (length_max : int) -> - let () = print_string(" Faustine -> Calculating...") in - let tic = Sys.time () in - let transpose : 'a array array -> 'a array array = fun matrix -> let get_element = fun i -> fun array -> array.(i) in @@ -91,26 +88,13 @@ class beam : signal_type array -> beam_type = container.(!index) <- Array.map value2float (self#at !index); incr index; done; - let result = transpose container in - let toc = Sys.time () in - let () = print_endline (" Done. (duration: " ^ (string_of_float (toc -. tic)) ^ "s.)") in - result + transpose container with x -> - let error_message = match x with - | Convert_Error s -> "Convert_Error: " ^ s - | Basic_operation s -> "Basic_operation: " ^ s - | Signal_operation s -> "Signal_operation: " ^ s - | Beam_matching s -> "Beam_Matching_Error: " ^ s - | Invalid_argument s -> "" - | _ -> "Unknown error" - in - let () = print_string (error_message) in - let result = transpose (Array.sub container 0 !index) in - let toc = Sys.time () in - let () = print_endline (" Done. (duration: " ^ (string_of_float (toc -. tic)) ^ "s.)") in - result + | Invalid_argument s -> + transpose (Array.sub container 0 !index) + | _ -> raise x method frequency : int array = let each_rate : signal -> int = diff --git a/interpretor/faustine b/interpretor/faustine index 2de8a55..7441928 100755 Binary files a/interpretor/faustine and b/interpretor/faustine differ diff --git a/interpretor/faustio.ml b/interpretor/faustio.ml index dc1ee1d..3094ce9 100644 --- a/interpretor/faustio.ml +++ b/interpretor/faustio.ml @@ -12,16 +12,24 @@ open Signal;; open Beam;; open Aux;; -let default_output_path = "../output_sounds/";; let csv_read_buffer_length = 0xFFFF;; class virtual io = object + val mutable _basename = "" + val mutable _dir = "" + method set : string -> string -> unit = + fun (dir : string) -> + fun (basename : string) -> + _basename <- basename; _dir <- dir + method virtual read : string array -> beam 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) + method private channels : float array array array -> int array = fun data -> let get_channel = fun s -> @@ -56,12 +64,9 @@ class waveio : io_type = method write : int array -> float array array array -> string array = fun (rates : int 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 + 1)) ^ ".wav") in + _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".wav") in let files = let channels = self#channels output in @@ -71,14 +76,9 @@ class waveio : io_type = Sndfile.openfile ~info:(Sndfile.RDWR, file_format, channel, rate) path in array_map3 openwr paths channels rates in - let () = 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 - (" Done. (duration: " ^ (string_of_float duration) ^ "s)") in paths end;; @@ -117,13 +117,10 @@ class csvio : io_type = method write : int array -> float array array array -> string array = fun (rates : int array) -> fun (data : float array array array) -> - let () = print_string(" Faustine -> Writing csv files...") in - let tic = Sys.time () in - let paths = let n = Array.length data in let path_pattern = fun i -> - default_output_path ^ "output" ^ (string_of_int (i + 1)) ^ ".csv" in + _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".csv" in Array.init n path_pattern in let files = Array.map open_out paths in @@ -139,8 +136,57 @@ class csvio : io_type = Array.map signal2string data in let _ = array_map2 output_string files strings in let _ = Array.map close_out files in - let toc = Sys.time () in - let () = print_endline - (" Done. (duration: " ^ (string_of_float (toc -. tic)) ^ "s)") in paths end;; + + +class iomanager = + object (self) + val wave = new waveio + val csv = new csvio + val mutable _dir = "" + val mutable _format = "" + val mutable _basename = "" + + method private grab_format : string -> string = + fun (path : string) -> + let fragments = Str.split (Str.regexp "\.") path in + let n = List.length fragments in + List.nth fragments (n - 1) + + method read : string list -> beam_type = + fun (paths : string list) -> + let formats = List.map self#grab_format paths in + let read_one : string -> string -> beam_type = + fun (format : string) -> + fun (path : string) -> + if format = "wav" then wave#read [|path|] + else if format = "csv" then csv#read [|path|] + else raise (Invalid_argument "Unknown format.") in + let beams = List.map2 read_one formats paths in + let concat : beam_type -> beam_type -> beam_type = + fun b1 -> fun b2 -> b1#append b2 in + List.fold_left concat (new beam [||]) beams + + method set : string -> string -> string -> unit = + fun (dir : string) -> + fun (format : string) -> + fun (basename : string) -> + _dir <- dir; + _format <- format; + _basename <- basename; + 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) -> + if _format = "" then + raise (Invalid_argument "output format unset.") + else if _format = "wav" then + wave#write rates data + else if _format = "csv" then + csv#write rates data + else raise (Invalid_argument "unknown format.") + + end;; diff --git a/interpretor/gmon.out b/interpretor/gmon.out index fd15f7f..5f2e3a6 100644 Binary files a/interpretor/gmon.out and b/interpretor/gmon.out differ diff --git a/interpretor/main.ml b/interpretor/main.ml index ee77898..a99a7a5 100644 --- a/interpretor/main.ml +++ b/interpretor/main.ml @@ -11,7 +11,7 @@ open Faustio;; exception Missing_Expression;; -let time_maximum = 0xFFF;; +let version = "Faustine: 0.0.1";; let set_GC () = let _ = Gc.set { (Gc.get()) @@ -28,48 +28,42 @@ let set_GC () = with Gc.allocation_policy = 0 } in () ;; -let has_dsp = ref false;; let path_dsp = ref "";; -let num_inwav = ref 0;; -let inwavs = ref [];; -let num_incsv = ref 0;; -let incsvs = ref [];; -let outwav = ref false;; -let outcsv = ref false;; - +let size_input = ref 0;; +let inputs = ref [];; +let time_max = ref 0xFFFF;; +let dir_output = ref "../output_sounds/";; +let format_output = ref "wav";; +let basename_output = ref "output";; + let option_usage = "usage: " ^ Sys.argv.(0) - ^ " [-ow] [-oc] [-d string] [-iw string] [-ic string]";; + ^ " [-d dsp_src] [-i input] [-t time] [--odir dir] [--oformat wav/csv] [--obasename name]";; let option_unknown = fun x -> raise (Arg.Bad ("Bad argument : " ^ x)) let speclist = [ - ("-ow", Arg.Unit (fun () -> outwav := true), ": output wave files"); - ("-oc", Arg.Unit (fun () -> outcsv := true), ": output csv files"); - ("-d", Arg.String (fun s -> has_dsp := true; - path_dsp := s), ": set dsp source file"); - ("-iw", Arg.String (fun s -> incr num_inwav; - inwavs := !inwavs @ [s]), ": set input wave file"); - ("-ic", Arg.String (fun s -> incr num_incsv; - incsvs := !incsvs @ [s]), ": set input csv file"); + ("-d", Arg.String (fun s -> path_dsp := s), ": set dsp source file"); + ("-i", Arg.String (fun s -> incr size_input; inputs := !inputs @ [s]), ": set input wave file"); + ("-t", Arg.Int (fun i -> time_max := i), ": set max output length"); + ("--odir", Arg.String (fun s -> dir_output := s), ": set output directory"); + ("--oformat", Arg.String (fun s -> format_output := s), ": set output format"); + ("--obasename", Arg.String (fun s -> basename_output := s), ": set output basename"); ];; let main () = - (* ignore system alarm clock *) + let () = Arg.parse speclist option_unknown option_usage in let _ = Sys.signal Sys.sigalrm Sys.Signal_ignore in let _ = set_GC () in - let () = Arg.parse speclist option_unknown option_usage in + let io = new iomanager in + let () = io#set !dir_output !format_output !basename_output in - let () = print_string(" Faustine -> Reading input files...") in + let () = print_string(" Faustine -> Reading input ...") in let tic0 = Sys.time () in - let wave = new waveio in - let csv = new csvio in - let input_wave = wave#read (Array.of_list !inwavs) in - let input_csv = csv#read (Array.of_list !incsvs) in - let input = input_wave#append input_csv in + let input = io#read !inputs in let toc0 = Sys.time () in let () = print_endline(" Done. (duration: " ^ (string_of_float (toc0 -. tic0)) ^ "s.)") in @@ -89,68 +83,30 @@ let main () = let () = print_endline(" Done. (duration: " ^ (string_of_float (toc2 -. tic2)) ^ "s.)") in - let () = print_string(" Faustine -> Evaluation...") in + let () = print_string(" Faustine -> Evaluating...") in let tic3 = Sys.time () in let output = proc#eval input in let toc3 = Sys.time () in let () = print_endline(" Done. (duration: " ^ (string_of_float (toc3 -. tic3)) ^ "s.)") in - - let data = output#output time_maximum in + let () = print_string(" Faustine -> Calculating...") in + let tic4 = Sys.time () in + let data = output#output !time_max in let rates = output#frequency in - - let output_wave_paths = wave#write rates data in - let output_csv_paths = csv#write rates data in - let _ = Array.map print_endline - (Array.map decorate output_wave_paths) in - let _ = Array.map print_endline - (Array.map decorate output_csv_paths) in - ();; - - - - - - + let toc4 = Sys.time () in + let () = print_endline(" Done. (duration: " ^ (string_of_float (toc4 -. tic4)) ^ "s.)") in + let () = print_string(" Faustine -> Writing output...") in + let tic5 = Sys.time () in + let output_paths = io#write rates data in + let toc5 = Sys.time () in + let () = print_endline(" Done. (duration: " ^ (string_of_float (toc5 -. tic5)) ^ "s.)") in - - - - - - -(* - try - (* preprocess *) - let dsp_file_route_string = (io_macro_to_string Dsp_Route_string) ^ Sys.argv.(3) in - let () = print_string(" Faustine -> Preprocessing...") in - let tic = Sys.time () in - let exp_string = Preprocess.preprocess(dsp_file_route_string) in - let toc = Sys.time () in - let () = print_endline(" Done. (duration: " ^ - (string_of_float (toc -. tic)) ^ "s)") in - - (* parsing *) - let exp_faust = exp_of_string exp_string in - - (* interpretation *) - let (output_channel_list, output_rate_list, output_float_array_list) = - interpreter exp_faust (input_rate_list, input_float_array_list) in - - (* make output wave files *) - if option_out = "-wav" then - write_output_wave output_channel_list output_rate_list output_float_array_list - else if option_out = "-csv" then - write_output_csv output_channel_list output_float_array_list - else raise (Invalid_argument ("Unkown option: " ^ option_out)) - - with NotYetDone -> - print_endline("Operation not yet programed..");; - -*) + let _ = Array.map print_endline + (Array.map decorate output_paths) in + ();; main();; diff --git a/interpretor/types.ml b/interpretor/types.ml index 17dea67..dae188f 100644 --- a/interpretor/types.ml +++ b/interpretor/types.ml @@ -153,6 +153,7 @@ class type process_type = class type io_type = object + method set : string -> string -> unit method read : string array -> beam_type method write : int array -> float array array array -> string array end;;