Tested by examples/sinwave/sin.dsp.
WAV_BASENAME = $(SINSUM:.dsp=)
WAV_FORMAT = wav
WAVIN = $(WAV_BASENAME)1.$(WAV_FORMAT)
-
-INPUT1 = sin_1378Hz_0.005_ampli_128samples.wav
-INPUT2 = sin_2067Hz_0.005_ampli_128samples.wav
-INPUT3 = sin_16536Hz_0.005_ampli_128samples.wav
-INPUT4 = sin_22000Hz_0.005_ampli_128samples.wav
-
+WAV_LENGTH = 128
all: $(IMGOUT)
$(CSVOUT): $(SRC) $(WAVIN)
faustine -f $(SRC) -i $(WAVIN) --oformat $(FORMAT) --obasename $(BASENAME)
-$(WAVIN): $(SINS) $(INPUT1) $(INPUT2) $(INPUT3) $(INPUT4)
- faustine -f $(SINSUM) -i $(INPUT1) -i $(INPUT2) -i $(INPUT3) -i $(INPUT4) --oformat $(WAV_FORMAT) --obasename $(WAV_BASENAME)
+$(WAVIN): $(SINS)
+ faustine -f $(SINSUM) -l $(WAV_LENGTH) --oformat $(WAV_FORMAT) --obasename $(WAV_BASENAME)
clean::
rm -f gmon.out $(CSVOUT) $(IMGOUT) $(WAVIN) *~
-process = +, + : +;
+import("math.lib");
+import("music.lib");
+samplerate = 44100;
+process = (sinwave(1378) + sinwave(2067)) , (sinwave(16536) + sinwave(22000)) : + : /(4) ;
+sinwave(f) = time*(2.0*PI)*f/samplerate : sin;
+
if n1 = n2 && n1 = n3 then Array.init n1 (fun i -> f a.(i) b.(i) c.(i))
else raise (Invalid_argument "Array.map3 size not matched.");;
-let decorate = fun s -> " Faustine -> " ^ s;;
+let decorate = fun s -> " Faustine -> " ^ s ^ "\n";;
let xor : bool -> bool -> bool =
fun a -> fun b -> (a || b) && (not (a && b));;
open Beam;;
open Aux;;
+exception Faustine_IO_Error of string;;
+
let csv_read_buffer_length = 0xFFFF;;
class virtual io =
object
+ val mutable _filename = ""
val mutable _basename = ""
val mutable _dir = ""
- method set : string -> string -> unit =
- fun (dir : string) ->
- fun (basename : string) ->
- _basename <- basename; _dir <- dir
+ method set : string -> string -> string -> unit =
+ fun (filename : string) ->
+ fun (dir : string) ->
+ fun (basename : string) ->
+ _filename <- filename; _basename <- basename; _dir <- dir
method virtual read : string array -> beam
method virtual write : rate array -> data -> string array
fun (rates : rate array) ->
fun (output : data) ->
let n = Array.length output in
- let paths = Array.init n (fun i ->
- _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".wav") in
+ let paths =
+ if _filename = "" then
+ Array.init n (fun i ->
+ _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".wav")
+ else if n = 1 then
+ let () = Unix.unlink "_filename" in [|(_filename ^ ".wav")|]
+ else raise (Faustine_IO_Error ("The process has several output signals,
+ however stdout supports only one output signal. Please remove
+ the '> " ^ _filename ^ "'.")) in
let get_freq = fun (r : rate) -> r#to_int in
let freqs = Array.map get_freq rates in
-
+
let files =
let channels = self#channels output in
let file_format = Sndfile.format
method write : rate array -> data -> string array =
fun (rates : rate array) ->
fun (data : data) ->
+ let n = Array.length data in
let paths =
- let n = Array.length data in
- let path_pattern = fun i ->
- _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".csv" in
- Array.init n path_pattern in
-
+ if _filename = "" then
+ Array.init n (fun i ->
+ _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".csv")
+ else if n = 1 then
+ let () = Unix.unlink _filename in [|(_filename ^ ".csv")|]
+ else raise (Faustine_IO_Error ("The process has several output signals,
+ however stdout supports only one output signal. Please remove
+ the '> " ^ _filename ^ "'.")) in
let files = Array.map open_out paths in
let strings =
let value2string : float array -> string =
object (self)
val wave = new waveio
val csv = new csvio
+ val mutable _output_filename = ""
val mutable _dir = ""
val mutable _format = ""
val mutable _basename = ""
fun b1 -> fun b2 -> b1#append b2 in
List.fold_left concat (new beam [||]) beams
- method set : string -> string -> string -> unit =
- fun (dir : string) ->
- fun (format : string) ->
- fun (basename : string) ->
- _dir <- dir;
- _format <- format;
- _basename <- basename;
- wave#set _dir _basename;
- csv#set _dir _basename
+ method set : string -> string -> string -> string -> unit =
+ fun (filename : string) ->
+ fun (dir : string) ->
+ fun (format : string) ->
+ fun (basename : string) ->
+ _output_filename <- filename;
+ _dir <- dir;
+ _format <- format;
+ _basename <- basename;
+ wave#set _output_filename _dir _basename;
+ csv#set _output_filename _dir _basename
method write : rate array -> data -> string array =
fun (rates : rate array) ->
*)
open Aux;;
+open Beam;;
open Process;;
open Faustio;;
let inputs = ref [];;
let time_max = ref 0xFFFF;;
let dir_output = ref "";;
-let format_output = ref "wav";;
+let format_output = ref "csv";;
let basename_output = ref "output";;
+let output = ref "";;
let option_usage = "usage: " ^ Sys.argv.(0)
^ " [-f dsp_src] [-i input] [-l length] [--odir dir] [--oformat wav/csv] [--obasename name]";;
("--obasename", Arg.String (fun s -> basename_output := s), ": set output basename");
];;
+let file_of_path : string -> string =
+ fun (path : string) ->
+ let fragments = Str.split (Str.regexp "/") path in
+ let n = List.length fragments in
+ List.nth fragments (n - 1);;
+
+let stdinput = fun (x : unit) ->
+ let path = Unix.readlink "/proc/self/fd/0" in
+ if path <> "/dev/pts/4" then
+ ( incr size_input;
+ inputs := !inputs @ [path] )
+ else ();;
+
+let stdoutput = fun (x : unit) ->
+ let path = Unix.readlink "/proc/self/fd/1" in
+ if path <> "/dev/pts/4" then output := path
+ else ();;
+
+let stdio = fun (x : unit) ->
+ stdinput ();
+ stdoutput ();;
let main () =
+
(*
- let () = print_endline (Scanf.Scanning.name_of_input (Scanf.Scanning.stdin)) in
let () = print_endline (Unix.readlink "/proc/self/fd/0") in
let () = print_endline (Unix.readlink "/proc/self/fd/1") in
let () = print_endline (Unix.readlink "/proc/self/fd/2") in
*)
+ let () = stdio () in
let () = Arg.parse speclist option_unknown option_usage in
let _ = Sys.signal Sys.sigalrm Sys.Signal_ignore in
let _ = set_GC () in
let io = new iomanager in
- let () = io#set !dir_output !format_output !basename_output in
+ let () = io#set !output !dir_output !format_output !basename_output in
- let () = print_string(" Faustine -> Reading input ...") in
+ let () = output_string stderr (" Faustine -> Reading input ...") in
let tic0 = Unix.time () in
- let input = io#read !inputs in
+ let input : beam = io#read !inputs in
let toc0 = Unix.time () in
- let () = print_endline(" Done. (duration: " ^ (string_of_float (toc0 -. tic0)) ^ "s.)") in
+ let () = output_string stderr (" Done. (duration: " ^ (string_of_float (toc0 -. tic0)) ^ "s.)\n") in
- let () = print_string(" Faustine -> Preprocessing...") in
+ let () = output_string stderr (" Faustine -> Preprocessing...") in
let tic1 = Unix.time () in
let faust_core = Preprocess.preprocess !path_dsp in
let toc1 = Unix.time () in
- let () = print_endline(" Done. (duration: " ^ (string_of_float (toc1 -. tic1)) ^ "s.)") in
+ let () = output_string stderr (" Done. (duration: " ^ (string_of_float (toc1 -. tic1)) ^ "s.)\n") in
- let () = print_string(" Faustine -> Constructing process...") in
+ let () = output_string stderr (" Faustine -> Constructing process...") in
let tic2 = Unix.time () in
let faust_exp = exp_of_string faust_core in
let proc = (new proc_factory)#make faust_exp in
let toc2 = Unix.time () in
- let () = print_endline(" Done. (duration: " ^ (string_of_float (toc2 -. tic2)) ^ "s.)") in
+ let () = output_string stderr (" Done. (duration: " ^ (string_of_float (toc2 -. tic2)) ^ "s.)\n") in
- let () = print_string(" Faustine -> Constructing signals...") in
+ let () = output_string stderr (" Faustine -> Constructing signals...") in
let tic3 = Unix.time () in
- let output = proc#eval input in
+ let output : beam = proc#eval input in
let toc3 = Unix.time () in
- let () = print_endline(" Done. (duration: " ^ (string_of_float (toc3 -. tic3)) ^ "s.)") in
+ let () = output_string stderr (" Done. (duration: " ^ (string_of_float (toc3 -. tic3)) ^ "s.)\n") in
- let () = print_string(" Faustine -> Evaluating...") in
+ let () = output_string stderr (" Faustine -> Evaluating...") in
let tic4 = Unix.time () in
let data = output#output !time_max in
let rates = output#frequency in
let toc4 = Unix.time () in
- let () = print_endline(" Done. (duration: " ^ (string_of_float (toc4 -. tic4)) ^ "s.)") in
+ let () = output_string stderr (" Done. (duration: " ^ (string_of_float (toc4 -. tic4)) ^ "s.)\n") in
- let () = print_string(" Faustine -> Writing output...") in
+ let () = output_string stderr (" Faustine -> Writing output...") in
let tic5 = Unix.time () in
let output_paths = io#write rates data in
let toc5 = Unix.time () in
- let () = print_endline(" Done. (duration: " ^ (string_of_float (toc5 -. tic5)) ^ "s.)") in
+ let () = output_string stderr (" Done. (duration: " ^ (string_of_float (toc5 -. tic5)) ^ "s.)\n") in
- let _ = Array.map print_endline
+ let _ = Array.map (output_string stderr)
(Array.map decorate output_paths) in
();;
fun i1 -> fun i2 ->
let r = i1 mod i2 in
if r = 0 then i2 else pgcd i2 r in
- let num_positive =
- if num_init >= 0 then num_init
- else (-num_init) in
- let denom_positive =
- if denom_init > 0 then denom_init
- else if denom_init < 0 then -denom_init
- else raise (Signal_operation "sample rate denominater = 0.") in
- let factor = pgcd num_positive denom_positive in
- let num_corrected = num_init / factor in
- let denom_corrected = denom_init / factor in
+ let factor =
+ if denom_init = 0 then
+ raise (Signal_operation "sample rate denominater = 0.")
+ else
+ pgcd (abs num_init) (abs denom_init) in
object (self)
- val _num = num_corrected
- val _denom = denom_corrected
+ val _num = num_init / factor
+ val _denom = denom_init / factor
method num = _num
method denom = _denom
method to_int =
new value (Vec (new vector size vec)) in
new signal freq func
-
method serialize : signal_type =
let size =
match (self#at 0)#get with
class type io_type =
object
- method set : string -> string -> unit
+ method set : string -> string -> string -> unit
method read : string array -> beam_type
method write : rate_type array -> data -> string array
end;;