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  /*                 Author: Richard Caley (rjc@cstr.ed.ac.uk)            */
34  /*                   Date: Fri May  9 1997                              */
35  /************************************************************************/
36  /*                                                                      */
37  /* Track maps provide a mapping from symbolic track names to the        */
38  /* actual position of the information within a track frame.             */
39  /*                                                                      */
40  /* Channel name maps map textual names for track channels to symbolic   */
41  /* names, they are just a special case of named enums.                  */
42  /*                                                                      */
43  /************************************************************************/
44 
45 #include "EST_TrackMap.h"
46 
clear(void)47 void EST_TrackMap::clear(void)
48 {
49   for(int i=0; i<num_channel_types; i++)
50     p_map[i]=NO_SUCH_CHANNEL;
51 }
52 
copy(EST_TrackMap & from)53 void EST_TrackMap::copy(EST_TrackMap &from)
54 {
55   for(int i=0; i<num_channel_types; i++)
56     p_map[i]=from.p_map[i];
57 }
58 
59 
init(void)60 void EST_TrackMap::init(void)
61 {
62 clear();
63 p_parent=NULL;
64 p_offset=0;
65 }
66 
EST_TrackMap(void)67 EST_TrackMap::EST_TrackMap(void)
68 {
69   init();
70 }
71 
72 
EST_TrackMap(int refcount)73 EST_TrackMap::EST_TrackMap(int refcount)
74 {
75   init();
76   if (refcount)
77     start_refcounting();
78 }
79 
EST_TrackMap(const EST_TrackMap * parent,int offset,int refcount)80 EST_TrackMap::EST_TrackMap(const EST_TrackMap *parent, int offset, int refcount)
81 {
82   init();
83   p_parent = (EST_TrackMap *)parent;
84   p_offset=offset;
85   if (refcount)
86     start_refcounting();
87 }
88 
EST_TrackMap(EST_TrackMap & from,int refcount)89 EST_TrackMap::EST_TrackMap(EST_TrackMap &from, int refcount)
90 {
91   copy(from);
92   if (refcount)
93     start_refcounting();
94 }
95 
EST_TrackMap(struct EST_TrackMap::ChannelMappingElement map[])96 EST_TrackMap::EST_TrackMap(struct EST_TrackMap::ChannelMappingElement map[])
97 {
98   init();
99 
100   int i;
101   for(i=0; map[i].type != channel_unknown; i++)
102     set(map[i].type, map[i].channel);
103 }
104 
~EST_TrackMap()105 EST_TrackMap::~EST_TrackMap()
106 {
107 }
108 
get_parent(EST_ChannelType type) const109 short EST_TrackMap::get_parent(EST_ChannelType type) const
110 {
111   short c= NO_SUCH_CHANNEL;
112   if (p_parent!=0)
113     {
114       c = p_parent->get(type);
115       if (c != NO_SUCH_CHANNEL)
116 	c -= p_offset;
117     }
118   return c;
119 }
120 
channel_type(unsigned short channel) const121 EST_ChannelType EST_TrackMap::channel_type(unsigned short channel) const
122 {
123   unsigned short i;
124 
125   for(i=0; i<num_channel_types;i++)
126     if (p_map[i] == channel)
127       return (EST_ChannelType)i;
128 
129   if (p_parent!=0)
130     return p_parent->channel_type(channel+p_offset);
131 
132   return channel_unknown;
133 }
134 
last_channel(void) const135 short EST_TrackMap::last_channel(void) const
136 {
137   short last = -1;
138   for(short i=0; i<num_channel_types;i++)
139     if (p_map[i]> last)
140       last = p_map[i];
141   return last;
142 }
143 
144 
145 static EST_TValuedEnumDefinition<EST_ChannelType, const char *, NO_INFO> channel_name_tbl[] = {
146   { channel_unknown,	{ "Unknown" }},
147   { channel_order,	{ "Order" }},
148   { channel_power,	{ "power", "Power", "raw_power"}},
149   { channel_power_d,	{ "power_d", "Power_d", "raw_power_d"}},
150   { channel_power_a,	{ "power_a", "Power_a", "raw_power_a"}},
151   { channel_energy,	{ "energy", "Energy"}},
152   { channel_energy_d,	{ "energy_d", "Energy_d"}},
153   { channel_energy_a,	{ "energy_a", "Energy_a"}},
154   { channel_peak,	{ "Peak", "ac_peak" }},
155   { channel_duration,	{ "Duration" }},
156   { channel_length,	{ "Length", "frame_len"}},
157   { channel_offset,	{ "Offset", "frame_offset"}},
158   { channel_f0,		{ "f0", "F0" }},
159   { channel_f0_d,	{ "f0_d", "F0_d" }},
160   { channel_f0_a,	{ "f0_a", "F0_a" }},
161   { channel_voiced,	{ "Voiced", "prob_voice"}},
162   { channel_frame,	{ "Frame"}},
163   { channel_time,	{ "Time"}},
164   { channel_lpc_0,	{ "lpc_0", "Lpc_0"}},
165   { channel_lpc_N,	{ "lpc_N", "Lpc_N"}},
166   { channel_lpc_d_0,	{ "lpc_d_0"}},
167   { channel_lpc_d_N,	{ "lpc_d_N"}},
168   { channel_lpc_a_0,	{ "lpc_a_0"}},
169   { channel_lpc_a_N,	{ "lpc_a_N"}},
170   { channel_cepstrum_0,	{ "cep_0"}},
171   { channel_cepstrum_N,	{ "cep_N"}},
172   { channel_cepstrum_d_0,	{ "cep_d_0"}},
173   { channel_cepstrum_d_N,	{ "cep_d_N"}},
174   { channel_cepstrum_a_0,	{ "cep_a_0"}},
175   { channel_cepstrum_a_N,	{ "cep_a_N"}},
176   { channel_melcepstrum_0,	{ "melcep_0"}},
177   { channel_melcepstrum_N,	{ "melcep_N"}},
178   { channel_melcepstrum_d_0,	{ "melcep_d_0"}},
179   { channel_melcepstrum_d_N,	{ "melcep_d_N"}},
180   { channel_melcepstrum_a_0,	{ "melcep_a_0"}},
181   { channel_melcepstrum_a_N,	{ "melcep_a_N"}},
182   { channel_lsf_0,	{ "lsf_0"}},
183   { channel_lsf_N,	{ "lsf_N"}},
184   { channel_lsf_d_0,	{ "lsf_d_0"}},
185   { channel_lsf_d_N,	{ "lsf_d_N"}},
186   { channel_lsf_a_0,	{ "lsf_a_0"}},
187   { channel_lsf_a_N,	{ "lsf_a_N"}},
188   { channel_fbank_0,	{ "fbank_0"}},
189   { channel_fbank_N,	{ "fbank_N"}},
190   { channel_fbank_d_0,	{ "fbank_d_0"}},
191   { channel_fbank_d_N,	{ "fbank_d_N"}},
192   { channel_fbank_a_0,	{ "fbank_a_0"}},
193   { channel_fbank_a_N,	{ "fbank_a_N"}},
194   { channel_filter_0,	{ "filter_0"}},
195   { channel_filter_N,	{ "filter_N"}},
196   { channel_filter_d_0,	{ "filter_d_0"}},
197   { channel_filter_d_N,	{ "filter_d_N"}},
198   { channel_filter_a_0,	{ "filter_a_0"}},
199   { channel_filter_a_N,	{ "filter_a_N"}},
200   { channel_reflection_0,	{ "reflection_0"}},
201   { channel_reflection_N,	{ "reflection_N"}},
202   { channel_reflection_d_0,	{ "reflection_d_0"}},
203   { channel_reflection_d_N,	{ "reflection_d_N"}},
204   { channel_reflection_a_0,	{ "reflection_a_0"}},
205   { channel_reflection_a_N,	{ "reflection_a_N"}},
206   { channel_unknown,	{ NULL }}
207 };
208 
209 EST_ChannelNameMap EST_default_channel_names(channel_name_tbl);
210 
211 static EST_TValuedEnumDefinition<EST_ChannelType, const char *, NO_INFO> esps_channel_name_tbl[] = {
212   { channel_unknown,	{ "Unknown" }},
213   { channel_order,	{ "Order" }},
214   { channel_power,	{ "raw_power", "rms" }},
215   { channel_peak,	{ "ac_peak" }},
216   { channel_duration,	{ "Duration" }},
217   { channel_length,	{ "frame_len"}},
218   { channel_f0,		{ "F0" }},
219   { channel_voiced,	{ "prob_voice"}},
220   { channel_lpc_0,	{ "lpc_0", "spec_param" }},
221   { channel_lpc_N,	{ "lpc_N"}},
222   //   { channel_coef0,	{ "spec_param" }},
223   { channel_unknown,	{ NULL }}
224 };
225 
226 EST_ChannelNameMap esps_channel_names(esps_channel_name_tbl);
227 
228 #if defined(INSTANTIATE_TEMPLATES)
229 
230 #include "../base_class/EST_TNamedEnum.cc"
231 
232 template class EST_TNamedEnum<EST_ChannelType>;
233 template class EST_TNamedEnumI<EST_ChannelType, NO_INFO>;
234 template class EST_TValuedEnum<EST_ChannelType,const char *>;
235 template class EST_TValuedEnumI<EST_ChannelType,const char *, NO_INFO>;
236 
237 template class EST_THandle<EST_TrackMap,EST_TrackMap>;
238 
239 #endif
240