Debian Codegraph @

src/synth/cst_phoneset.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 1999 */
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 /* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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: Alan W Black ([email protected]) */
34 /* Date: December 2000 */
35 /*************************************************************************/
36 /* */
37 /* Voice definition */
38 /* */
39 /*************************************************************************/
40 #include "cst_val.h"
41 #include "cst_utterance.h"
42 #include "cst_item.h"
43 #include "cst_phoneset.h"
44
45 CST_VAL_REGISTER_TYPE_NODEL(phoneset,cst_phoneset)
46
47 cst_phoneset *new_phoneset()
48 {
49 /* These aren't going to be supported dynamically */
50 cst_phoneset *v = cst_alloc(struct cst_phoneset_struct,1);
51
52 v->freeable = 1;
53 return v;
54 }
55
56 void delete_phoneset(const cst_phoneset *v)
57 {
58 int i;
59
60 if (v && v->freeable)
61 {
62 for (i=0; v->featnames[i]; i++)
63 cst_free((void *)v->featnames[i]);
64 cst_free((void *)v->featnames);
65 for (i=0; v->featvals[i]; i++)
66 delete_val((cst_val *)(void *)v->featvals[i]);
67 cst_free((void *)v->featvals);
68 for (i=0; v->phonenames[i]; i++)
69 cst_free((void *)v->phonenames[i]);
70 cst_free((void *)v->phonenames);
71 cst_free((void *)v->silence);
72 for (i=0; v->fvtable[i]; i++)
73 cst_free((void *)v->fvtable[i]);
74 cst_free((void *)v->fvtable);
75 cst_free((void *)v);
76 }
77 }
78
79 int phone_id(const cst_phoneset *ps,const char* phonename)
80 {
81 int i;
82
83 for (i=0; i< ps->num_phones; i++)
84 if (cst_streq(ps->phonenames[i],phonename))
85 return i;
86 /* Wonder if I should print an error here or not */
87 /* printf("awb_debug cst_phoneset.c phone_id unknown phone %s\n",phonename); */
88
89 return 0;
90 }
91
92 int phone_feat_id(const cst_phoneset *ps,const char* featname)
93 {
94 int i;
95
96 for (i=0; ps->featnames[i]; i++)
97 if (cst_streq(ps->featnames[i],featname))
98 return i;
99
100 /* Wonder if I should print an error here or not */
101 return 0;
102 }
103
104 const cst_val *phone_feature(const cst_phoneset *ps,
105 const char* phonename,
106 const char *featname)
107 {
108 return ps->featvals[ps->fvtable[phone_id(ps,phonename)]
109 [phone_feat_id(ps,featname)]];
110 }
111
112 const char *phone_feature_string(const cst_phoneset *ps,
113 const char* phonename,
114 const char *featname)
115 {
116 return val_string(phone_feature(ps,phonename,featname));
117 }
118
119
120 const cst_phoneset *item_phoneset(const cst_item *p)
121 {
122 return val_phoneset(feat_val(item_utt(p)->features,"phoneset"));
123 }
124
125