Pretty printing of main.ml.
[Faustine.git] / interpretor / main.ml
1 (**
2 Module: Interpreter
3 Description: Input wave -> interpretation -> output wave
4 @author WANG Haisheng
5 Created: 15/05/2013 Modified: 14/08/2013
6 *)
7
8 open Aux;;
9 open Process;;
10 open Faustio;;
11
12 exception Missing_Expression;;
13
14 let time_maximum = 0xFFF;;
15
16 let set_GC () =
17 let _ = Gc.set { (Gc.get())
18 with Gc.minor_heap_size = 0xFFFFFF } in
19 let _ = Gc.set { (Gc.get())
20 with Gc.major_heap_increment = 0xFFFFFF } in
21 let _ = Gc.set { (Gc.get())
22 with Gc.space_overhead = 100 } in
23 let _ = Gc.set { (Gc.get())
24 with Gc.max_overhead = 0xFFFFF } in
25 let _ = Gc.set { (Gc.get())
26 with Gc.stack_limit = 0xFFFFF } in
27 let _ = Gc.set { (Gc.get())
28 with Gc.allocation_policy = 0 } in
29 () ;;
30
31 let has_dsp = ref false;;
32 let path_dsp = ref "";;
33 let num_inwav = ref 0;;
34 let inwavs = ref [];;
35 let num_incsv = ref 0;;
36 let incsvs = ref [];;
37 let outwav = ref false;;
38 let outcsv = ref false;;
39
40 let option_usage = "usage: " ^ Sys.argv.(0)
41 ^ " [-ow] [-oc] [-d string] [-iw string] [-ic string]";;
42
43 let option_unknown =
44 fun x -> raise (Arg.Bad ("Bad argument : " ^ x))
45
46 let speclist = [
47 ("-ow", Arg.Unit (fun () -> outwav := true), ": output wave files");
48 ("-oc", Arg.Unit (fun () -> outcsv := true), ": output csv files");
49 ("-d", Arg.String (fun s -> has_dsp := true;
50 path_dsp := s), ": set dsp source file");
51 ("-iw", Arg.String (fun s -> incr num_inwav;
52 inwavs := !inwavs @ [s]), ": set input wave file");
53 ("-ic", Arg.String (fun s -> incr num_incsv;
54 incsvs := !incsvs @ [s]), ": set input csv file");
55 ];;
56
57
58 let main () =
59
60 (* ignore system alarm clock *)
61 let _ = Sys.signal Sys.sigalrm Sys.Signal_ignore in
62 let _ = set_GC () in
63 let () = Arg.parse speclist option_unknown option_usage in
64
65
66 let () = print_string(" Faustine -> Reading input files...") in
67 let tic0 = Sys.time () in
68 let wave = new waveio in
69 let csv = new csvio in
70 let input_wave = wave#read (Array.of_list !inwavs) in
71 let input_csv = csv#read (Array.of_list !incsvs) in
72 let input = input_wave#append input_csv in
73 let toc0 = Sys.time () in
74 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc0 -. tic0)) ^ "s.)") in
75
76
77 let () = print_string(" Faustine -> Preprocessing...") in
78 let tic1 = Sys.time () in
79 let faust_core = Preprocess.preprocess !path_dsp in
80 let toc1 = Sys.time () in
81 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc1 -. tic1)) ^ "s.)") in
82
83
84 let () = print_string(" Faustine -> Constructing process...") in
85 let tic2 = Sys.time () in
86 let faust_exp = exp_of_string faust_core in
87 let proc = (new proc_factory)#make faust_exp in
88 let toc2 = Sys.time () in
89 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc2 -. tic2)) ^ "s.)") in
90
91
92 let () = print_string(" Faustine -> Evaluation...") in
93 let tic3 = Sys.time () in
94 let output = proc#eval input in
95 let toc3 = Sys.time () in
96 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc3 -. tic3)) ^ "s.)") in
97
98
99
100 let data = output#output time_maximum in
101 let rates = output#frequency in
102
103 let output_wave_paths = wave#write rates data in
104 let output_csv_paths = csv#write rates data in
105 let _ = Array.map print_endline
106 (Array.map decorate output_wave_paths) in
107 let _ = Array.map print_endline
108 (Array.map decorate output_csv_paths) in
109 ();;
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 (*
126 try
127 (* preprocess *)
128 let dsp_file_route_string = (io_macro_to_string Dsp_Route_string) ^ Sys.argv.(3) in
129 let () = print_string(" Faustine -> Preprocessing...") in
130 let tic = Sys.time () in
131 let exp_string = Preprocess.preprocess(dsp_file_route_string) in
132 let toc = Sys.time () in
133 let () = print_endline(" Done. (duration: " ^
134 (string_of_float (toc -. tic)) ^ "s)") in
135
136 (* parsing *)
137 let exp_faust = exp_of_string exp_string in
138
139 (* interpretation *)
140 let (output_channel_list, output_rate_list, output_float_array_list) =
141 interpreter exp_faust (input_rate_list, input_float_array_list) in
142
143 (* make output wave files *)
144 if option_out = "-wav" then
145 write_output_wave output_channel_list output_rate_list output_float_array_list
146 else if option_out = "-csv" then
147 write_output_csv output_channel_list output_float_array_list
148 else raise (Invalid_argument ("Unkown option: " ^ option_out))
149
150 with NotYetDone ->
151 print_endline("Operation not yet programed..");;
152
153 *)
154
155 main();;
156