Edinburgh Speech Tools  2.1-release
EST_track_aux.h
Go to the documentation of this file.
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 /** @defgroup EST_Track_aux_functions EST_Track Auxiliary functions
36  * @author Paul Taylor <pault@cstr.ed.ac.uk>
37  * @version $Id: EST_track_aux.h,v 1.4 2004/05/24 11:15:51 korin Exp $
38  */
39 
40 ///@{
41 
42 #ifndef __EST_TRACK_AUX_H__
43 #define __EST_TRACK_AUX_H__
44 
45 #include "EST_FMatrix.h"
46 #include "EST_TList.h"
48 #include "EST_Option.h"
49 #include "EST_Track.h"
50 #include "EST_TBuffer.h"
51 
52 void track_smooth(EST_Track &c, float x, EST_String stype = "");
53 void time_med_smooth(EST_Track &c, float x);
54 void time_mean_smooth(EST_Track &c, float x);
55 void simple_med_smooth(EST_Track &c, ssize_t n, ssize_t channel=0);
56 void simple_mean_smooth(EST_Track &c, ssize_t n, ssize_t channel=0);
57 
58 /** Calculate the mean absolute error between the same channel in
59  * two tracks. This is given by \f[\frac{1}{n}\sum_{i=1}^{n}|a_{i} - b_{i}|\f]
60  \param a First track
61  \param b Second track
62  \param channel Channel from track for which the error is to be computed
63  \return absolute error
64  * @see abs_error, rms_error(EST_Track &a, EST_Track &b)
65  */
66 float abs_error(EST_Track &a, EST_Track &b, ssize_t channel);
67 
68 void absolute(EST_Track &tr);
69 void normalise(EST_Track &tr);
70 void normalise(EST_Track &tr, float mean, float sd, ssize_t channel,
71  float upper, float lower);
73  float upper, float lower);
74 void normalise(EST_TrackList &trlist, EST_FVector &mean,
75  EST_FVector &sd, float upper, float lower);
76 
77 /** Calculate the simple derivative of a track. This is given by
78  * \f[a_{i+1} - a_{i}\f] The values in the resultant track are spaced
79  * midway between the values in the input track, resulting in 1 fewer
80  * frames in the track. This is a very local estimation of the derivative
81  * of the track at a point in time. A smoother value can be obtained
82  * using the delta function.
83  * @see delta
84  */
85 EST_Track differentiate(EST_Track &c, float samp_int=0.0);
87 
88 float mean( const EST_Track &a, ssize_t channel );
89 void mean( const EST_Track &a, EST_FVector &m );
90 
91 void meansd(EST_Track &a, float &m, float &sd, ssize_t channel);
92 
93 /** Calculate the root mean square error between the same channel in
94  * two tracks. The channel is identified by its index.
95  * @see abs_error, float rms_error(EST_Track &a, EST_Track &b)
96  */
97 float rms_error(EST_Track &a, EST_Track &b, ssize_t channel);
98 
99 float correlation(EST_Track &a, EST_Track &b, ssize_t channel);
100 
101 void meansd(EST_Track &a, EST_FVector &m, EST_FVector &sd);
102 
103 /** Calculate the root mean square error between each channels in two
104  * tracks. For two tracks of M channels, the result is returned as an
105  * EST_FVector of size M, with element *i* representing the
106  * rms error for channel *i*.
107  * @see abs_error, rms_error
108  */
110 
113 
114 /// Move the start and end variables to the nearest frame.
115 void align_to_track(EST_Track &tr, float &start, float &end);
116 /// Move the start and end variables to the nearest frame.
117 void align_to_track(EST_Track &tr, int &start, int &end, int sample_rate);
118 /// Move the start and end variables to the start and end of the nearest frame.
119 void move_to_frame_ends(EST_Track &tr,
120  int &start, int &end,
121  int sample_rate, float offset=0.0);
122 /// Index of the frame whose start boundary
123 int nearest_boundary(EST_Track &tr, float time, int sample_rate, float offset=0);
124 
125 /// Move the track so that it starts at the indicated time.
126 void set_start(EST_Track &tr, float start);
127 /// Move the track by *shift* seconds
128 void move_start(EST_Track &tr, float shift);
129 
130 EST_Track error(EST_Track &ref, EST_Track &test, int relax= 0);
131 void extract(EST_Track &orig, float start, float end, EST_Track &res);
132 
133 int track_divide(EST_TrackList &mtfr, EST_Track &fv, EST_Relation &key);
134 void ParallelTracks(EST_Track &a, EST_TrackList &list,const EST_String &style);
135 void track_info(EST_Track &track);
136 
140 
141 int read_track(EST_Track &tr, const EST_String &in_file, EST_Option &al);
142 
143 /** Return the frame size in **seconds** based on analysis of
144 current time points. This function basically determines the local
145 frame size (shift) by subtracting the current time point from the next
146 time point. If the `prefer_prev` flag is set to `true`, or the
147 index is the last in the track, the size is determined by subtracting
148 the previous time point from the current one.
149 
150 This is most commonly used in pitch synchronous analysis to determine
151 the local pitch period.
152 
153 @see get_frame_size
154 */
155 float get_time_frame_size(EST_Track &pms, int i, int prefer_prev = 0);
156 
157 /** Return the frame size in **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 `prefer_prev` flag is set to `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  ///@}
188 
189 /**@name Analysis frame position
190  * @ingroup EST_Track_aux_functions
191  * Functions which define which part of a single is associated with a
192  * given frame in a track.
193  *
194  * This is defined here in one place for consistency. They are inline since
195  * they tend to be used in inner loops. There are two versions,
196  * the second for when there are offsets in the track.
197  */
198 ///@{
199 
200 /// Get the start and end of a given frame (in samples)
201 static inline void get_frame(const EST_Track &tr, int sample_rate,
202  ssize_t f,
203  ssize_t &start, ssize_t &center, ssize_t &end)
204 {
205  center = (int)(tr.t(f)*sample_rate + 0.5);
206  start = center - (int)(tr.a(f, channel_length)/2.0);
207  end = start + (int)(tr.a(f, channel_length));
208 }
209 
210 /// Get the start and end of a given frame (in seconds)
211 static inline void get_frame(const EST_Track &tr, int sample_rate,
212  ssize_t f,
213  float &start, float &center, float &end)
214 {
215  center = tr.t(f);
216  start = center - tr.a(f, channel_length)/(float)sample_rate/2.0;
217  end = start + tr.a(f, channel_length)/(float)sample_rate;
218 }
219 
220 /// Get the start and end of a given frame (in samples)
221 static inline void get_frame_o(const EST_Track &tr, int sample_rate,
222  ssize_t f,
223  int &start, int &center, int &end)
224 {
225  center = (int)(tr.t(f)*sample_rate + tr.a(f,channel_offset) + 0.5);
226  start = center - (int)(tr.a(f, channel_length)/2.0);
227  end = start + (int)(tr.a(f, channel_length));
228 }
229 
230 /// Get the start and end of a given frame (in seconds)
231 static inline void get_frame_o(const EST_Track &tr, int sample_rate,
232  ssize_t f,
233  float &start, float &center, float &end)
234 {
235  center = tr.t(f) + tr.a(f,channel_offset)/(float)sample_rate;
236  start = center - tr.a(f, channel_length)/(float)sample_rate/2.0;
237  end = start + tr.a(f, channel_length)/(float)sample_rate;
238 }
239 
240 ///@}
241 
242 /** @addtogroup EST_Track_aux_functions
243  * @{ */
244 
245 // take one of the channels as the timeline
246 void channel_to_time(EST_Track &tr, ssize_t channel, float scale=1.0);
247 void channel_to_time(EST_Track &tr, EST_ChannelType c,float scale=1.0);
248 void channel_to_time(EST_Track &tr, const EST_String c_name, float scale=1.0);
249 
250 void channel_to_time_lengths(EST_Track &tr, ssize_t channel, float scale=1.0);
251 void channel_to_time_lengths(EST_Track &tr, EST_ChannelType c,float scale=1.0);
252 void channel_to_time_lengths(EST_Track &tr, const EST_String c_name, float scale=1.0);
253 
254 /* Allow EST_Track to be used in an EST_Val */
256 
257 #endif /* __EST_TRACK_AUX_H__ */
258 //@}
void time_mean_smooth(EST_Track &c, float x)
float end(const EST_Item &item)
Definition: EST_item_aux.cc:96
void move_to_frame_ends(EST_Track &tr, int &start, int &end, int sample_rate, float offset=0.0)
Move the start and end variables to the start and end of the nearest frame.
EST_CoefficientType
EST_ChannelType
int track_divide(EST_TrackList &mtfr, EST_Track &fv, EST_Relation &key)
void channel_to_time(EST_Track &tr, ssize_t channel, float scale=1.0)
void get_start_positions(const EST_Track &t, int sample_rate, EST_TBuffer< int > &pos)
Find the start point in the signal of the sections of speech related to each frame.
void simple_mean_smooth(EST_Track &c, ssize_t n, ssize_t channel=0)
unsigned int pos
Position in the structure. May or may not be useful.
Definition: EST_TIterator.h:92
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
Definition: EST_FMatrix.h:119
float rms_error(EST_Track &a, EST_Track &b, ssize_t channel)
float abs_error(EST_Track &a, EST_Track &b, ssize_t channel)
void set_start(EST_Track &tr, float start)
Move the track so that it starts at the indicated time.
unsigned int n() const
Return the current position.
int ssize_t
void extract(EST_Track &orig, float start, float end, EST_Track &res)
EST_Track error(EST_Track &ref, EST_Track &test, int relax=0)
void time_med_smooth(EST_Track &c, float x)
void track_smooth(EST_Track &c, float x, EST_String stype="")
int get_frame_size(EST_Track &pms, int current_pos, int sample_rate, int prefer_prev=0)
Definition: sigpr_utt.cc:317
float & t(ssize_t i=0)
return time position of frame i
Definition: EST_Track.h:478
float & a(ssize_t i, int c=0)
Definition: EST_Track.cc:1025
#define VAL_REGISTER_CLASS_DCLS(NAME, CLASS)
Definition: EST_Val_defs.h:44
void move_start(EST_Track &tr, float shift)
Move the track by shift seconds.
EST_String options_track_filetypes_long(void)
int nearest_boundary(EST_Track &tr, float time, int sample_rate, float offset=0)
Index of the frame whose start boundary.
void track_info(EST_Track &track)
void channel_to_time_lengths(EST_Track &tr, ssize_t channel, float scale=1.0)
void simple_med_smooth(EST_Track &c, ssize_t n, ssize_t channel=0)
EST_String options_subtrack(void)
float time(const EST_Item &item)
Definition: EST_item_aux.cc:82
void align_to_track(EST_Track &tr, float &start, float &end)
Move the start and end variables to the nearest frame.
f
Definition: EST_item_aux.cc:48
Length of section in samples.
getString int
Definition: EST_item_aux.cc:50
float correlation(EST_Track &a, EST_Track &b, ssize_t channel)
EST_Track difference(EST_Track &a, EST_Track &b)
int read_track(EST_Track &tr, const EST_String &in_file, EST_Option &al)
void absolute(EST_Track &tr)
Offset from frame center to center of window.
float mean(const EST_Track &a, ssize_t channel)
float start(const EST_Item &item)
Definition: EST_item_aux.cc:52
void normalise(EST_Track &tr)
float get_time_frame_size(EST_Track &pms, int i, int prefer_prev=0)
Definition: sigpr_utt.cc:333
int get_order(const EST_Track &t, EST_CoefficientType type, int d=0)
How many coefficients in track (looks for Coef0 and coefN channels)
void ParallelTracks(EST_Track &a, EST_TrackList &list, const EST_String &style)
int sum_lengths(const EST_Track &t, int sample_rate, int start_frame=0, int end_frame=-1)
Total the length channel values.
EST_String options_track_filetypes(void)
EST_Track differentiate(EST_Track &c, float samp_int=0.0)
Extending buffer class.
Definition: EST_TBuffer.h:86
void meansd(EST_Track &a, float &m, float &sd, ssize_t channel)