Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_track_aux.h
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 
34 
35 /**@name EST_track_aux.h
36  * EST_Track Auxiliary functions
37  * @author Paul Taylor <pault@cstr.ed.ac.uk>
38  * @version $Id: EST_track_aux.h,v 1.4 2004/05/24 11:15:51 korin Exp $
39  */
40 
41 //@{
42 
43 #ifndef __EST_TRACK_AUX_H__
44 #define __EST_TRACK_AUX_H__
45 
46 #include "EST_FMatrix.h"
47 #include "EST_TList.h"
48 #include "ling_class/EST_Relation.h"
49 #include "EST_Option.h"
50 #include "EST_Track.h"
51 #include "EST_TBuffer.h"
52 
53 void track_smooth(EST_Track &c, float x, EST_String stype = "");
54 void time_med_smooth(EST_Track &c, float x);
55 void time_mean_smooth(EST_Track &c, float x);
56 void simple_med_smooth(EST_Track &c, int n, int channel=0);
57 void simple_mean_smooth(EST_Track &c, int n, int channel=0);
58 
59 /** Calculate the mean absolute error between the same channel in
60  * two tracks. This is given by \[\frac{1}{n}\sum_{i=1}^{n}|a_{i} - b_{i}|\]
61  * @see abs_error, rms_error(EST_Track &a, EST_Track &b)
62  */
63 
64 float abs_error(EST_Track &a, EST_Track &b, int channel);
65 
66 void absolute(EST_Track &tr);
67 void normalise(EST_Track &tr);
68 void normalise(EST_Track &tr, float mean, float sd, int channel,
69  float upper, float lower);
70 void normalise(EST_Track &tr, EST_FVector &mean, EST_FVector &sd,
71  float upper, float lower);
72 void normalise(EST_TrackList &trlist, EST_FVector &mean,
73  EST_FVector &sd, float upper, float lower);
74 
75 /** Calculate the simple derivative of a track. This is given by
76  * \[a_{i+1} - a_{i}\] The values in the resultant track are spaced
77  * midway between the values in the input track, resulting in 1 fewer
78  * frames in the track. This is a very local estimation of the derivative
79  * of the track at a point in time. A smoother value can be obtained
80  * using the delta function.
81  * @see delta
82  */
83 
84 EST_Track differentiate(EST_Track &c, float samp_int=0.0);
85 EST_Track difference(EST_Track &a, EST_Track &b);
86 
87 float mean( const EST_Track &a, int channel );
88 void mean( const EST_Track &a, EST_FVector &m );
89 
90 void meansd(EST_Track &a, float &m, float &sd, int channel);
91 
92 /** Calculate the root mean square error between the same channel in
93  * two tracks. The channel is identified by its index.
94  * @see abs_error, float rms_error(EST_Track &a, EST_Track &b)
95  */
96 float rms_error(EST_Track &a, EST_Track &b, int channel);
97 
98 float correlation(EST_Track &a, EST_Track &b, int channel);
99 
100 void meansd(EST_Track &a, EST_FVector &m, EST_FVector &sd);
101 
102 /** Calculate the root mean square error between each channels in two
103  * tracks. For two tracks of M channels, the result is returned as an
104  * EST_FVector of size M, with element {\it i} representing the
105  * rms error for channel {\it i}.
106  * @see abs_error, rms_error
107  */
108 EST_FVector rms_error(EST_Track &a, EST_Track &b);
109 
110 EST_FVector abs_error(EST_Track &a, EST_Track &b); EST_FVector
111 correlation(EST_Track &a, EST_Track &b);
112 
113 /// Move the start and end variables to the nearest frame.
114 void align_to_track(EST_Track &tr, float &start, float &end);
115 /// Move the start and end variables to the nearest frame.
116 void align_to_track(EST_Track &tr, int &start, int &end, int sample_rate);
117 /// Move the start and end variables to the start and end of the nearest frame.
118 void move_to_frame_ends(EST_Track &tr,
119  int &start, int &end,
120  int sample_rate, float offset=0.0);
121 /// Index of the frame whose start boundary
122 int nearest_boundary(EST_Track &tr, float time, int sample_rate, float offset=0);
123 
124 /// Move the track so that it starts at the indicated time.
125 void set_start(EST_Track &tr, float start);
126 /// Move the track by {\it shift} seconds
127 void move_start(EST_Track &tr, float shift);
128 
129 EST_Track error(EST_Track &ref, EST_Track &test, int relax= 0);
130 void extract(EST_Track &orig, float start, float end, EST_Track &res);
131 
132 int track_divide(EST_TrackList &mtfr, EST_Track &fv, EST_Relation &key);
133 void ParallelTracks(EST_Track &a, EST_TrackList &list,const EST_String &style);
134 void track_info(EST_Track &track);
135 
136 EST_String options_track_filetypes(void);
137 EST_String options_track_filetypes_long(void);
138 EST_String options_subtrack(void);
139 
140 int read_track(EST_Track &tr, const EST_String &in_file, EST_Option &al);
141 
142 /** Return the frame size in {\bf seconds} based on analysis of
143 current time points. This function basically determines the local
144 frame size (shift) by subtracting the current time point from the next
145 time point. If the {\tt prefer_prev} flag is set to {\tt true}, or the
146 index is the last in the track, the size is determined by subtracting
147 the previous time point from the current one.
148 
149 This is most commonly used in pitch synchronous analysis to determine
150 the local pitch period.
151 
152 @see get_frame_size
153 */
154 
155 float get_time_frame_size(EST_Track &pms, int i, int prefer_prev = 0);
156 
157 /** Return the frame size in {\bf samples} based on analysis of
158 current time points. This function basically determines the local
159 frame size (shift) by subtracting the current time point from the next
160 time point. If the {\tt prefer_prev} flag is set to {\tt true}, or the
161 index is the last in the track, the size is determined by subtracting
162 the previous time point from the current one.
163 
164 This is most commonly used in pitch synchronous analysis to determine
165 the local pitch period.
166 
167 @see get_time_frame_size
168 */
169 int get_frame_size(EST_Track &pms, int current_pos, int sample_rate,
170  int prefer_prev=0);
171 
172 
173 /// How many coefficients in track (looks for Coef0 and coefN channels)
174 int get_order(const EST_Track &t, EST_CoefficientType type, int d=0);
175 int get_order(const EST_Track &t);
176 
177 /// Total the length channel values.
178 int sum_lengths(const EST_Track &t,
179  int sample_rate,
180  int start_frame=0, int end_frame=-1);
181 
182 /// Find the start point in the signal of the sections of speech related to each frame.
183 void get_start_positions(const EST_Track &t,
184  int sample_rate,
186 
187 /**@name Analysis frame position
188  * Functions which define which part of a single is associated with a
189  * given frame in a track.
190  * <p>
191  * This is defined here in one place for consistency. They are inline since
192  * they tend to be used in inner loops. There are two versions,
193  * the second for when there are offsets in the track.
194  */
195 //@{
196 
197 /// Get the start and end of a given frame (in samples)
198 static inline void get_frame(const EST_Track &tr, int sample_rate,
199  int f,
200  int &start, int &center, int &end)
201 {
202  center = (int)(tr.t(f)*sample_rate + 0.5);
203  start = center - (int)(tr.a(f, channel_length)/2.0);
204  end = start + (int)(tr.a(f, channel_length));
205 }
206 
207 /// Get the start and end of a given frame (in seconds)
208 static inline void get_frame(const EST_Track &tr, int sample_rate,
209  int f,
210  float &start, float &center, float &end)
211 {
212  center = tr.t(f);
213  start = center - tr.a(f, channel_length)/(float)sample_rate/2.0;
214  end = start + tr.a(f, channel_length)/(float)sample_rate;
215 }
216 
217 /// Get the start and end of a given frame (in samples)
218 static inline void get_frame_o(const EST_Track &tr, int sample_rate,
219  int f,
220  int &start, int &center, int &end)
221 {
222  center = (int)(tr.t(f)*sample_rate + tr.a(f,channel_offset) + 0.5);
223  start = center - (int)(tr.a(f, channel_length)/2.0);
224  end = start + (int)(tr.a(f, channel_length));
225 }
226 
227 /// Get the start and end of a given frame (in seconds)
228 static inline void get_frame_o(const EST_Track &tr, int sample_rate,
229  int f,
230  float &start, float &center, float &end)
231 {
232  center = tr.t(f) + tr.a(f,channel_offset)/(float)sample_rate;
233  start = center - tr.a(f, channel_length)/(float)sample_rate/2.0;
234  end = start + tr.a(f, channel_length)/(float)sample_rate;
235 }
236 
237 //@}
238 
239 // take one of the channels as the timeline
240 void channel_to_time(EST_Track &tr, int channel, float scale=1.0);
241 void channel_to_time(EST_Track &tr, EST_ChannelType c,float scale=1.0);
242 void channel_to_time(EST_Track &tr, const EST_String c_name, float scale=1.0);
243 
244 void channel_to_time_lengths(EST_Track &tr, int channel, float scale=1.0);
245 void channel_to_time_lengths(EST_Track &tr, EST_ChannelType c,float scale=1.0);
246 void channel_to_time_lengths(EST_Track &tr, const EST_String c_name, float scale=1.0);
247 
248 /* Allow EST_Track to be used in an EST_Val */
249 VAL_REGISTER_CLASS_DCLS(track,EST_Track)
250 
251 #endif /* __EST_TRACK_AUX_H__ */
252 //@}