53 static inline int irint(
float f) {
return (
int)(f+0.5); }
54 static inline int irint(
double f) {
return (
int)(f+0.5); }
55 static inline int ifloor(
float f) {
return (
int)(
f); }
62 static
int sorttest(const
void *a, const
void *b)
64 float *c = (
float *)a;
65 float *d = (
float *)b;
66 float res = (*c - *d);
69 return (res < 0.0) ? -1 : 1;
74 if (stype ==
"median")
84 cerr <<
"Error: Time smoothing can only operate on fixed contours\n";
90 cerr <<
"Error in smoothing: time spacing problem\n";
124 float *m =
new float[n];
129 for (i = 0; i < h; ++i)
132 for (j = 0; j < k; ++j)
133 m[j] = c.
a(j, channel);
134 qsort(m, k,
sizeof(
float), sorttest);
141 for (j = 0; j < n; ++j)
142 m[j] = c.
a(i - h + j, channel);
144 qsort(m, n,
sizeof(
float), sorttest);
151 for (j = 0; j < k; ++j)
152 m[j] = c.
a(i - (k/2) + j, channel);
153 qsort(m, k,
sizeof(
float), sorttest);
158 c.
a(i,channel) = a[i];
171 for (i = 0; i < h; ++i)
175 for (j = 0; j < k; ++j)
176 sum += c.
a(j, channel);
177 a[i] = sum /(float) k;
185 for (j = 0; j < k; ++j)
186 sum += c.
a(i - h + j, channel);
187 a[i] = sum /(float) k;
194 for (j = 0; j < k; ++j)
195 sum += c.
a(i - (k/2) + j, channel);
196 a[i] = sum /(float) k;
200 c.
a(i,channel) = a[i];
210 tr.
a(i, j) = fabs(tr.
a(i, j));
223 float upper,
float lower)
232 float upper,
float lower)
239 float upper,
float lower)
247 tr.
a(i, channel) = ((((tr.
a(i, channel) -
mean) / (4 *sd)) + 0.5)
248 * (upper -lower)) + lower;
268 dist = c.
t(i + 1) - c.
t(i);
271 : (c.
a(i + 1) - c.
a(i)) / dist;
272 diff.
t(i) = c.
t(i) + (dist / 2.0);
289 " channel EST_Track with " << b.
num_channels() <<
" channel EST_Track\n";
293 for (i = 0; i < size; ++i)
295 diff.a(i, j) = a.
a(i, j) - b.
a(i, j);
307 for (i = 0; i < size; ++i)
308 diff.
a(i, channel_a) = a.
a(i, channel_a) - b.
a(i, channel_b);
320 cerr <<
"Error: Couldn't find field named " << fname <<
327 cerr <<
"Error: Couldn't find field named " << fname <<
328 " in second Track\n";
342 EST_error(
"Tried to access channel %d of %d channel track",
349 for( i=0, n=0; i<tr_num_frames; ++i )
355 if (n == 0)
return NAN;
357 return mean/(float)n;
364 m.
resize( tr_num_channels, 0 );
366 for(
ssize_t i=0; i<tr_num_channels; ++i )
378 m =
mean( tr, channel );
382 for( i=0, n=0; i<tr_num_frames; ++i)
384 var += pow(tr.
a_no_check(i, channel) - m, float(2.0));
389 var /= (float) (n-1);
406 for (i = 0; i < size; ++i)
408 sum += pow((a.
a(i, channel) - b.
a(i, channel)),
float(2.0));
410 sum = sqrt(sum / size);
419 for (i = 0; i < size; ++i)
423 sum += fabs(a.
a(i, channel) - b.
a(i, channel));
436 for (i = 0; i < size; ++i)
440 predict = b.
a(i, channelb);
441 real = a.
a(i, channela);
444 error = predict-real;
447 xx += predict*predict;
459 cout <<
"RMSE " << sqrt(se.
mean()) <<
" Correlation is " << cor
460 <<
" Mean (abs) Error " << e.
mean() <<
" (" << e.
stddev() <<
")" 473 meansd(a, m[i], sd[i], i);
485 for (p = tl.
head(); p; p = p->
next())
486 for (i = 0; i < tl(p).num_frames(); ++i)
488 if (!tl(p).track_break(i))
490 mean += tl(p).a(i, channel);
502 for (p = tl.
head(); p; p = p->
next())
503 for (i = 0; i < tl(p).num_frames(); ++i)
504 if (!tl(p).track_break(i))
505 var += pow(tl(p).a(i, channel) -
mean, float(2.0));
518 for (i = 0; i < tl.
first().num_channels(); ++i)
519 meansd(tl, m[i], sd[i], i);
531 " channel EST_Track with " << b.
num_channels() <<
" channel EST_Track\n";
550 " channel EST_Track with " << b.
num_channels() <<
" channel EST_Track\n";
569 " channel EST_Track with " << b.
num_channels() <<
" channel EST_Track\n";
586 cerr <<
"Error: Couldn't find field named " << fname <<
593 cerr <<
"Error: Couldn't find field named " << fname <<
594 " in second Track\n";
617 float *r =
new float[relax*3];
623 for (k = 0, j =
Gof((i - relax), 0); j < i + relax + 1; ++j, ++k)
625 if (ref.
a(i, l) > 0.5)
626 r[k] = ((j < test.
num_frames()) && (test.
a(j, l)> 0.6)) ?1
629 r[k] = ((j < test.
num_frames()) && (test.
a(j, l)< 0.4)) ? -1
649 is = tr.
index(start);
661 float start_t = start/(float)sample_rate;
662 float end_t = end/(float)sample_rate;
669 start = (
int)(start_t*sample_rate + 0.5);
670 end = (
int)( end_t*sample_rate + 0.5);
678 float start_t = start/(float)sample_rate;
679 float end_t = end/(float)sample_rate;
683 int is = tr.
index(start_t-offset);
684 int ie = tr.
index(end_t-offset);
686 ssize_t start_s, start_c, start_e;
691 get_frame(tr, sample_rate, is, start_s, start_c, start_e);
692 get_frame(tr, sample_rate, ie, end_s, end_c, end_e);
696 start_s = (
int)(tr.
t(is) * sample_rate);
697 end_s = (
int)(tr.
t(ie) * sample_rate);
700 start = start_s + (
int)(offset*sample_rate + 0.5);
701 end = end_e + (
int)(offset*sample_rate + 0.5);
708 float distance = 10000;
714 get_frame(tr, sample_rate, i, start, center, end);
718 if (fabs(start-time) > distance)
720 distance = fabs(start-time);
734 float shift = start - tr.
t(0);
744 from = orig.
index(start);
754 ret.
a(i, j) = orig.
a(i + from, j);
755 ret.
t(i) = orig.
t(i + from);
781 is = orig.
index(start);
782 ie = orig.
index(end);
785 new_num_frames = (ie - is) > 0 ?ie - is : 0;
788 for (i = 0; i < new_num_frames; ++i)
791 ret.
a(i, j) = orig.
a(i + is, j);
792 ret.
t(i) = orig.
t(i + is);
825 cout <<
"No coefficients in track\n";
837 for(
ssize_t i=start_frame; i<end_frame; i++)
841 cout <<
"no length channel";
854 cout <<
"no length channel\n";
861 get_frame(t, sample_rate, i, wstart, wcent, wend);
876 from = al.
ival(
"-from");
896 new_ch = ch_list.
length();
901 for (i = 0, p = ch_list.
head(); p; p = p->
next(), ++i)
906 EST_error(
"Tried to extract channel number %d from track with " 910 nt.
a(j, i) = orig.
a(j, k);
924 ssize_t num_channels, num_frames;
927 for (num_channels=0,p=list.
head(); p; p=p->
next())
928 num_channels += list(p).num_channels();
930 if (style ==
"first")
932 num_frames = list.
first().num_frames();
933 longest = list.
head();
937 if (style !=
"longest")
938 cerr <<
"EST_Track: unknown combine style \"" << style <<
939 "\" assuming longest" << endl;
940 for (num_frames = 0, longest = p = list.
head(); p; p = p->
next())
941 if (num_frames < list(p).num_frames())
943 num_frames = list(p).num_frames();
948 a.
resize(num_frames, num_channels);
951 for (k = 0, p = list.
head(); p; p = p->
next())
953 n =
Lof(num_frames, list(p).num_frames());
954 for (j = 0; j < list(p).num_channels(); ++j, ++k)
956 for (i = 0; i < n; ++i)
957 a(i, k) = list(p).a(i, j);
962 for (i = 0; i < list(longest).num_frames(); ++i)
963 a.
t(i) = list(longest).
t(i);
971 tr.
t(i) = tr.
a(i,channel) * scale;
1001 cerr <<
"no channel named '" << c_name <<
"'\n";
1012 tt += tr.
a(i,channel) * scale;
1042 cerr <<
"no channel named '" << c_name <<
"'\n";
1050 "-start <float> Extract track starting at this time, \n" 1051 " specified in seconds\n\n" 1052 "-end <float> Extract track ending at this time, \n" 1053 " specified in seconds\n\n" 1054 "-from <int> Extract track starting at this frame position\n\n" 1055 "-to <int> Extract track ending at this frame position\n\n";
1063 "-itype <string> Input file type (optional). If no type is\n" 1064 " specified type is automatically derived from\n" 1065 " file's header. Supported types\n" 1068 "-ctype <string> Contour type: F0, track\n\n" 1069 "-s <float> Frame spacing of input in seconds, for unheadered input file\n\n" 1070 "-startt <float> Time of first frame, for formats which don't provide this\n\n" 1071 "-c <string> Select a subset of channels (starts from 0). \n" 1072 " Tracks can have multiple channels. This option \n" 1073 " specifies a list of numbers, refering to the channel \n" 1074 " numbers which are to be used for for processing. \n\n"+
1084 "-otype <string> {ascii}\n"+
1085 " Output file type, if unspecified ascii is\n"+
1087 "-S <float> Frame spacing of output in seconds. If this is \n" 1088 " different from the internal spacing, the contour is \n" 1089 " resampled at this spacing \n\n" 1090 "-o <ofile> Output filename, defaults to stdout\n\n";
1095 cout << t.
name() << endl;
1096 cout <<
"Number of frames: " << t.
num_frames() << endl;
1097 cout <<
"Number of channels: " << t.
num_channels() << endl;
1100 cout <<
"Frame shift: " << t.
shift() << endl;
1102 cout <<
"Frame shift: varied" << endl;
1104 cout <<
"Channel: " << i <<
": " << t.
channel_name(i) << endl;
void time_mean_smooth(EST_Track &c, float x)
float end(const EST_Item &item)
short get(EST_ChannelType type) const
Get the position of a channel.
void qsort(EST_TList< T > &a)
#define EST_CoefChannelId(CT, D, SE)
void move_to_frame_ends(EST_Track &tr, int &start, int &end, int sample_rate, float offset)
Move the start and end variables to the start and end of the nearest frame.
double stddev(void) const
standard deviation of currently cummulated values
void channel_to_time(EST_Track &tr, ssize_t channel, float scale)
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)
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
void set_value(ssize_t i)
set frame i to be a value
void set_channel_name(const EST_String &name, int channel)
set the name of the channel.
void set_break(ssize_t i)
set frame i to be a break
int ival(const EST_String &rkey, int m=1) const
EST_String name() const
name of track - redundant use access to features
int num_channels() const
return number of channels in track
float rms_error(EST_Track &a, EST_Track &b, ssize_t channel)
double mean(void) const
mean of currently cummulated values
EST_TrackFileType file_type() const
void ensure(unsigned int req_size)
Extend if needed, copying existing data.
INLINE const T & a_no_check(ssize_t n) const
read-only const access operator: without bounds checking
float abs_error(EST_Track &a, EST_Track &b, ssize_t channel)
ssize_t index_below(float x) const
return the frame index before time t
void set_start(EST_Track &tr, float start)
Move the track so that it starts at the indicated time.
float fval(const EST_String &rkey, int m=1) const
#define VAL_REGISTER_CLASS(NAME, CLASS)
void resize(ssize_t num_frames, int num_channels, bool preserve=1)
float & a_no_check(ssize_t i, int c=0)
static EST_String options_short(void)
void extract(EST_Track &orig, float start, float end, EST_Track &ret)
ssize_t index(float t) const
return the frame index nearest time t
EST_Track error(EST_Track &ref, EST_Track &test, int relax)
guaranteed to be the first known type
void time_med_smooth(EST_Track &c, float x)
void track_smooth(EST_Track &c, float x, EST_String stype)
void sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL)
float correlation(EST_Track &a, EST_Track &b, ssize_t cha, ssize_t chb)
int track_break(ssize_t i) const
return true if frame i is a break
int channel_position(const char *name, int offset=0) const
bool equal_space() const
return true if track has equal (i.e. fixed) frame spacing */
float & t(ssize_t i=0)
return time position of frame i
float & a(ssize_t i, int c=0)
const char * name(ENUM tok, int n=0) const
void copy_setup(const EST_Track &a)
copy everything but data
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)
Index of the frame whose start boundary.
void track_info(EST_Track &t)
void channel_to_time_lengths(EST_Track &tr, ssize_t channel, float scale)
void simple_med_smooth(EST_Track &c, ssize_t n, ssize_t channel)
EST_String options_subtrack(void)
float time(const EST_Item &item)
void align_to_track(EST_Track &tr, float &start, float &end)
Move the start and end variables to the nearest frame.
const T & first() const
return const reference to first item in list
static EST_TNamedEnumI< EST_TrackFileType, Info > map
ssize_t num_frames() const
return number of frames in track
Length of section in samples.
EST_Track difference(EST_Track &a, EST_Track &b)
const EST_String channel_name(int channel, const EST_ChannelNameMap &map, int strings_override=1) const
EST_ChannelNameMap EST_default_channel_names
Definition of standard names we use for channels.
void absolute(EST_Track &tr)
float mean(const EST_Track &tr, ssize_t channel)
float start(const EST_Item &item)
void extract2(EST_Track &orig, float start, float end, EST_Track &ret)
int present(const K &rkey) const
Returns true if key is present.
void normalise(EST_Track &tr)
int val(ssize_t i) const
return true if frame i is a value
int get_order(const EST_Track &t, EST_CoefficientType type, int d)
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, ssize_t start_frame, ssize_t end_frame)
Total the length channel values.
EST_String options_track_filetypes(void)
EST_Track differentiate(EST_Track &c, float samp_int)
void extract_channel(EST_Track &orig, EST_Track &nt, EST_IList &ch_list)
bool has_channel(const char *name) const
float sum(const EST_FMatrix &a)
sum of elements
void set_equal_space(bool t)
EST_String options_track_input(void)
EST_String options_track_output(void)
void meansd(EST_Track &tr, float &m, float &sd, ssize_t channel)
void resize(int n, int set=1)
resize vector
static EST_String options_supported(void)
#define NO_SUCH_CHANNEL
Returned if we ask for a channel not in the map.
EST_TrackMap::P map() const
Guaranteed to be one more than last legal coefficient type.