46#include "EST_string_aux.h"
47#include "EST_TrackFile.h"
50const int EST_Track::default_sample_rate=16000;
51const float EST_Track::default_frame_shift=0.005;
100void EST_Track::default_channel_names()
106void EST_Track::default_vals(
void)
108 p_equal_space = FALSE;
109 p_single_break = FALSE;
115 p_channel_names.
resize(0);
125 cerr <<
"Requested setting of break value of the end of the array\n";
140 return p_channel_names(i);
168 p_channel_names[i] =
fn;
179 for (i = 0; i <
tr.num_frames(); ++i)
182 for (
j = 0;
j <
tr.num_channels(); ++
j)
183 s <<
"\t" <<
tr(i,
j);
184 for (
j = 0;
j <
tr.num_aux_channels(); ++
j)
185 s <<
"\t" <<
tr.aux(i,
j);
186 s <<
"\t" << !
tr.track_break(i) <<
endl;
194 p_values =
a.p_values;
196 p_is_val =
a.p_is_val;
197 p_t_offset =
a.p_t_offset;
199 p_aux_names =
a.p_aux_names;
204 p_equal_space =
a.p_equal_space;
205 p_single_break =
a.p_single_break;
206 p_channel_names =
a.p_channel_names;
256 cerr<<
"Ill formed coefficient range in map: " << b <<
"\n";
260 first = b.
after(
"-");
262 if (!first.contains(
"+"))
264 cerr<<
"Ill formed coefficient range in map: "<<first<<
"\n";
268 last = first.after(
"+");
269 first = first.before(
"+");
271 n_f = Stringtoi(first);
272 n_l = Stringtoi(last);
274 for (
int i =
n_f; i <
n_l; ++i)
300 for (i = 0, p =
x.head(); p ; p = p->next(), ++i)
340 cerr <<
"Error: Tried to add " <<
a.num_channels() <<
341 " channel EST_Track to "<<
num_channels() <<
" channel EST_Track\n";
348 for (i = 0,
j =
old_num; i <
a.num_frames(); ++i, ++
j)
353 p_is_val[
j] =
a.p_is_val(i);
371 cerr <<
"Error: Tried to add " <<
a.num_frames() <<
372 " channel EST_Track to "<<
num_frames()<<
" channel EST_Track\n";
378 for (i = 0,
j =
old_num; i <
a.num_channels(); ++i, ++
j)
397 if (channel_name(c) ==
name)
408 if (channel_name(c) ==
name)
411 cerr <<
"no channel '" <<
name <<
"'\n";
415EST_Val &EST_Track::aux(
int i,
const char *name)
418 if (aux_channel_name(c) ==
name)
421 cerr <<
"no auxiliary channel '" <<
name <<
"' found\n";
425EST_Val &EST_Track::aux(
int i,
int c)
430EST_Val &EST_Track::aux(
int i,
int c)
const
435#define EPSILON (0.0001)
439 static float ia = 0.0;
441 if (interp == it_nearest)
443 else if (interp == it_linear)
449 float n =
a(i,c),
n1 =
a(i+1,c);
450 float tn = p_times(i),
tn1 = p_times(i+1);
454 else if (interp == it_linear_nz)
460 float n =
a(i,c),
n1 =
a(i+1,c);
463 float tn = p_times(i),
tn1 = p_times(i+1);
475 int f = (int)( (
x-
t(0))/s+0.5 );
605 EST_error(
"Tried to take shift from non-fixed contour\n");
613 while ((
j2 != 0) && (
j2 != (
j1 +1)));
618 return p_times(1) - p_times(0);
620 EST_error(
"Couldn't determine shift size\n");
623 return (p_times(
j2) - p_times(
j1));
647 for (--i; i >= 0 ; --i)
659 p_equal_space = TRUE;
685 for (i = 0; i < n; ++i)
688 for (i = 0; i < n; ++i)
698 p_single_break = FALSE;
699 p_equal_space = TRUE;
702float EST_Track::interp_amp(
float x,
int c,
float fl)
708 if ((p_times(i) + (
fl / 2.0))>
x)
731 return ((
x -
x1) *
m) +
y1;
734int EST_Track::interp_value(
float x,
float fl)
743 cf = estimate_shift(
x);
746 if ((p_times(i) + (
fl / 2.0))>
x)
762 if ((
x < p_times(p) + (
cf / 2.0)) || (
x > p_times(n) - (
cf / 2.0)))
768float EST_Track::estimate_shift(
float x)
775 for (i =
j; i > 0; --i)
777 return p_times(i) - p_times(i - 1);
781 return p_times(i + 1) - p_times(i);
790 for(
unsigned int i=0; i<
nframes; ++i )
798 for(
unsigned int i=0; i<
nframes; ++i )
806 for(
unsigned int i=0; i<
nframes; ++i )
841 p_single_break = TRUE;
844void EST_Track::rm_trailing_breaks()
863 p_times[
j] = p_times(i);
866 p_is_val[
j] = p_is_val(i);
875void EST_Track::add_trailing_breaks()
913void EST_Track::pad_breaks()
919 EST_error(
"pad_breaks: Can only operate on fixed data\n");
926 n = (int)(((
end())/
shift()) + 1.0);
929 for (i = 0; i < n; ++i)
937 for (i = 0,
j = s;
j < n; ++i, ++
j)
963 p_single_break = FALSE;
966static bool bounds_check(
const EST_Track &t,
int f,
int c,
int set)
968 const char *
what = set?
"set" :
"access";
972 cerr <<
"Attempt to " <<
what <<
" frame " << f <<
" of " << t.
num_frames() <<
" frame track\n";
977 cerr <<
"Attempt to " <<
what <<
" channel " << c <<
" of " << t.
num_channels() <<
" channel track\n";
984static bool bounds_check(
const EST_Track &t,
989 const char *
what = set?
"set" :
"access";
995 cerr <<
"Attempt to " <<
what <<
" frame " << f <<
" of " << t.
num_frames() <<
" frame track\n";
1000 cerr <<
"Attempt to " <<
what <<
" frame " << f+
nf-1 <<
" of " << t.
num_frames() <<
" frame track\n";
1009 cerr <<
"Attempt to " <<
what <<
" channel " << c <<
" of " << t.
num_channels() <<
" channel track\n";
1014 cerr <<
"Attempt to " <<
what <<
" channel " << c+
nc-1 <<
" of " << t.
num_channels() <<
" channel track\n";
1024 if (!bounds_check(*
this, i,c,0))
1066 EST_error(
"sub_track: No such channel %s\n",
1080 EST_error(
"sub_track: No such channel %s\n",
1088 EST_error(
"sub_track: No such channel %s\n",
1123 st.p_t_offset = p_t_offset;
1125 st.p_equal_space = p_equal_space;
1126 st.p_single_break = p_single_break;
1127 st.copy_features(*
this);
1154 for (
int c=0; c<
nchans; c++)
1158 for (
int c=0; c<
nchans; c++)
1159 st.p_channel_names.a(c) = p_channel_names.a(c+
start_chan);
1162 st.p_aux_names = p_aux_names;
1164 st.p_equal_space = p_equal_space;
1165 st.p_single_break = p_single_break;
1167 st.copy_features(*
this);
1181 for(
int i=0; i<
f_len; ++i ){
1188 for(
int c=0; c<
nchans; c++ )
1192 st.copy_setup( *
this );
1193 st.set_equal_space(
false );
1207 for(
int i=0; i<
f_len; ++i ){
1216 for(
int c=0; c<
nchans; c++ )
1221 st.copy_setup( *
this );
1222 st.set_equal_space(
false );
1235 EST_TrackFileType
t = EST_TrackFile::map.token(
save_type);
1243 EST_TrackFile::Save_File *
s_fun = EST_TrackFile::map.info(
t).save;
1251 return (*
s_fun)(filename, *
this);
1256 EST_TrackFileType
t = EST_TrackFile::ts_map.token(type);
1260 cerr <<
"Unknown Track file type " << type <<
endl;
1264 EST_TrackFile::Save_TokenStream *
s_fun =
1265 EST_TrackFile::ts_map.info(
t).save;
1269 cerr <<
"Can't save tracks to files type " << type <<
endl;
1272 return (*
s_fun)(fp, *
this);
1277 EST_read_status
stat = read_error;
1279 for (
int n = 0; n < EST_TrackFile::ts_map.n(); n++)
1281 EST_TrackFileType
t = EST_TrackFile::ts_map.token(n);
1286 EST_TrackFile::TS_Info *info = &(EST_TrackFile::ts_map.info(
t));
1288 if (! info->recognise)
1291 EST_TrackFile::Load_TokenStream *
l_fun =info->load;
1298 if (
stat != read_format_error)
1300 if (
stat == read_ok)
1311 EST_read_status
stat = read_error;
1313 for(
int n=0; n< EST_TrackFile::map.n() ; n++)
1315 EST_TrackFileType
t = EST_TrackFile::map.token(n);
1321 EST_TrackFile::Info *info = &(EST_TrackFile::map.info(
t));
1323 if (! info->recognise)
1326 EST_TrackFile::Load_File *
l_fun =info->load;
1333 if (
stat == read_ok)
1338 else if (
stat == read_error)
1347 EST_TrackFileType
t = EST_TrackFile::map.token(type);
1351 cerr <<
"Unknown Track file type " << type <<
endl;
1355 EST_TrackFile::Load_File *
l_fun = EST_TrackFile::map.info(
t).load;
1359 cerr <<
"Can't load tracks from file type" << type <<
endl;
1367EST_write_status EST_Track::save_channel_names(
const EST_String filename)
1375 fprintf(
file,
"%s\n", (
const char *)channel_name(c));
1382EST_read_status EST_Track::load_channel_names(
const EST_String filename)
1385 static const int buffer_length = 100;
1386 char buffer[buffer_length];
1389 return misc_read_error;
1393 if (!
fgets(buffer, buffer_length,
file))
1396 buffer[
strlen(buffer)-1] =
'\0';
1409float &
EST_Track::a(
float t, EST_ChannelType type, EST_InterpType interp)
1411 short c = NO_SUCH_CHANNEL;
1413 if (p_map!=0 && (c = p_map->
get(type)) != NO_SUCH_CHANNEL)
1414 return a(
t, c, interp);
1417 cerr <<
"no channel '" << EST_default_channel_names.name(type) <<
"' = " << (int)type <<
"\n";
1434 EST_ChannelType type = names.token(p_channel_names(i));
1436 if (type != channel_unknown)
1456 int p = (*p_map)(type);
1457 return (p!= NO_SUCH_CHANNEL)?(p+offset): NO_SUCH_CHANNEL;
1462float &
EST_Track::a(
int i, EST_ChannelType type,
int offset)
1464 short c = NO_SUCH_CHANNEL;
1466 if (p_map!=0 && ((c = p_map->
get(type)) != NO_SUCH_CHANNEL))
1470 cerr <<
"no channel '" << EST_default_channel_names.name(type) <<
"' = " << (int)type <<
"\n";
1476EST_Track::IPointer_f::IPointer_f()
1481EST_Track::IPointer_f::IPointer_f(
const IPointer_f &p)
1486EST_Track::IPointer_f::~IPointer_f()
1496#if defined(INSTANTIATE_TEMPLATES)
EST_String before(int pos, int len=0) const
Part before position.
int contains(const char *s, int pos=-1) const
Does it contain this substring?
EST_String after(int pos, int len=1) const
Part after pos+len.
int matches(const char *e, int pos=0) const
Exactly match this string?
INLINE const T & a_no_check(int row, int col) const
const access with no bounds check, care recommend
void sub_matrix(EST_TMatrix< T > &sm, int r=0, int numr=EST_ALL, int c=0, int numc=EST_ALL)
Make the matrix {\tt sm} a window into this matrix.
void resize(int rows, int cols, int set=1)
void resize(int rows, int cols, int set=1)
resize matrix
void resize(int n, int set=1)
resize vector
void resize(int n, int set=1)
void sub_vector(EST_TVector< T > &sv, int start_c=0, int len=-1)
Create a sub vector.
void fill(const T &v)
Fill entire array will value <parameter>v</parameter>.
INLINE const T & a_no_check(int n) const
read-only const access operator: without bounds checking
short last_channel(void) const
Returns the index of the last known channel.
short get(EST_ChannelType type) const
Get the position of a channel.
void set(EST_ChannelType type, short pos)
Record the position of a channel.
void copy_sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL) const
int channel_position(const char *name, int offset=0) const
void set_channel_name(const EST_String &name, int channel)
set the name of the channel.
EST_read_status load(const EST_String name, float ishift=0.0, float startt=0.0)
int track_break(int i) const
return true if frame i is a break
float & t(int i=0)
return time position of frame i
int val(int i) const
return true if frame i is a value
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
float & a(int i, int c=0)
int num_aux_channels() const
return number of auxiliary channels in track
int next_non_break(int i) const
void copy_setup(const EST_Track &a)
copy everything but data
~EST_Track()
default destructor
int index_below(float x) const
return the frame index before time t
void sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL)
EST_Track()
Default constructor.
int empty() const
returns true if no values are set in the frame
bool equal_space() const
return true if track has equal (i.e. fixed) frame spacing */
float start() const
return time of first value in track
void set_value(int i)
set frame i to be a value
void resize_aux(EST_StrList &map, bool preserve=1)
int num_channels() const
return number of channels in track
int num_frames() const
return number of frames in track
float end() const
return time of last value in track
int index(float t) const
return the frame index nearest time t
float & a_no_check(int i, int c=0)
void channel(EST_FVector &cv, int n, int startf=0, int nf=EST_ALL)
void change_type(float nshift, bool single_break)
REDO.
void resize(int num_frames, int num_channels, bool preserve=1)
float & a(float t, int c=0, EST_InterpType interp=it_nearest)
EST_String name() const
name of track - redundant use access to features
void fill_time(float t, int start=1)
void set_aux_channel_name(const EST_String &name, int channel)
set the name of the auxiliary channel.
int prev_non_break(int i) const
void frame(EST_FVector &fv, int n, int startf=0, int nf=EST_ALL)
void set_break(int i)
set frame i to be a break
bool single_break() const