From e3449439410ee92986e5ef95fc933813dfa6c67b Mon Sep 17 00:00:00 2001 From: WANG Date: Fri, 27 Sep 2013 17:07:30 +0200 Subject: [PATCH] Bugs fixed for stdin and stdout. --- examples/dilation/Makefile | 8 +++----- examples/dilation/img_write.m | 2 +- examples/primitives/Makefile | 12 +++++------- examples/sinwave/Makefile | 4 ++-- interpreter/aux.ml | 6 ++++++ interpreter/faustio.ml | 35 ++++++++++++++++++----------------- interpreter/main.ml | 2 +- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/examples/dilation/Makefile b/examples/dilation/Makefile index 3d2c6dd..93a2ece 100644 --- a/examples/dilation/Makefile +++ b/examples/dilation/Makefile @@ -2,10 +2,8 @@ SRC = dilation.dsp IMGIN = letter_j.png LINES = 150 -BASENAME = output -FORMAT = csv +CSVOUT = dilation.csv CSVIN = $(IMGIN:.png=.csv) -CSVOUT = $(BASENAME)1.$(FORMAT) IMGOUT = $(SRC:.dsp=.png) all: $(IMGOUT) @@ -14,10 +12,10 @@ $(IMGOUT): $(CSVOUT) octave -qf img_write.m $(CSVOUT): $(SRC) $(CSVIN) - faustine -f $(SRC) -i $(CSVIN) -l $(LINES) --oformat $(FORMAT) --obasename $(BASENAME) + faustine -f $(SRC) -l $(LINES) < $(CSVIN) 1> $@ $(CSVIN): $(IMGIN) octave -qf img_read.m clean:: - rm -f gmon.out $(IMGOUT) $(BASENAME)* + rm -f gmon.out $(IMGOUT) $(CSVOUT) diff --git a/examples/dilation/img_write.m b/examples/dilation/img_write.m index 574f59d..85d5b81 100644 --- a/examples/dilation/img_write.m +++ b/examples/dilation/img_write.m @@ -1,4 +1,4 @@ a = imread('letter_j.png' ); -b = csvread('output1.csv' ); +b = csvread('dilation.csv' ); imwrite(b, 'dilation.png'); diff --git a/examples/primitives/Makefile b/examples/primitives/Makefile index fb73fc3..7494e85 100644 --- a/examples/primitives/Makefile +++ b/examples/primitives/Makefile @@ -2,14 +2,12 @@ EXAMPLE = primitives SRC = $(EXAMPLE).dsp SAMPLES = 30 -BASENAME = output -FORMAT = csv -CSVOUT = $(BASENAME)1.$(FORMAT) +FILEOUT = primitives.csv -all: $(CSVOUT) +all: $(FILEOUT) -$(CSVOUT): $(SRC) - faustine -f $(SRC) -l $(SAMPLES) --oformat $(FORMAT) --obasename $(BASENAME) +$(FILEOUT): $(SRC) + faustine -f $(SRC) -l $(SAMPLES) 1> $@ 2> toto.txt clean:: - rm -f gmon.out output* + rm -f gmon.out $(FILEOUT) diff --git a/examples/sinwave/Makefile b/examples/sinwave/Makefile index 064b7c8..cdd957c 100644 --- a/examples/sinwave/Makefile +++ b/examples/sinwave/Makefile @@ -7,7 +7,7 @@ WAVOUT = $(BASENAME)1.$(FORMAT) all: $(WAVOUT) $(WAVOUT): $(SRC) - faustine -f $< --obasename $(BASENAME) --oformat $(FORMAT) + faustine -f $< > sin.wav clean:: - rm -f gmon.out $(BASENAME)* + rm -f gmon.out $(BASENAME)* *.wav *~ diff --git a/interpreter/aux.ml b/interpreter/aux.ml index 5321349..0564c30 100644 --- a/interpreter/aux.ml +++ b/interpreter/aux.ml @@ -34,3 +34,9 @@ let remainder_float : float -> float -> float = if (abs_float r) > ((abs_float f2) /. 2.) then (if r *. f2 > 0. then (r -. f2) else (r +. f2)) else r;; + +let format_of_file : string -> string = + fun (path : string) -> + let fragments = Str.split (Str.regexp "\.") path in + let n = List.length fragments in + List.nth fragments (n - 1);; diff --git a/interpreter/faustio.ml b/interpreter/faustio.ml index 47e07ce..9539bf3 100644 --- a/interpreter/faustio.ml +++ b/interpreter/faustio.ml @@ -79,7 +79,7 @@ class waveio : io_type = 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")|] + let () = Unix.unlink _filename in [|_filename|] else raise (Faustine_IO_Error ("The process has several output signals, however stdout supports only one output signal. Please remove the '> " ^ _filename ^ "'.")) in @@ -141,7 +141,7 @@ class csvio : io_type = 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")|] + let () = Unix.unlink _filename in [|_filename|] else raise (Faustine_IO_Error ("The process has several output signals, however stdout supports only one output signal. Please remove the '> " ^ _filename ^ "'.")) in @@ -171,15 +171,9 @@ class iomanager = val mutable _format = "" val mutable _basename = "" - method private grab_format : string -> string = - fun (path : string) -> - let fragments = Str.split (Str.regexp "\.") path in - let n = List.length fragments in - List.nth fragments (n - 1) - method read : string list -> beam_type = fun (paths : string list) -> - let formats = List.map self#grab_format paths in + let formats = List.map format_of_file paths in let read_one : string -> string -> beam_type = fun (format : string) -> fun (path : string) -> @@ -206,12 +200,19 @@ class iomanager = method write : rate array -> data -> string array = fun (rates : rate array) -> fun (data : data) -> - if _format = "" then - raise (Invalid_argument "output format unset.") - else if _format = "wav" then - wave#write rates data - else if _format = "csv" then - csv#write rates data - else raise (Invalid_argument "unknown format.") - + if _output_filename = "" then ( + if _format = "" then + raise (Invalid_argument "output format unset.") + else if _format = "wav" then + wave#write rates data + else if _format = "csv" then + csv#write rates data + else raise (Invalid_argument "unknown format.")) + else ( + let format = format_of_file _output_filename in + if format = "wav" then + wave#write rates data + else if format = "csv" then + csv#write rates data + else raise (Invalid_argument ("unknown format" ^ format))) end;; diff --git a/interpreter/main.ml b/interpreter/main.ml index 2f102f3..3c5ef42 100644 --- a/interpreter/main.ml +++ b/interpreter/main.ml @@ -35,7 +35,7 @@ let inputs = ref [];; let time_max = ref 0xFFFF;; let dir_output = ref "";; let format_output = ref "csv";; -let basename_output = ref "output";; +let basename_output = ref "";; let output = ref "";; let option_usage = "usage: " ^ Sys.argv.(0) -- 2.20.1