Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
EST_TTimeIndex.cc
1 /************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
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: Richard Caley (rjc@cstr.ed.ac.uk) */
35 /* Date: Wed Mar 25 1998 */
36 /* -------------------------------------------------------------------- */
37 /* Indexing a container by time. */
38 /* */
39 /*************************************************************************/
40
41#include "EST_TTimeIndex.h"
42
43template<class CONTAINER>
45{
46 p_time_step=0;
47 p_entries.resize(0);
48}
49
50template<class CONTAINER>
52{
53 initialise();
54}
55
56
57template<class CONTAINER>
58EST_TTimeIndex<CONTAINER>::EST_TTimeIndex(CONTAINER &c, int bunch)
59{
60 initialise();
61 index(c, bunch);
62}
63
64template<class CONTAINER>
65void EST_TTimeIndex<CONTAINER>::index(CONTAINER &c, int bunch)
66{
67 int n_objects = c.length();
68 float total_time = c.end();
69
70 int n_buckets = n_objects/bunch +1;
71
72 p_time_step = total_time / n_buckets;
73 p_entries.resize(n_buckets);
74 p_container = &c;
75
76 Index i;
77
78 i=c.first_index();
79 p_entries[0].t = 0.0;
80 p_entries[0].i = i;
81
82 for(; c.valid_index(i); i=c.next_index(i))
83 {
84 float t = c.time_of(i);
85 int b = (int)(t/p_time_step);
86 if (b>=p_entries.num_columns())
87 b = p_entries.num_columns()-1;
88 for (int bb=b+1; bb < n_buckets ; bb++)
89 if ( t > p_entries(bb).t )
90 {
91 p_entries[bb].t = t;
92 p_entries[bb].i = i;
93 }
94 else
95 break;
96 }
97}
98
99template<class CONTAINER>
101 void *inp) const
102{
103 CONTAINER::Index &in(*(Index *)inp);
104 in= CONTAINER::bad_index();
105
106 if (p_container==NULL)
107 return;
108
109 int b = (int)(t/p_time_step);
110
111 if (b>=p_entries.num_columns())
112 b = p_entries.num_columns()-1;
113
114 Index i = p_entries(b).i;
115
116 for(Index j=i; p_container->valid_index(j); j = p_container->next_index(j))
117 {
118 if (p_container->time_of(j) > t)
119 {
120 in=i;
121 return;
122 }
123 i=j;
124 }
125 in =i;
126 return;
127}
128
129template<class CONTAINER>
130int operator !=(const EST_TTI_Entry<CONTAINER> &e1,
131 const EST_TTI_Entry<CONTAINER> &e2)
132{ (void)e1; (void)e2; return 1; }
133
134template<class CONTAINER>
135ostream& operator <<(ostream &s,
137{ (void)e; return s << "entry"; }