Update .gitignore for the corrected name interpreter.
[Faustine.git] / interpreter / 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 version = "Faustine: 0.0.1";;
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 = 0xFFF } 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 = 1 } in
29 () ;;
30
31 let path_dsp = ref "";;
32 let size_input = ref 0;;
33 let inputs = ref [];;
34 let time_max = ref 0xFFFF;;
35 let dir_output = ref "";;
36 let format_output = ref "wav";;
37 let basename_output = ref "output";;
38
39 let option_usage = "usage: " ^ Sys.argv.(0)
40 ^ " [-d dsp_src] [-i input] [-t time] [--odir dir] [--oformat wav/csv] [--obasename name]";;
41
42 let option_unknown =
43 fun x -> raise (Arg.Bad ("Bad argument : " ^ x))
44
45 let speclist = [
46 ("-d", Arg.String (fun s -> path_dsp := s), ": set dsp source file");
47 ("-i", Arg.String (fun s -> incr size_input; inputs := !inputs @ [s]), ": set input wave file");
48 ("-t", Arg.Int (fun i -> time_max := i), ": set max output length");
49 ("--odir", Arg.String (fun s -> dir_output := s), ": set output directory");
50 ("--oformat", Arg.String (fun s -> format_output := s), ": set output format");
51 ("--obasename", Arg.String (fun s -> basename_output := s), ": set output basename");
52 ];;
53
54
55 let main () =
56
57 let () = Arg.parse speclist option_unknown option_usage in
58 let _ = Sys.signal Sys.sigalrm Sys.Signal_ignore in
59 let _ = set_GC () in
60 let io = new iomanager in
61 let () = io#set !dir_output !format_output !basename_output in
62
63
64 let () = print_string(" Faustine -> Reading input ...") in
65 let tic0 = Sys.time () in
66 let input = io#read !inputs in
67 let toc0 = Sys.time () in
68 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc0 -. tic0)) ^ "s.)") in
69
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 -> Constructing process...") 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 () = print_string(" Faustine -> Evaluating...") in
87 let tic3 = Sys.time () in
88 let output = proc#eval input in
89 let toc3 = Sys.time () in
90 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc3 -. tic3)) ^ "s.)") in
91
92
93 let () = print_string(" Faustine -> Calculating...") in
94 let tic4 = Sys.time () in
95 let data = output#output !time_max in
96 let rates = output#frequency in
97 let toc4 = Sys.time () in
98 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc4 -. tic4)) ^ "s.)") in
99
100
101 let () = print_string(" Faustine -> Writing output...") in
102 let tic5 = Sys.time () in
103 let output_paths = io#write rates data in
104 let toc5 = Sys.time () in
105 let () = print_endline(" Done. (duration: " ^ (string_of_float (toc5 -. tic5)) ^ "s.)") in
106
107 let _ = Array.map print_endline
108 (Array.map decorate output_paths) in
109 ();;
110
111 main();;
112