From: WANG Date: Wed, 31 Jul 2013 17:34:00 +0000 (+0200) Subject: Refactoring of file beam.ml. X-Git-Url: https://svn.cri.ensmp.fr/git/Faustine.git/commitdiff_plain/14e4f8cd6102d273c520c2d2e0168a5221a7daeb?ds=inline Refactoring of file beam.ml. --- diff --git a/interpretor/beam.ml b/interpretor/beam.ml index 33fb08e..cf5c003 100644 --- a/interpretor/beam.ml +++ b/interpretor/beam.ml @@ -7,17 +7,16 @@ exception Beam_matching of string;; +open Types;; open Signal;; class beam : signal_type array -> beam_type = - fun (sa_init : signal_type array) -> + fun (signals_init : signal_type array) -> object (self) - val sa = sa_init - val l = Array.length sa + val signals = signals_init - method get = sa - - method length = l + method get = signals + method length = Array.length signals method sub : int -> int -> beam_type = fun start -> @@ -25,17 +24,46 @@ class beam : signal_type array -> beam_type = new beam (Array.sub self#get start len) method append : beam_type -> beam_type = - fun b -> - new beam (Array.append self#get b) + fun (b : beam_type) -> + new beam (Array.append self#get b#get) + + method private add_memory : int -> unit = + fun (window : int) -> + let signal_add_memory : int -> signal_type -> unit = + fun (l : int) -> + fun (s : signal) -> + s#add_memory l in + let _ = Array.map (signal_add_memory window) self#get in () - method matching : int -> beam_type + method matching : int -> beam_type = fun size -> - if size = self#length then self - else if size > self#length && size mod self#length = 0 then - - else if size < self#length && self#length mod size = 0 then - + if size = self#length then new beam self#get + + else if (size > self#length) && (size mod self#length = 0) then + let () = self#add_memory 1 in + let split_signals = + Array.concat (Array.to_list + (Array.make (size/self#length) self#get)) in + new beam split_signals + + else if (size < self#length) && (self#length mod size = 0) then + let rec merge_rec = + fun (sa : signal_type array) -> + fun (l : int) -> + fun (i : int) -> + if i + l < Array.length sa then + (sa.(i))#add (merge_rec sa l (i + l)) + else sa.(i) in + let merge_signals = Array.init size (merge_rec self#get size) in + new beam merge_signals + else raise (Beam_matching "matching size error") + method time : time -> value_type array = + fun t -> + let signal_at = fun (t : time) -> fun (s : signal_type) -> s#at t in + Array.map (signal_at t) self#get + method output : int -> (int list) * (float array list) = + end diff --git a/interpretor/faust-0.9.47mr3/compiler/faust b/interpretor/faust-0.9.47mr3/compiler/faust index 76dd708..59c114e 100755 Binary files a/interpretor/faust-0.9.47mr3/compiler/faust and b/interpretor/faust-0.9.47mr3/compiler/faust differ diff --git a/interpretor/faust-0.9.47mr3/compiler/preprocess.a b/interpretor/faust-0.9.47mr3/compiler/preprocess.a index 6cb02ae..023801b 100644 Binary files a/interpretor/faust-0.9.47mr3/compiler/preprocess.a and b/interpretor/faust-0.9.47mr3/compiler/preprocess.a differ diff --git a/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.cpp b/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.cpp index 572d831..f74de94 100644 --- a/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.cpp +++ b/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.cpp @@ -529,12 +529,12 @@ char* preProcess (char* file_route) // Karim Barkati: printing globals value //list faustGlobals = { - cout << "gFaustSuperSuperDirectory = " << gFaustSuperSuperDirectory << endl; - cout << "gFaustSuperDirectory = " << gFaustSuperDirectory << endl; - cout << "gFaustDirectory = " << gFaustDirectory << endl; - cout << "gMasterDocument = " << gMasterDocument << endl; - cout << "gMasterDirectory = " << gMasterDirectory << endl; - cout << "gMasterName = " << gMasterName << endl; + //cout << "gFaustSuperSuperDirectory = " << gFaustSuperSuperDirectory << endl; + //cout << "gFaustSuperDirectory = " << gFaustSuperDirectory << endl; + //cout << "gFaustDirectory = " << gFaustDirectory << endl; + //cout << "gMasterDocument = " << gMasterDocument << endl; + //cout << "gMasterDirectory = " << gMasterDirectory << endl; + //cout << "gMasterName = " << gMasterName << endl; return result_char; } diff --git a/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.o b/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.o index be9b323..0c97dae 100644 Binary files a/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.o and b/interpretor/faust-0.9.47mr3/compiler/preprocess/preprocess.o differ diff --git a/interpretor/interpreter.ml b/interpretor/interpreter.ml index 4f0e1ba..226fadf 100644 --- a/interpretor/interpreter.ml +++ b/interpretor/interpreter.ml @@ -26,7 +26,7 @@ type interpreter_macro = (** val interpreter_macro_to_value : returns the value associated with the macro.*) let interpreter_macro_to_value m = match m with - | Number_samples_int -> 0xFF + | Number_samples_int -> 0xFFFFF | Max_Eval_Time_int -> 0xFFFFFFFF;; @@ -55,7 +55,6 @@ let computing = fun f -> fun width -> fun length -> <- (Array.map convert_back_R (f (!index))); incr index; done; - let () = print_string ("Done.") in !container_float_array_array_array with x -> @@ -67,9 +66,9 @@ let computing = fun f -> fun width -> fun length -> |Beam_Matching_Error s -> "Beam_Matching_Error: " ^ s |Evaluation_Error s -> "Evaluation_Error: " ^ s |NotYetDone -> "NotYetDone" - |_ -> "Done." + |_ -> "Compute finished." in - let () = print_string error_message in + let () = print_endline error_message in Array.sub (!container_float_array_array_array) 0 !index;; @@ -112,8 +111,7 @@ let arrange = fun float_array_array_array -> fun width -> input: a list of signal functions output: channel number list, data list.*) let compute fun_list = - let () = print_string(" Faustine -> Signals computing... ") in - let tic = Sys.time () in + let () = print_endline("Computing output signals...") in (* arrange input information *) let length = interpreter_macro_to_value Number_samples_int in @@ -128,8 +126,6 @@ let compute fun_list = let channel_array = channels output_float_array_array_array width in let channel_list = Array.to_list channel_array in let output_float_array_list = arrange output_float_array_array_array width in - let toc = Sys.time () in - let () = print_endline(" (duration: " ^ (string_of_float (toc -. tic)) ^ "s)") in (channel_list, output_float_array_list);; @@ -218,18 +214,6 @@ let interpret_ident = fun s -> fun input_beam -> |Sin -> if n = 1 then [signal_sin (List.nth input_beam 0)] else raise (Evaluation_Error "Ident sin") - |Cos -> if n = 1 then [signal_cos (List.nth input_beam 0)] - else raise (Evaluation_Error "Ident cos") - - |Atan -> if n = 1 then [signal_atan (List.nth input_beam 0)] - else raise (Evaluation_Error "Ident atan") - - |Atantwo -> if n = 2 then [signal_atantwo (List.nth input_beam 0) (List.nth input_beam 1)] - else raise (Evaluation_Error "Ident atantwo") - - |Sqrt -> if n = 1 then [signal_sqrt (List.nth input_beam 0)] - else raise (Evaluation_Error "Ident sqrt") - |Rdtable -> if n = 3 then [signal_rdtable (List.nth input_beam 0) (List.nth input_beam 1) (List.nth input_beam 2)] else raise (Evaluation_Error "Ident rdtable") @@ -494,8 +478,7 @@ let extract_rate = fun beam -> input: faust expression, sample rate list * input data list output: channel list * sample rate list * output data list.*) let interpreter exp_faust input = - let () = print_string(" Faustine -> Interpretation...") in - let tic = Sys.time () in + let () = print_endline("Interpretation...") in (* make input beam *) let input_beam = make_beam input in @@ -505,8 +488,6 @@ let interpreter exp_faust input = (* interprete output beam *) let output_beam = eval exp_faust dimension_tree input_beam in - let toc = Sys.time () in - let () = print_endline(" Done. (duration: " ^ (string_of_float (toc -. tic)) ^ "s)") in (* get rate list from output beam *) let rate_list = extract_rate output_beam in diff --git a/interpretor/parser.ml b/interpretor/parser.ml index feec7e2..1d2850c 100644 --- a/interpretor/parser.ml +++ b/interpretor/parser.ml @@ -1,6 +1,6 @@ type token = | CONST of (string) - | IDENT of (string) + | IDENT of (Types.symbol) | LPAR | RPAR | SEQ @@ -188,10 +188,10 @@ let yyact = [| # 189 "parser.ml" : 'faust_exp)) ; (fun __caml_parser_env -> - let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in + let _1 = (Parsing.peek_val __caml_parser_env 0 : Types.symbol) in Obj.repr( # 20 "parser.mly" - ( Ident(symbol_of_string _1) ) + ( Ident(_1) ) # 196 "parser.ml" : 'faust_exp)) ; (fun __caml_parser_env -> diff --git a/interpretor/parser.mly b/interpretor/parser.mly index a9b470e..9e9b151 100644 --- a/interpretor/parser.mly +++ b/interpretor/parser.mly @@ -3,7 +3,7 @@ %} %token CONST -%token IDENT +%token IDENT %token LPAR RPAR SEQ SPLIT MERGE PAR REC EOF POINT %right SPLIT MERGE %right SEQ @@ -17,7 +17,7 @@ main: faust_exp EOF { $1 }; faust_exp: CONST { Const(N (int_of_string $1)) } | CONST POINT { Const(R (float_of_string $1)) } | CONST POINT CONST { Const(R (float_of_string ($1 ^ "." ^ $3))) } - | IDENT { Ident(symbol_of_string $1) } + | IDENT { Ident($1) } | LPAR faust_exp RPAR { $2 } | faust_exp PAR faust_exp { Par($1,$3) } | faust_exp SPLIT faust_exp { Split($1,$3) } diff --git a/interpretor/signal.ml b/interpretor/signal.ml index b493b6c..b8f0e68 100644 --- a/interpretor/signal.ml +++ b/interpretor/signal.ml @@ -32,7 +32,7 @@ class signal : int -> (time -> value_type) -> signal_type = else raise (Signal_operation "frequency not matched.") in List.fold_left check self#frequency sl - method private add_memory : int -> unit = + method add_memory : int -> unit = fun (length : int) -> assert (length >= 0); if memory_length >= length then () diff --git a/interpretor/types.ml b/interpretor/types.ml index ba61990..d117836 100644 --- a/interpretor/types.ml +++ b/interpretor/types.ml @@ -86,6 +86,7 @@ class type signal_type = object method frequency : int method at : time -> value_type + method add_memory : int -> unit method add : signal_type -> signal_type method neg : signal_type method sub : signal_type -> signal_type @@ -116,12 +117,13 @@ class type signal_type = class type beam_type = object + method get : signal_type array method length : int - method sub : start: int -> length: int -> beam_type + method sub : int -> int -> beam_type method append : beam_type -> beam_type - method matching : size: int -> beam_type - method time : time -> basic list - method output : length: int -> (int list) * (float array list) + method matching : int -> beam_type + method time : time -> value_type array + method output : int -> (int list) * (float array list) end;;