New Faustine tested by sin.dsp and fft.dsp.
[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_string output_paths in
75 ();;
76
77 (*
78 try
79 (* preprocess *)
80 let dsp_file_route_string = (io_macro_to_string Dsp_Route_string) ^ Sys.argv.(3) in
81 let () = print_string(" Faustine -> Preprocessing...") in
82 let tic = Sys.time () in
83 let exp_string = Preprocess.preprocess(dsp_file_route_string) in
84 let toc = Sys.time () in
85 let () = print_endline(" Done. (duration: " ^
86 (string_of_float (toc -. tic)) ^ "s)") in
87
88 (* parsing *)
89 let exp_faust = exp_of_string exp_string in
90
91 (* interpretation *)
92 let (output_channel_list, output_rate_list, output_float_array_list) =
93 interpreter exp_faust (input_rate_list, input_float_array_list) in
94
95 (* make output wave files *)
96 if option_out = "-wav" then
97 write_output_wave output_channel_list output_rate_list output_float_array_list
98 else if option_out = "-csv" then
99 write_output_csv output_channel_list output_float_array_list
100 else raise (Invalid_argument ("Unkown option: " ^ option_out))
101
102 with NotYetDone ->
103 print_endline("Operation not yet programed..");;
104
105 *)
106
107 main();;
108