Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
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
53void track_smooth(EST_Track &c, float x, EST_String stype = "");
54void time_med_smooth(EST_Track &c, float x);
55void time_mean_smooth(EST_Track &c, float x);
56void simple_med_smooth(EST_Track &c, int n, int channel=0);
57void 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
64float abs_error(EST_Track &a, EST_Track &b, int channel);
65
66void absolute(EST_Track &tr);
67void normalise(EST_Track &tr);
68void normalise(EST_Track &tr, float mean, float sd, int channel,
69 float upper, float lower);
70void normalise(EST_Track &tr, EST_FVector &mean, EST_FVector &sd,
71 float upper, float lower);
72void 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
84EST_Track differentiate(EST_Track &c, float samp_int=0.0);
85EST_Track difference(EST_Track &a, EST_Track &b);
86
87float mean( const EST_Track &a, int channel );
88void mean( const EST_Track &a, EST_FVector &m );
89
90void 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 */
96float rms_error(EST_Track &a, EST_Track &b, int channel);
97
98float correlation(EST_Track &a, EST_Track &b, int channel);
99
100void 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 */
108EST_FVector rms_error(EST_Track &a, EST_Track &b);
109
111correlation(EST_Track &a, EST_Track &b);
112
113/// Move the start and end variables to the nearest frame.
114void align_to_track(EST_Track &tr, float &start, float &end);
115/// Move the start and end variables to the nearest frame.
116void 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.
118void 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
122int 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.
125void set_start(EST_Track &tr, float start);
126/// Move the track by {\it shift} seconds
127void move_start(EST_Track &tr, float shift);
128
129EST_Track error(EST_Track &ref, EST_Track &test, int relax= 0);
130void extract(EST_Track &orig, float start, float end, EST_Track &res);
131
132int track_divide(EST_TrackList &mtfr, EST_Track &fv, EST_Relation &key);
133void ParallelTracks(EST_Track &a, EST_TrackList &list,const EST_String &style);
134void track_info(EST_Track &track);
135
136EST_String options_track_filetypes(void);
137EST_String options_track_filetypes_long(void);
138EST_String options_subtrack(void);
139
140int 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
143current time points. This function basically determines the local
144frame size (shift) by subtracting the current time point from the next
145time point. If the {\tt prefer_prev} flag is set to {\tt true}, or the
146index is the last in the track, the size is determined by subtracting
147the previous time point from the current one.
148
149This is most commonly used in pitch synchronous analysis to determine
150the local pitch period.
151
152@see get_frame_size
153*/
154
155float 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
158current time points. This function basically determines the local
159frame size (shift) by subtracting the current time point from the next
160time point. If the {\tt prefer_prev} flag is set to {\tt true}, or the
161index is the last in the track, the size is determined by subtracting
162the previous time point from the current one.
163
164This is most commonly used in pitch synchronous analysis to determine
165the local pitch period.
166
167@see get_time_frame_size
168*/
169int 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)
174int get_order(const EST_Track &t, EST_CoefficientType type, int d=0);
175int get_order(const EST_Track &t);
176
177/// Total the length channel values.
178int 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.
183void get_start_positions(const EST_Track &t,
184 int sample_rate,
185 EST_TBuffer<int> &pos);
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)
198static 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)
208static 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)
218static 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)
228static 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
240void channel_to_time(EST_Track &tr, int channel, float scale=1.0);
241void channel_to_time(EST_Track &tr, EST_ChannelType c,float scale=1.0);
242void channel_to_time(EST_Track &tr, const EST_String c_name, float scale=1.0);
243
244void channel_to_time_lengths(EST_Track &tr, int channel, float scale=1.0);
245void channel_to_time_lengths(EST_Track &tr, EST_ChannelType c,float scale=1.0);
246void 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 */
249VAL_REGISTER_CLASS_DCLS(track,EST_Track)
250
251#endif /* __EST_TRACK_AUX_H__ */
252//@}
float & t(int i=0)
return time position of frame i
Definition EST_Track.h:477
float & a(int i, int c=0)