Bug of vector wave output error fixed.
[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 Process;;
9 open Faustio;;
10
11 exception Missing_Expression;;
12
13 let time_maximum = 0xFFF;;
14
15 let set_GC () =
16 let _ = Gc.set { (Gc.get())
17 with Gc.minor_heap_size = 0xFFFFFF } in
18 let _ = Gc.set { (Gc.get())
19 with Gc.major_heap_increment = 0xFFFFFF } in
20 let _ = Gc.set { (Gc.get())
21 with Gc.space_overhead = 100 } in
22 let _ = Gc.set { (Gc.get())
23 with Gc.max_overhead = 0xFFFFF } in
24 let _ = Gc.set { (Gc.get())
25 with Gc.stack_limit = 0xFFFFF } in
26 let _ = Gc.set { (Gc.get())
27 with Gc.allocation_policy = 0 } in
28 () ;;
29
30 let has_dsp = ref false;;
31 let path_dsp = ref "";;
32 let num_inwav = ref 0;;
33 let inwavs = ref [];;
34 let num_incsv = ref 0;;
35 let incsvs = ref [];;
36 let outwav = ref false;;
37 let outcsv = ref false;;
38
39 let option_usage = "usage: " ^ Sys.argv.(0)
40 ^ " [-ow] [-oc] [-d string] [-iw string] [-ic string]";;
41
42 let option_unknown =
43 fun x -> raise (Arg.Bad ("Bad argument : " ^ x))
44
45 let speclist = [
46 ("-ow", Arg.Unit (fun () -> outwav := true), ": output wave files");
47 ("-oc", Arg.Unit (fun () -> outcsv := true), ": output csv files");
48 ("-d", Arg.String (fun s -> has_dsp := true;
49 path_dsp := s), ": set dsp source file");
50 ("-iw", Arg.String (fun s -> incr num_inwav;
51 inwavs := !inwavs @ [s]), ": set input wave file");
52 ("-ic", Arg.String (fun s -> incr num_incsv;
53 incsvs := !incsvs @ [s]), ": set input csv file");
54 ];;
55
56
57 let main () =
58
59 (* ignore system alarm clock *)
60 let _ = Sys.signal Sys.sigalrm Sys.Signal_ignore in
61 let _ = set_GC () in
62 let () = Arg.parse speclist option_unknown option_usage in
63
64 let wave = new waveio in
65 let input = wave#read (Array.of_list !inwavs) in
66 let faust_core = Preprocess.preprocess !path_dsp in
67 let faust_exp = exp_of_string faust_core in
68 let proc = (new proc_factory)#make faust_exp in
69 let output = proc#eval input in
70 let data = output#output time_maximum in
71 let rates = output#frequency in
72
73 let output_paths = wave#write rates data in
74 let _ = Array.map print_endline output_paths in
75 ();;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 (*
92 try
93 (* preprocess *)
94 let dsp_file_route_string = (io_macro_to_string Dsp_Route_string) ^ Sys.argv.(3) in
95 let () = print_string(" Faustine -> Preprocessing...") in
96 let tic = Sys.time () in
97 let exp_string = Preprocess.preprocess(dsp_file_route_string) in
98 let toc = Sys.time () in
99 let () = print_endline(" Done. (duration: " ^
100 (string_of_float (toc -. tic)) ^ "s)") in
101
102 (* parsing *)
103 let exp_faust = exp_of_string exp_string in
104
105 (* interpretation *)
106 let (output_channel_list, output_rate_list, output_float_array_list) =
107 interpreter exp_faust (input_rate_list, input_float_array_list) in
108
109 (* make output wave files *)
110 if option_out = "-wav" then
111 write_output_wave output_channel_list output_rate_list output_float_array_list
112 else if option_out = "-csv" then
113 write_output_csv output_channel_list output_float_array_list
114 else raise (Invalid_argument ("Unkown option: " ^ option_out))
115
116 with NotYetDone ->
117 print_endline("Operation not yet programed..");;
118
119 *)
120
121 main();;
122