+
+
+class iomanager =
+ object (self)
+ val wave = new waveio
+ val csv = new csvio
+ val mutable _dir = ""
+ 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 read_one : string -> string -> beam_type =
+ fun (format : string) ->
+ fun (path : string) ->
+ if format = "wav" then wave#read [|path|]
+ else if format = "csv" then csv#read [|path|]
+ else raise (Invalid_argument "Unknown format.") in
+ let beams = List.map2 read_one formats paths in
+ let concat : beam_type -> beam_type -> beam_type =
+ 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 write : int array -> float array array array -> string array =
+ fun (rates : int array) ->
+ fun (data : float array array array) ->
+ 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.")
+
+ end;;