1 /*************************************************************************/ 2 /* */ 3 /* Centre for Speech Technology Research */ 4 /* (University of Edinburgh, UK) and */ 5 /* Korin Richmond */ 6 /* Copyright (c) 2003 */ 7 /* All Rights Reserved. */ 8 /* */ 9 /* Permission is hereby granted, free of charge, to use and distribute */ 10 /* this software and its documentation without restriction, including */ 11 /* without limitation the rights to use, copy, modify, merge, publish, */ 12 /* distribute, sublicense, and/or sell copies of this work, and to */ 13 /* permit persons to whom this work is furnished to do so, subject to */ 14 /* the following conditions: */ 15 /* */ 16 /* 1. The code must retain the above copyright notice, this list of */ 17 /* conditions and the following disclaimer. */ 18 /* 2. Any modifications must be clearly marked as such. */ 19 /* 3. Original authors' names are not deleted. */ 20 /* 4. The authors' names are not used to endorse or promote products */ 21 /* derived from this software without specific prior written */ 22 /* permission. */ 23 /* */ 24 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */ 25 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ 26 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT */ 27 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */ 28 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ 29 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ 30 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ 31 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ 32 /* THIS SOFTWARE. */ 33 /* */ 34 /*************************************************************************/ 35 /*************************************************************************/ 36 /* */ 37 /* Author : Korin Richmond */ 38 /* Date : 02 June 2003 */ 39 /* ------------------------------------------------------------------- */ 40 /* EST_Track script language interface file */ 41 /* */ 42 /*************************************************************************/ 43 44 %module EST_Track 45 46 %{ 47 #include "EST_Track.h" 48 #include "EST_track_aux.h" 49 %} 50 51 %include "typemaps.i" 52 %include "EST_rw_status.i" 53 54 %import "EST_FVector.i" 55 %include "EST_typemaps.i" 56 57 class EST_Track { 58 59 protected: 60 EST_FMatrix p_values; 61 EST_FVector p_times; 62 EST_CVector p_is_val; 63 64 EST_ValMatrix p_aux; 65 EST_StrVector p_aux_names; 66 67 float p_t_offset; 68 69 EST_TrackMap::P p_map; 70 EST_StrVector p_channel_names; 71 72 bool p_equal_space; 73 bool p_single_break; 74 75 void default_vals(); 76 void default_channel_names(); 77 void clear_arrays(); 78 void pad_breaks(); 79 80 int interp_value(float x, float f); 81 float interp_amp(float x, int c, float f); 82 float estimate_shift(float x); 83 void copy(const EST_Track& a); 84 85 public: 86 // these are static in the EST_Track class, but there's some 87 // problem with segmentation fault... 88 const float default_frame_shift; 89 const int default_sample_rate; 90 91 EST_Track(); 92 EST_Track(const EST_Track &a); 93 EST_Track(int num_frames, int num_channels); 94 ~EST_Track(); 95 96 void resize(int num_frames, int num_channels, bool preserve = 1); 97 98 void set_num_channels(int n, bool preserve = 1); 99 void set_num_frames(int n, bool preserve = 1); 100 101 void set_channel_name(const EST_String &name, int channel); 102 103 // set the name of the auxiliary channel. 104 void set_aux_channel_name(const EST_String &name, int channel); 105 106 // copy everything but data 107 void copy_setup(const EST_Track& a); 108 109 // name of track 110 EST_String name() const; 111 void set_name(const EST_String &n); 112 113 // make "fv" a window to frame "n" in the track. 114 void frame(EST_FVector &fv, int n, int startf=0, int nf=EST_ALL); 115 116 // make "fv" a window to channel "n" in the track. 117 void channel(EST_FVector &cv, int n, int startf=0, int nf=EST_ALL); 118 119 // make "fv" a window to the named channel in the track. 120 void channel(EST_FVector &cv, const char * name, int startf=0, int nf=EST_ALL); 121 122 void sub_track(EST_Track &st, 123 int start_frame=0, 124 int nframes=EST_ALL, 125 int start_chan=0, 126 int nchans=EST_ALL); 127 128 129 void copy_sub_track(EST_Track &st, 130 int start_frame=0, 131 int nframes=EST_ALL, 132 int start_chan=0, 133 int nchans=EST_ALL) const; 134 135 void copy_sub_track_out( EST_Track &st, 136 const EST_FVector& frame_times ) const; 137 138 void copy_sub_track_out( EST_Track &st, 139 const EST_IVector& frame_indices ) const; 140 141 // copy channel "n" into pre-allocated buffer "buf" 142 // void copy_channel_out(int n, float *buf, int offset=0, int nf=EST_ALL) const; 143 144 // copy channel {\tt n} into EST_FVector 145 void copy_channel_out(int n, EST_FVector &f, int offset=0, int nf=EST_ALL) const; 146 147 // copy frame "n" into pre-allocated buffer "buf" 148 // void copy_frame_out(int n, float *buf, int offset=0, int nc=EST_ALL) const; 149 150 // copy frame "n" into EST_FVector "f" 151 void copy_frame_out(int n, EST_FVector &f, int offset=0, int nc=EST_ALL) const; 152 153 // copy "buf" into pre-allocated channel "n" of track 154 // void copy_channel_in(int n, const float *buf, int offset=0, int nf=EST_ALL); 155 156 // copy f into pre-allocated channel n of track */ 157 void copy_channel_in(int n, const EST_FVector &f, int offset=0, int num=EST_ALL); 158 159 // copy channel "buf" into pre-allocated channel "n" of track 160 void copy_channel_in(int c, 161 const EST_Track &from, int from_c, int from_offset=0, 162 int offset=0, int num=EST_ALL); 163 164 // copy "buf" into frame "n" of track 165 // void copy_frame_in(int n, const float *buf, int offset=0, int nc=EST_ALL); 166 167 // copy "f" into frame "n" of track 168 void copy_frame_in(int n, const EST_FVector &f, int offset=0, int nf=EST_ALL); 169 170 // copy from "from" frame into frame "n" of track 171 void copy_frame_in(int i, 172 const EST_Track &from, int from_f, int from_offset=0, 173 int offset=0, int num=EST_ALL); 174 175 // Return the position of channel "name" if it exists,otherwise return -1. 176 int channel_position(const char *name, int offset=0) const; 177 178 bool has_channel(const char *name) const; 179 180 // return amplitude of frame i, channel c. 181 float a(int i, int c=0) const; 182 183 // return amplitude at frame nearest t, channel c. 184 float a(float t, int c=0) const; 185 186 // return time position of frame i 187 float t(int i=0) const; 188 189 // return time of frame i in milli-seconds. 190 float ms_t(int i) const; 191 192 // set frame times to regular intervals of time "t". 193 //void fill_time(float t, int start =1); 194 195 // set frame times to regular intervals of time "t", 196 // begining at time "startt" 197 void fill_time(float t, float startt=0.0); 198 199 // fill times with times of other track 200 void fill_time(EST_Track &t); 201 202 // fill all amplitudes with value "v" 203 void fill(float v); 204 205 // resample track at this frame shift, specified in seconds. 206 void sample(float shift); 207 208 // return an estimation of the frame spacing in seconds. 209 float shift() const; 210 // return time of first value in track 211 float start() const; 212 // return time of last value in track 213 float end() const; 214 215 // EST_read_status load(const EST_String name, float ishift = 0.0, float startt = 0.0); 216 // EST_write_status save(const EST_String name, const EST_String EST_filetype = ""); 217 218 EST_read_status load(const char *name, float ishift = 0.0, float startt = 0.0); 219 EST_write_status save(const char *name, const char* EST_filetype = ""); 220 221 // set frame i to be a break 222 void set_break(int i); 223 224 // set frame i to be a value 225 void set_value(int i); 226 227 // return true if frame i is a value 228 int val(int i) const; 229 230 // return true if frame i is a break track_break(int i)231 int track_break(int i) const { return (p_is_val(i)); } 232 233 /** starting at frame i, return the frame index of the first 234 value frame before i. If frame i is a value, return i */ 235 int prev_non_break(int i) const; 236 237 /** starting at frame i, return the frame index of the first 238 value frame after i. If frame i is a value, return i */ 239 int next_non_break(int i) const; 240 241 int empty() const; 242 243 // return the frame index nearest time t 244 int index(float t) const; 245 246 // return the frame index before time t 247 int index_below(float x) const; 248 249 // return number of frames in track 250 int num_frames() const; 251 252 // return number of frames in track 253 int length() const; 254 255 // return number of channels in track 256 int num_channels() const; 257 258 // return number of auxiliary channels in track 259 int num_aux_channels() const; 260 261 // return true if track has fixed frame spacing 262 bool equal_space() const; 263 264 // return true if track has only single breaks between value sections 265 bool single_break() const; 266 267 void set_equal_space(bool t); 268 void set_single_break(bool t); 269 270 // EST_Track& operator = (const EST_Track& a); 271 // add track at end 272 EST_Track& operator+=(const EST_Track &a); 273 // add track in parallel 274 EST_Track& operator|=(const EST_Track &a); 275 276 EST_read_status load_channel_names(const EST_String name); 277 EST_write_status save_channel_names(const EST_String name); 278 279 const EST_String channel_name(int channel, int strings_override=1) const; 280 281 const EST_String aux_channel_name(int channel) const; 282 }; 283 284 float mean( const EST_Track &tr, int channel ); 285 void mean( const EST_Track &tr, EST_FVector &means ); 286 287 %apply float &OUTPUT { float &m, float &sd }; 288 void meansd( EST_Track &tr, float &m, float &sd, int channel ); 289 %clear float &m, float &sd; 290 291 void meansd( EST_Track &tr, EST_FVector &m, EST_FVector &sd ); 292 293 void normalise( EST_Track &tr ); 294 295 void normalise( EST_Track &tr, float mean, float sd, int channel, 296 float upper, float lower ); 297 298 void normalise( EST_Track &tr, EST_FVector &mean, EST_FVector &sd, 299 float upper, float lower); 300