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