Edinburgh Speech Tools  2.1-release
EST_Track.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  /* Author : Paul Taylor */
35  /* Rewritten : Richard Caley */
36  /* ------------------------------------------------------------------- */
37  /* EST_Track Class header file */
38  /* */
39  /*************************************************************************/
40 
41 class EST_Track;
42 
43 #ifndef __Track_H__
44 #define __Track_H__
45 
46 #include <cstdlib>
47 #include "EST_FMatrix.h"
48 #include "EST_types.h"
49 #include "EST_TrackMap.h"
50 #include "EST_ChannelType.h"
51 #include "EST_Featured.h"
52 
54 
55 class EST_TokenStream;
56 class EST_String;
57 
58 typedef enum EST_TrackFileType {
78 
79 typedef enum EST_InterpType {
80  it_nearest, // nearest time point
81  it_linear, // linerar interpolation
82  it_linear_nz // .. unless one end near zero
84 
85 /** A class for storing time aligned coefficients.
86 
87 some stuff.
88 */
89 
90 class EST_Track : public EST_Featured {
91 
92 protected:
93  EST_FMatrix p_values; // float x array
94  EST_FVector p_times; // float y array
95  EST_CVector p_is_val; // for breaks and non-breaks
96 
97  EST_ValMatrix p_aux; // Auxiliary channels
98  EST_StrVector p_aux_names; // Names of auxiliary channels
99 
100  float p_t_offset; // time shift.
101 
103  EST_StrVector p_channel_names; // name of each track
104 
105  bool p_equal_space; // fixed or variable frame rate
106  bool p_single_break; // single break lots between data
107 
108  void default_vals();
109  void default_channel_names();
110  void clear_arrays();
111  void pad_breaks(); // put in extra breaks
112 
113  int interp_value(float x, float f);
114  float interp_amp(float x, int c, float f);
115  float estimate_shift(float x);
116  void copy(const EST_Track& a);
117 
118 public:
119  static const float default_frame_shift;
120  static const int default_sample_rate;
121 
122  /**@name Constructor and Destructor functions
123  */
124 
125  //@{
126 
127  /// Default constructor
128  EST_Track();
129 
130  /// Copy constructor
131  EST_Track(const EST_Track &a);
132 
133  /// resizing constructor
135 
136  /// resizing constructor
138 
139  /// default destructor
140  ~EST_Track();
141  //@}
142 
143  /** @name Configuring Tracks
144  */
145  //@{
146 
147  /** resize the track to have `num_frames` and `num_channels`.
148  if `preserve` is set to 1, any existing values in the track
149  are kept, up to the limits imposed by the new number of frames
150  and channels. If the new track size is bigger, new positions
151  are filled with 0 */
152  void resize(ssize_t num_frames, int num_channels, bool preserve = 1);
153 
154  /** resize the track to have `num_frames` and `num_channels`.
155  if `preserve` is set to 1, any existing values in the track
156  are kept, up to the limits imposed by the new number of frames
157  and channels. If the new track size is bigger, new positions
158  are filled with 0 */
159  void resize(ssize_t num_frames, EST_StrList &map, bool preserve = 1);
160 
161  /** resize the track's auxiliary channels.
162  */
163  void resize_aux(EST_StrList &map, bool preserve = 1);
164 
165  /** Change the number of channels while keeping the number of
166  frames the same. if `preserve` is set to 1, any existing
167  values in the track are kept, up to the limits imposed by the
168  new number of frames and channels. If the new track size is
169  bigger, new positions are filled with 0 */
170  void set_num_channels(int n, bool preserve = 1)
171  { resize(EST_CURRENT, n, preserve); }
172 
173  /** Change the number of frames while keeping the number of
174  channels the same. if `preserve` is set to 1, any
175  existing values in the track are kept, up to the limits
176  imposed by the new number of frames and channels. If the new
177  track size is bigger, new positions are filled with 0 */
178  void set_num_frames(ssize_t n, bool preserve = 1)
179  { resize(n, EST_CURRENT, preserve); }
180 
181  /// set the name of the channel.
182  void set_channel_name(const EST_String &name, int channel);
183 
184  /// set the name of the auxiliary channel.
185  void set_aux_channel_name(const EST_String &name, int channel);
186 
187  /// copy everything but data
188 
189  void copy_setup(const EST_Track& a);
190  //@}
191 
192  /**@name Global track information
193  */
194  //@{
195  /// name of track - redundant use access to features
196  EST_String name() const
197  { return f_String("name");}
198  /// set name of track - redundant use access to features
199  void set_name(const EST_String &n)
200  {f_set("name",n);}
201 
202  //@}
203 
204  /**@name Functions for sub tracks, channels and frames.
205  */
206  //@{
207 
208  /** make `fv` a window to frame `n` in the track.
209  */
210  void frame(EST_FVector &fv, int n, int startf=0, int nf=EST_ALL)
211  { p_values.row(fv, n, startf, nf); }
212 
213  /** make `fv` a window to channel `n` in the track.
214  */
215  void channel(EST_FVector &cv, ssize_t n, int startf=0, int nf=EST_ALL)
216  { p_values.column(cv, n, startf, nf); }
217 
218  /** make `fv` a window to the named channel in the track.
219  */
220  void channel(EST_FVector &cv, const char * name, int startf=0,
221  int nf=EST_ALL);
222 
223  /** make `st` refer to a portion of the track. No values
224  are copied - an internal pointer in st is set to the specified
225  portion of the the track. After this, st behaves like a normal
226  track. Its first channel is the same as start_channel and its
227  first frame is the same as start_frame. Any values written into
228  st will changes values in the main track. st cannot be resized.
229 
230  @param start_frame first frame at which sub-track starts
231  @param nframes number of frames to be included in total
232  @param start_channel first channel at which sub-track starts
233  @param nframes number of channels to be included in total
234  */
235  void sub_track(EST_Track &st,
236  int start_frame=0, int nframes=EST_ALL,
237  int start_chan=0, int nchans=EST_ALL);
238 
239  /** make `st` refer to a portion of the track. No values
240  are copied - an internal pointer in st is set to the specified
241  portion of the the track. After this, st behaves like a normal
242  track. Its first channel is the same as start_channel and its
243  first frame is the same as start_frame. Any values written into
244  st will changes values in the main track. st cannot be resized.
245 
246  @param start_frame first frame at which sub-track starts
247  @param nframes number of frames to be included in total
248  @param start_channel_name name of channel at which sub-track starts
249  @param end_channel_name name of channel at which sub-track stops
250  */
251  void sub_track(EST_Track &st,
252  int start_frame, int nframes,
253  const EST_String &start_chan_name,
254  int nchans=EST_ALL);
255 
256  /** make `st` refer to a portion of the track. No values
257  are copied - an internal pointer in st is set to the specified
258  portion of the the track. After this, st behaves like a normal
259  track. Its first channel is the same as start_channel and its
260  first frame is the same as start_frame. Any values written into
261  st will changes values in the main track. st cannot be resized.
262 
263  @param start_frame first frame at which sub-track starts
264  @param nframes number of frames to be included in total
265  @param start_channel_name name of channel at which sub-track starts
266  @param end_channel_name name of channel at which sub-track stops
267  */
268  void sub_track(EST_Track &st,
269  int start_frame, int nframes,
270  const EST_String &start_chan_name,
271  const EST_String &end_chan_name);
272 
273  /** make `st` refer to a portion of the track. (const version)
274  No values
275  are copied - an internal pointer in st is set to the specified
276  portion of the the track. After this, st behaves like a normal
277  track. Its first channel is the same as start_channel and its
278  first frame is the same as start_frame. Any values written into
279  st will changes values in the main track. st cannot be resized.
280 
281  @param start_frame first frame at which sub-track starts
282  @param nframes number of frames to be included in total
283  @param start_channel first channel at which sub-track starts
284  @param nframes number of channels to be included in total
285  */
287  int start_frame=0, int nframes=EST_ALL,
288  int start_chan=0, int nchans=EST_ALL) const
289  { ((EST_Track *)this)->sub_track(st, start_frame, nframes,
290  start_chan, nchans); }
291 
292  /** Copy contiguous portion of track into `st`. Unlike the
293  normal sub_track functions, this makes a completely new track.
294  values written into this will not affect the main track and it
295  can be resized.
296 
297  @param start_frame first frame at which sub-track starts
298  @param nframes number of frames to be included in total
299  @param start_channel first channel at which sub-track starts
300  @param nframes number of channels to be included in total
301  */
302 
303  void copy_sub_track( EST_Track &st,
304  int start_frame=0, int nframes=EST_ALL,
305  int start_chan=0, int nchans=EST_ALL) const;
306 
307  void copy_sub_track_out( EST_Track &st, const EST_FVector& frame_times ) const;
308  void copy_sub_track_out( EST_Track &st, const EST_IVector& frame_indices ) const;
309 
310  /** copy channel `n` into pre-allocated buffer buf */
311  void copy_channel_out(int n, float *buf, int offset=0, int num=EST_ALL)
312  const
313  { p_values.copy_column(n, buf, offset, num); }
314 
315  /** copy channel `n` into EST_FVector */
316  void copy_channel_out(int n, EST_FVector &f, int offset=0, int num=EST_ALL)
317  const
318  { p_values.copy_column(n, f, offset, num); }
319 
320  /** copy frame `n` into pre-allocated buffer buf */
321  void copy_frame_out(int n, float *buf, int offset=0, int num=EST_ALL)
322  const {p_values.copy_row(n, buf, offset, num); }
323 
324  /** copy frame `n` into EST_FVector */
325  void copy_frame_out(int n, EST_FVector &f, int offset=0, int num=EST_ALL)
326  const {p_values.copy_row(n, f, offset, num); }
327 
328  /** copy buf into pre-allocated channel n of track */
329  void copy_channel_in(int n, const float *buf, int offset=0,
330  int num=EST_ALL)
331  { p_values.set_column(n, buf, offset, num); }
332 
333  /** copy f into pre-allocated channel n of track */
334  void copy_channel_in(int n, const EST_FVector &f, int offset=0,
335  int num=EST_ALL)
336  { p_values.set_column(n, f, offset, num); }
337 
338  /** copy channel buf into pre-allocated channel n of track */
339  void copy_channel_in(int c,
340  const EST_Track &from, int from_c, int from_offset=0,
341  int offset=0, int num=EST_ALL)
342  { p_values.set_column(c, from.p_values, from_c,
343  from_offset, offset, num); }
344 
345  /** copy buf into frame n of track */
346  void copy_frame_in(int n, const float *buf, int offset=0,
347  int num=EST_ALL)
348  { p_values.set_row(n, buf, offset, num); }
349 
350  /** copy t into frame n of track */
351  void copy_frame_in(int n, const EST_FVector &t, int offset=0,
352  int num=EST_ALL)
353  { p_values.set_row(n, t, offset, num); }
354 
355  /** copy from into frame n of track */
357  const EST_Track &from, int from_f, int from_offset=0,
358  int offset=0, int num=EST_ALL)
359  { p_values.set_row(i, from.p_values, from_f, from_offset, offset,
360  num); }
361 
362  //@}
363 
364  /**@name Channel information
365  */
366 
367  //@{
368 
369  /** Return the position of channel `name` if it exists,
370  otherwise return -1.
371  */
372  int channel_position(const char *name, int offset=0) const;
373 
374  /** Return the position of channel `name` if it exists,
375  otherwise return -1.
376  */
377  int channel_position(EST_String name, int offset=0) const
378  { return channel_position((const char *)name, offset); }
379 
380 
381  /** Returns true if the track has a channel named `name`,
382  otherwise false.
383  */
384 
385  bool has_channel(const char *name) const
386  { return (long signed int) channel_position(name) >=0; }
387 
388  /** Returns true if the track has a channel named `name`,
389  otherwise false.
390  */
391  bool has_channel(EST_String name) const
392  { return has_channel((const char *)name); }
393 
394  //@}
395 
396  /** @name Accessing amplitudes The following functions can be used
397  to access to amplitude of the track at certain points. Most of
398  these functions can be used for reading or writing to this
399  point, thus
400 
401  tr.a(10, 5) = 10.3;
402 
403  can be used to set the 10th frame of the 5th channel and
404 
405  cout << tr.a(10, 5);
406 
407  can be used to print the same information. Most of these functions
408  have a const equivalent for helping the compiler in
409  read only operations.
410  */
411 
412  //@{
413 
414  /** return amplitude of frame i, channel c.*/
415  float &a(ssize_t i, int c=0);
416  float a(ssize_t i, int c=0) const;
417 
418  /** return amplitude of frame i, channel c with no bounds
419  checking. */
420  float &a_no_check(ssize_t i, int c=0) { return p_values.a_no_check(i,c); }
421  float a_no_check(ssize_t i, int c=0) const {return p_values.a_no_check(i,c);}
422 
423  /** return amplitude of point i, in the channel named name plus
424  offset. If you have a track with say channels called F0 and
425  voicing, you can access the 45th frame's F0 as t.a(45, "F0");
426  If there are 20 cepstral coefficients for each frame, the 5th can
427  be accessed as t.a(45, "cepstrum", 5);
428  */
429 
430  float &a(ssize_t i, const char *name, int offset=0);
431 
432  float a(ssize_t i, const char *name, int offset=0) const
433  { return ((EST_Track *)this)->a(i, name, offset); }
434  float &a(ssize_t i, EST_String name, int offset=0)
435  { return a(i, (const char *)name, offset); }
436  float a(ssize_t i, EST_String name, int offset=0) const
437  { return ((EST_Track *)this)->a(i, (const char *)name, offset); }
438 
439  /** return amplitude of time t, channel c. This can be used for
440  reading or writing to this point. By default the nearest frame
441  to this time is used. If `interp` is set to `it_linear`,
442  linear interpolation is performed between the two
443  amplitudes of the two frames either side of the time point to
444  give an estimation of what the amplitude would have been at
445  time `t`. If `interp` is set to `it_linear_nz`,
446  interpolation is as above, unless the time requested is off
447  the end of a portion of track in which case the nearest
448  amplitude is returned.
449  */
450  float &a(float t, int c=0, EST_InterpType interp=it_nearest);
451  float a(float t, int c=0, EST_InterpType interp=it_nearest) const
452  { return ((EST_Track *)this)->a(t, c, interp); }
453 
454 
455  /** return amplitude of frame i, channel c. */
456  float &operator() (ssize_t i, int c) { return a(i,c); }
457  /** return amplitude of frame i, channel 0. */
458  float &operator() (ssize_t i) { return a(i,0); }
459  float operator() (ssize_t i, int c) const { return a(i,c); }
460  float operator() (ssize_t i) const { return a(i,0); }
461 
462  /** return amplitude of frame nearest time t, channel c. */
463  float &operator() (float t, int c) {return a(t,c); }
464  /** return amplitude of frame nearest time t, channel 0. */
465  float &operator() (float t) {return a(t,0); }
466  float operator() (float t, int c) const {return a(t,c); }
467  float operator() (float t) const {return a(t,0); }
468 
469  //@}
470 
471  /** @name Timing
472 
473  */
474 
475  //@{
476 
477  /// return time position of frame i
478  float &t(ssize_t i=0) { return p_times[i]; }
479  float t(ssize_t i=0) const { return p_times(i); }
480 
481  /// return time of frame i in milli-seconds.
482  float ms_t(ssize_t i) const { return p_times(i) * 1000.0; }
483 
484  /** set frame times to regular intervals of time `t`.
485  The `start` parameter specifies the integer multiple of `t` at
486  which to start. For example, setting this to 0 will start at time
487  0.0 (The default means the first time value = `t`
488  */
489  void fill_time( float t, int start=1 );
490 
491  /** set frame times to regular intervals of time `t`.
492  The `start` parameter specifies the first time value.
493  */
494  void fill_time( float t, float start );
495 
496  /** fill time channel with times from another track
497  */
498  void fill_time( const EST_Track &t );
499 
500  /** fill all amplitudes with value `v` */
501  void fill(float v) { p_values.fill(v); }
502 
503  /** resample track at this frame shift, specified in seconds.
504  This can be used to change a variable frame spaced track into
505  a fixed frame track, or to change the spacing of an existing
506  evenly spaced track.
507  */
508  void sample(float shift);
509 
510  /// REDO
511  void change_type(float nshift, bool single_break);
512 
513  /** return an estimation of the frame spacing in seconds.
514  This returns -1 if the track is not a fixed shift track */
515  float shift() const;
516  /// return time of first value in track
517  float start() const;
518  /// return time of last value in track
519  float end() const;
520  //@}
521 
522  /** @name Auxiliary channels
523 
524  Auxiliary information is used to store information that goes
525  along with frames, but which are not amplitudes and hence
526  not appropriate for operations such as interpolation,
527  smoothing etc. The aux() array is an array of EST_Vals which
528  allows points to be int, float or a string.
529 
530  The following functions can be used to access to auxiliary
531  track information. Most of these functions can be used for
532  reading or writing to this point, thus
533 
534  tr.aux(10, "voicing") = 1;
535 
536  can be used to set the 10th frame of the "voicing" channel and
537 
538  cout << tr.a(10, "voicing");
539 
540  can be used to print the same information. Most of these functions
541  have a const equivalent for helping the compiler in
542  read only operations.
543 
544  Auxiliary channels are usually accessed by name rather than
545  numerical index. The names are set using the set_aux_channel_names()
546  function.
547  */
548 
549  //@{
550 
551  EST_Val &aux(ssize_t i, int c);
552  EST_Val &aux(ssize_t i, int c) const;
553 
554  EST_Val &aux(ssize_t i, const char *name);
555  EST_Val aux(ssize_t i, const char *name) const
556  { return ((EST_Track *)this)->aux(i, name); }
557 
559  { return aux(i, (const char *)name); }
560 
561  EST_Val aux(ssize_t i, EST_String name) const
562  { return ((EST_Track *)this)->aux(i, (const char *)name); }
563 
564  //@}
565 
566  /** @name File i/o functions
567  */
568 
569  //@{
570 
571  /** Load a file called `name` into the track.
572  The load function attempts to
573  automatically determine which file type is being loaded from the
574  file's header. If no header is found, the function assumes the
575  file is ascii data, with a fixed frame shift, arranged with rows
576  representing frames and columns channels. In this case, the
577  frame shift must be specified as an argument to this function.
578  For those file formats which don't contain provision for specifying
579  an initial time (e.g. HTK, or ascii...), the `startt` parameter
580  may be specified.
581  */
582  EST_read_status load(const EST_String name, float ishift = 0.0, float startt = 0.0);
583 
584  /** Load character data from an already opened tokenstream `ts`
585  into the track.
586  The load function attempts to
587  automatically determine which file type is being loaded from the
588  file's header. If no header is found, the function assumes the
589  file is ascii data, with a fixed frame shift, arranged with rows
590  representing frames and columns channels. In this case, the
591  frame shift must be specified as an argument to this function
592  For those file formats which don't contain provision for specifying
593  an initial time (e.g. HTK, or ascii...), the `startt` parameter
594  may be specified.
595  */
596  EST_read_status load(EST_TokenStream &ts, float ishift = 0.0, float startt = 0.0);
597 
598  /** Load a file called `name` of format `type`
599  into the track. If no header is found, the function assumes the
600  file is ascii data, with a fixed frame shift, arranged with rows
601  representing frames and columns channels. In this case, the
602  frame shift must be specified as an argument to this function
603  For those file formats which don't contain provision for specifying
604  an initial time (e.g. HTK, or ascii...), the `startt` parameter
605  may be specified.
606  */
607  EST_read_status load(const EST_String name, const EST_String type,
608  float ishift = 0.0, float startt = 0.0 );
609 
610  /** Save the track to a file `name` of format `type`. */
611  EST_write_status save(const EST_String name,
612  const EST_String EST_filetype = "");
613 
614  /** Save the track to a already opened file pointer`FP`
615  and write a file of format `type`. */
616  EST_write_status save(FILE *fp,
617  const EST_String EST_filetype = "");
618 
619  //@}
620 
621  /** @name Utility functions */
622 
623  //@{
624  /// returns true if no values are set in the frame
625  int empty() const;
626 
627  /// set frame i to be a break
628  void set_break(ssize_t i);
629  /// set frame i to be a value
630  void set_value(ssize_t i);
631  /// return true if frame i is a value
632  int val(ssize_t i) const;
633  /// return true if frame i is a break
634  int track_break(ssize_t i) const { return (p_is_val(i)); }
635 
636  /** starting at frame i, return the frame index of the first
637  value frame before i. If frame i is a value, return i */
638  ssize_t prev_non_break(ssize_t i) const;
639 
640  /** starting at frame i, return the frame index of the first
641  value frame after i. If frame i is a value, return i */
642  ssize_t next_non_break(ssize_t i) const;
643 
644  /// return the frame index nearest time t
645  ssize_t index(float t) const;
646 
647  /// return the frame index before time t
648  ssize_t index_below(float x) const;
649 
650  /// return number of frames in track
651  ssize_t num_frames() const {return p_values.num_rows();}
652 
653  /// return number of frames in track
654  ssize_t length() const { return num_frames(); }
655 
656  /// return number of channels in track
657  int num_channels() const {return p_values.num_columns();}
658 
659  /// return number of auxiliary channels in track
660  int num_aux_channels() const {return p_aux.num_columns();}
661 
662  void add_trailing_breaks();
663  void rm_trailing_breaks();
664  /** If the contour has multiple break values between sections
665  containing values, reduce the break sections so that each has
666  a single break only. */
667  void rm_excess_breaks();
668 
669  /// return true if track has equal (i.e. fixed) frame spacing */
670  bool equal_space() const {return p_equal_space;}
671 
672  /**return true if track has only single breaks between value sections */
673  bool single_break() const {return p_single_break;}
674 
675  void set_equal_space(bool t) {p_equal_space = t;}
676  void set_single_break(bool t) {p_single_break = t;}
677 
678 
679  //@}
680 
681 
682  EST_Track& operator = (const EST_Track& a);
683  EST_Track& operator+=(const EST_Track &a); // add to existing track
684  EST_Track& operator|=(const EST_Track &a); // add to existing track in parallel
685  friend std::ostream& operator << (std::ostream& s, const EST_Track &tr);
686 
687  // Default constructor
689 
690  // assign a known description to a track
691  void assign_map(EST_TrackMap::P map);
692  void assign_map(EST_TrackMap &map) { assign_map(&map); }
693 
694  // create a description for an unknown track
695  void create_map(EST_ChannelNameMap &names);
697 
698  EST_TrackMap::P map() const { return p_map; }
699 
700  int channel_position(EST_ChannelType type, int offset=0) const;
701 
702 
703 
704  // return amplitude of point i, channel type c (plus offset)
705  float &a(ssize_t i, EST_ChannelType c, int offset=0);
706  float a(ssize_t i, EST_ChannelType c, int offset=0) const
707  { return ((EST_Track *)this)->a(i,c, offset); }
708 
709  // return amplitude at time t, channel type c
710  float &a(float t, EST_ChannelType c, EST_InterpType interp=it_nearest);
711  float a(float t, EST_ChannelType c, EST_InterpType interp=it_nearest) const
712  { return ((EST_Track *)this)->a(t, c, interp); }
713 
714  float &operator() (ssize_t i, EST_ChannelType c) { return a(i,c); }
715  float operator() (ssize_t i, EST_ChannelType c) const { return a(i,c); }
716 
717  float &t_offset() { return p_t_offset; }
718  float t_offset() const { return p_t_offset; }
719 
720 
723 
724  const EST_String channel_name(int channel, const EST_ChannelNameMap &map, int strings_override=1) const;
725  const EST_String channel_name(int channel, int strings_override=1) const
726  { return channel_name(channel, EST_default_channel_names, strings_override); }
727 
728  const EST_String aux_channel_name(int channel) const
729  { return p_aux_names(channel);}
730 
731  void resize(ssize_t num_frames, EST_TrackMap &map);
732 
733  EST_TrackFileType file_type() const {return (EST_TrackFileType)f_Int("file_type",0);}
734 
735 
736  void set_file_type(EST_TrackFileType t) {f_set("file_type", (int)t);}
737 
738 
739  bool has_channel(EST_ChannelType type) const
740  { long signed int cp = (long signed int) channel_position(type);
741  return cp>=0; }
742 
743  // Frame iteration support
744 
745 protected:
746  class IPointer_f {
747  public:
749  IPointer_f();
750  IPointer_f(const IPointer_f &p);
751  ~IPointer_f();
752  };
753 
754  void point_to_first(IPointer_f &ip) const { ip.i = 0; }
755  void move_pointer_forwards(IPointer_f &ip) const { ip.i++; }
756  bool points_to_something(const IPointer_f &ip) const { return ip.i <num_frames(); }
757  EST_Track &points_at(const IPointer_f &ip) { sub_track(*(ip.frame), ip.i, 1);
758  return *(ip.frame); }
759 
762 
763 public:
764  typedef EST_Track Entry;
767 
768 };
769 
770 // list of tracks in serial
772 
773 
774 #endif /* __Track_H__ */
void default_channel_names()
Definition: EST_Track.cc:102
void move_pointer_forwards(IPointer_f &ip) const
Definition: EST_Track.h:755
bool single_break() const
Definition: EST_Track.h:673
EST_TrackMap::P p_map
Definition: EST_Track.h:102
void set_column(ssize_t n, const T *buf, ptrdiff_t offset=0, int num=-1)
Definition: EST_TMatrix.cc:478
void pad_breaks()
Definition: EST_Track.cc:916
int num_aux_channels() const
return number of auxiliary channels in track
Definition: EST_Track.h:660
float t_offset() const
Definition: EST_Track.h:718
void copy_frame_in(int n, const EST_FVector &t, int offset=0, int num=EST_ALL)
Definition: EST_Track.h:351
EST_Val aux(ssize_t i, EST_String name) const
Definition: EST_Track.h:561
bool p_equal_space
Definition: EST_Track.h:105
EST_Track & operator+=(const EST_Track &a)
Definition: EST_Track.cc:331
ssize_t prev_non_break(ssize_t i) const
Definition: EST_Track.cc:647
EST_ChannelType
EST_Val aux(ssize_t i, const char *name) const
Definition: EST_Track.h:555
EST_write_status
int channel_position(EST_String name, int offset=0) const
Definition: EST_Track.h:377
float end() const
return time of last value in track
Definition: EST_Track.cc:587
ssize_t length() const
return number of frames in track
Definition: EST_Track.h:654
void copy_frame_out(int n, EST_FVector &f, int offset=0, int num=EST_ALL) const
Definition: EST_Track.h:325
void copy_column(ssize_t c, T *buf, ptrdiff_t offset=0, int num=-1) const
Definition: EST_TMatrix.cc:420
void create_map(void)
Definition: EST_Track.h:696
ssize_t num_columns() const
return number of columns
Definition: EST_TMatrix.h:179
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
Definition: EST_FMatrix.h:119
void set_row(ssize_t n, const T *buf, ptrdiff_t offset=0, int num=-1)
Definition: EST_TMatrix.cc:466
void set_value(ssize_t i)
set frame i to be a value
Definition: EST_Track.cc:133
void set_channel_name(const EST_String &name, int channel)
set the name of the channel.
Definition: EST_Track.cc:168
EST_Track & operator=(const EST_Track &a)
Definition: EST_Track.cc:388
void set_break(ssize_t i)
set frame i to be a break
Definition: EST_Track.cc:124
EST_String name() const
name of track - redundant use access to features
Definition: EST_Track.h:196
bool points_to_something(const IPointer_f &ip) const
Definition: EST_Track.h:756
int num_channels() const
return number of channels in track
Definition: EST_Track.h:657
EST_Track & points_at(const IPointer_f &ip)
Definition: EST_Track.h:757
void set_single_break(bool t)
Definition: EST_Track.h:676
float a(ssize_t i, EST_ChannelType c, int offset=0) const
Definition: EST_Track.h:706
EST_TrackFileType file_type() const
Definition: EST_Track.h:733
bool has_channel(EST_ChannelType type) const
Definition: EST_Track.h:739
float & operator()(ssize_t i, int c)
Definition: EST_Track.h:456
ssize_t index_below(float x) const
return the frame index before time t
Definition: EST_Track.cc:521
const int EST_CURRENT
ssize_t num_rows() const
return number of rows
Definition: EST_TMatrix.h:177
int ssize_t
EST_TIterator< EST_Track, IPointer_f, EST_Track > Entries
Definition: EST_Track.h:765
EST_TList< EST_Track > EST_TrackList
Definition: EST_Track.h:771
void set_num_channels(int n, bool preserve=1)
Definition: EST_Track.h:170
const int EST_ALL
void resize(ssize_t num_frames, int num_channels, bool preserve=1)
Definition: EST_Track.cc:214
float & a_no_check(ssize_t i, int c=0)
Definition: EST_Track.h:420
float a_no_check(ssize_t i, int c=0) const
Definition: EST_Track.h:421
EST_TMatrix< EST_Val > EST_ValMatrix
Definition: EST_Track.h:41
void column(EST_TVector< T > &cv, ssize_t c, ssize_t start_r=0, int len=-1)
Make the vector cv a window onto column c
Definition: EST_TMatrix.cc:556
ssize_t index(float t) const
return the frame index nearest time t
Definition: EST_Track.cc:473
static const float default_frame_shift
Definition: EST_Track.h:119
EST_TrackFileType
Definition: EST_Track.h:58
void sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL)
Definition: EST_Track.cc:1100
EST_read_status load_channel_names(const EST_String name)
Definition: EST_Track.cc:1385
float interp_amp(float x, int c, float f)
Definition: EST_Track.cc:705
void copy(const EST_Track &a)
Definition: EST_Track.cc:194
int track_break(ssize_t i) const
return true if frame i is a break
Definition: EST_Track.h:634
EST_Track Entry
Definition: EST_Track.h:764
int channel_position(const char *name, int offset=0) const
Definition: EST_Track.cc:395
void assign_map(EST_TrackMap::P map)
Definition: EST_Track.cc:1426
float t(ssize_t i=0) const
Definition: EST_Track.h:479
void fill(const T &v)
fill matrix with value v
Definition: EST_TMatrix.cc:314
EST_read_status load(const EST_String name, float ishift=0.0, float startt=0.0)
Definition: EST_Track.cc:1312
void clear_arrays()
void set_num_frames(ssize_t n, bool preserve=1)
Definition: EST_Track.h:178
bool equal_space() const
return true if track has equal (i.e. fixed) frame spacing */
Definition: EST_Track.h:670
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
EST_InterpType
Definition: EST_Track.h:79
void copy_setup(const EST_Track &a)
copy everything but data
Definition: EST_Track.cc:205
ssize_t next_non_break(ssize_t i) const
Definition: EST_Track.cc:632
~EST_Track()
default destructor
Definition: EST_Track.cc:97
static const int default_sample_rate
Definition: EST_Track.h:120
EST_FVector p_times
Definition: EST_Track.h:94
void default_vals()
Definition: EST_Track.cc:108
void set_file_type(EST_TrackFileType t)
Definition: EST_Track.h:736
float a(float t, int c=0, EST_InterpType interp=it_nearest) const
Definition: EST_Track.h:451
void set_name(const EST_String &n)
set name of track - redundant use access to features
Definition: EST_Track.h:199
void copy_channel_in(int n, const EST_FVector &f, int offset=0, int num=EST_ALL)
Definition: EST_Track.h:334
EST_TRwIterator< EST_Track, IPointer_f, EST_Track > RwEntries
Definition: EST_Track.h:766
friend std::ostream & operator<<(std::ostream &s, const EST_Track &tr)
void copy_channel_out(int n, EST_FVector &f, int offset=0, int num=EST_ALL) const
Definition: EST_Track.h:316
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1233
void copy_channel_out(int n, float *buf, int offset=0, int num=EST_ALL) const
Definition: EST_Track.h:311
EST_ValMatrix p_aux
Definition: EST_Track.h:97
bool p_single_break
Definition: EST_Track.h:106
void change_type(float nshift, bool single_break)
REDO.
Definition: EST_Track.cc:656
void resize_aux(EST_StrList &map, bool preserve=1)
Definition: EST_Track.cc:314
float & t_offset()
Definition: EST_Track.h:717
void copy_frame_in(ssize_t i, const EST_Track &from, int from_f, int from_offset=0, int offset=0, int num=EST_ALL)
Definition: EST_Track.h:356
void channel(EST_FVector &cv, ssize_t n, int startf=0, int nf=EST_ALL)
Definition: EST_Track.h:215
f
Definition: EST_item_aux.cc:48
void rm_excess_breaks()
Definition: EST_Track.cc:813
bool has_channel(EST_String name) const
Definition: EST_Track.h:391
void sample(float shift)
Definition: EST_Track.cc:674
ssize_t num_frames() const
return number of frames in track
Definition: EST_Track.h:651
void copy_frame_out(int n, float *buf, int offset=0, int num=EST_ALL) const
Definition: EST_Track.h:321
EST_Track * frame
Definition: EST_Track.h:748
float a(float t, EST_ChannelType c, EST_InterpType interp=it_nearest) const
Definition: EST_Track.h:711
float p_t_offset
Definition: EST_Track.h:100
getString int
Definition: EST_item_aux.cc:50
void row(EST_TVector< T > &rv, ssize_t r, ssize_t start_c=0, int len=-1)
Make the vector rv a window onto row r
Definition: EST_TMatrix.cc:534
EST_Track()
Default constructor.
Definition: EST_Track.cc:57
float start() const
return time of first value in track
Definition: EST_Track.cc:594
void copy_row(ssize_t r, T *buf, ptrdiff_t offset=0, int num=-1) const
Definition: EST_TMatrix.cc:381
void assign_map(EST_TrackMap &map)
Definition: EST_Track.h:692
EST_FMatrix p_values
Definition: EST_Track.h:93
void copy_frame_in(int n, const float *buf, int offset=0, int num=EST_ALL)
Definition: EST_Track.h:346
void add_trailing_breaks()
Definition: EST_Track.cc:878
EST_CVector p_is_val
Definition: EST_Track.h:95
const EST_String channel_name(int channel, const EST_ChannelNameMap &map, int strings_override=1) const
Definition: EST_Track.cc:138
float estimate_shift(float x)
Definition: EST_Track.cc:771
void copy_channel_in(int n, const float *buf, int offset=0, int num=EST_ALL)
Definition: EST_Track.h:329
void point_to_first(IPointer_f &ip) const
Definition: EST_Track.h:754
EST_ChannelNameMap EST_default_channel_names
Definition of standard names we use for channels.
void fill(float v)
Definition: EST_Track.h:501
EST_read_status
EST_write_status save_channel_names(const EST_String name)
Definition: EST_Track.cc:1370
const EST_String channel_name(int channel, int strings_override=1) const
Definition: EST_Track.h:725
void set_aux_channel_name(const EST_String &name, int channel)
set the name of the auxiliary channel.
Definition: EST_Track.cc:173
float a(ssize_t i, EST_String name, int offset=0) const
Definition: EST_Track.h:436
void copy_sub_track_out(EST_Track &st, const EST_FVector &frame_times) const
Definition: EST_Track.cc:1178
EST_Val & aux(ssize_t i, int c)
Definition: EST_Track.cc:428
EST_StrVector p_aux_names
Definition: EST_Track.h:98
int interp_value(float x, float f)
Definition: EST_Track.cc:737
void rm_trailing_breaks()
Definition: EST_Track.cc:847
int val(ssize_t i) const
return true if frame i is a value
Definition: EST_Track.cc:542
float shift() const
Definition: EST_Track.cc:602
INLINE const T & a_no_check(ssize_t row, ssize_t col) const
const access with no bounds check, care recommend
Definition: EST_TMatrix.h:182
EST_Val & aux(ssize_t i, EST_String name)
Definition: EST_Track.h:558
int empty() const
returns true if no values are set in the frame
Definition: EST_Track.cc:1038
LISP fp
Definition: kkcompile.cc:63
bool has_channel(const char *name) const
Definition: EST_Track.h:385
void frame(EST_FVector &fv, int n, int startf=0, int nf=EST_ALL)
Definition: EST_Track.h:210
void set_equal_space(bool t)
Definition: EST_Track.h:675
EST_Track & operator|=(const EST_Track &a)
Definition: EST_Track.cc:362
EST_StrVector p_channel_names
Definition: EST_Track.h:103
float ms_t(ssize_t i) const
return time of frame i in milli-seconds.
Definition: EST_Track.h:482
float & a(ssize_t i, EST_String name, int offset=0)
Definition: EST_Track.h:434
void fill_time(float t, int start=1)
Definition: EST_Track.cc:789
void copy_channel_in(int c, const EST_Track &from, int from_c, int from_offset=0, int offset=0, int num=EST_ALL)
Definition: EST_Track.h:339
void copy_sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL) const
Definition: EST_Track.cc:1139
const EST_String aux_channel_name(int channel) const
Definition: EST_Track.h:728
float a(ssize_t i, const char *name, int offset=0) const
Definition: EST_Track.h:432
EST_TrackMap::P map() const
Definition: EST_Track.h:698
void sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL) const
Definition: EST_Track.h:286