3 Description: beam definition and operations
5 Created: 21/07/2013 Modified: 21/07/2013
8 exception Beam_matching of string;;
16 class beam : signal_type array -> beam_type =
17 fun (signals_init : signal_type array) ->
19 val signals = signals_init
22 method width = Array.length signals
24 method sub : int -> int -> beam_type =
27 new beam (Array.sub self#get start len)
29 method cut : int -> beam_type * beam_type =
30 fun (cut_width : int)->
31 ((self#sub 0 cut_width),(self#sub cut_width (self#width - cut_width)))
33 method append : beam_type -> beam_type =
34 fun (b : beam_type) ->
35 new beam (Array.append self#get b#get)
37 method private add_memory : int -> unit =
39 let signal_add_memory : int -> signal_type -> unit =
43 let _ = Array.map (signal_add_memory window) self#get in ()
45 method matching : int -> beam_type =
47 if size = self#width then new beam self#get
49 else if (size > self#width) && (size mod self#width = 0) then
50 let () = self#add_memory 1 in
52 Array.concat (Array.to_list
53 (Array.make (size/self#width) self#get)) in
54 new beam split_signals
56 else if (size < self#width) && (self#width mod size = 0) then
58 fun (sa : signal_type array) ->
61 if i + l < Array.length sa then
62 (sa.(i))#add (merge_rec sa l (i + l))
64 let merge_signals = Array.init size (merge_rec self#get size) in
65 new beam merge_signals
67 else raise (Beam_matching "matching size error")
69 method at : time -> value_type array =
71 let signal_at = fun (t : time) -> fun (s : signal_type) -> s#at t in
72 Array.map (signal_at t) self#get
74 method output : int -> data =
75 fun (length_max : int) ->
76 let value2float = fun (v : value_type) -> v#to_float_array in
78 let container = Array.make length_max
79 (Array.make self#width init) in
83 while !index < length_max do
84 container.(!index) <- Array.map value2float (self#at !index);
87 transpose self#width container
91 | Invalid_argument s ->
92 transpose self#width (Array.sub container 0 !index)
96 method output_values : int -> raw_data =
97 fun (length_max : int) ->
98 let init = new value (N 0) in
99 let container = Array.make length_max
100 (Array.make self#width init) in
104 while !index < length_max do
105 container.(!index) <- self#at !index;
112 | Invalid_argument s ->
113 Array.sub container 0 !index
117 method frequency : rate_type array =
118 let each_rate : signal -> rate =
120 let rate = s#frequency in
121 if rate#num > 0 then rate
122 else if rate#num = 0 then new rate 44100 1
123 else raise (Beam_matching "frequency error.") in
124 Array.map each_rate self#get