e214802d12142faa4a187f83b6e4c3c482d06b8a
[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 let wave = new waveio in
66 let csv = new csvio in
67 let input_wave = wave#read (Array.of_list !inwavs) in
68 let input_csv = csv#read (Array.of_list !incsvs) in
69 let input = input_wave#append input_csv in
70
71 let () = print_string(" Faustine -> Preprocessing...") in
72 let tic1 = Sys.time () in
73 let faust_core = Preprocess.preprocess !path_dsp in
74 let toc1 = Sys.time () in
75 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc1 -. tic1)) ^ "s.)") in
76
77
78 let () = print_string(" Faustine -> Interpretation...") in
79 let tic2 = Sys.time () in
80 let faust_exp = exp_of_string faust_core in
81 let proc = (new proc_factory)#make faust_exp in
82 let toc2 = Sys.time () in
83 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc2 -. tic2)) ^ "s.)") in
84
85
86 let output = proc#eval input in
87 let data = output#output time_maximum in
88 let rates = output#frequency in
89
90 let output_wave_paths = wave#write rates data in
91 let output_csv_paths = csv#write rates data in
92 let _ = Array.map print_endline
93 (Array.map decorate output_wave_paths) in
94 let _ = Array.map print_endline
95 (Array.map decorate output_csv_paths) in
96 ();;
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 (*
113 try
114 (* preprocess *)
115 let dsp_file_route_string = (io_macro_to_string Dsp_Route_string) ^ Sys.argv.(3) in
116 let () = print_string(" Faustine -> Preprocessing...") in
117 let tic = Sys.time () in
118 let exp_string = Preprocess.preprocess(dsp_file_route_string) in
119 let toc = Sys.time () in
120 let () = print_endline(" Done. (duration: " ^
121 (string_of_float (toc -. tic)) ^ "s)") in
122
123 (* parsing *)
124 let exp_faust = exp_of_string exp_string in
125
126 (* interpretation *)
127 let (output_channel_list, output_rate_list, output_float_array_list) =
128 interpreter exp_faust (input_rate_list, input_float_array_list) in
129
130 (* make output wave files *)
131 if option_out = "-wav" then
132 write_output_wave output_channel_list output_rate_list output_float_array_list
133 else if option_out = "-csv" then
134 write_output_csv output_channel_list output_float_array_list
135 else raise (Invalid_argument ("Unkown option: " ^ option_out))
136
137 with NotYetDone ->
138 print_endline("Operation not yet programed..");;
139
140 *)
141
142 main();;
143