Debian Codegraph @

tools/VOICE_clunits.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 1999-2000 */
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: April 2001 */
35 /*************************************************************************/
36 /* */
37 /* A simple clunits/ldom voice defintion */
38 /* */
39 /*************************************************************************/
40
41 #include <string.h>
42 #include "flite.h"
43 #include "cst_clunits.h"
44 #include "__FLITELANG__.h"
45 #include "__FLITELEX__.h"
46
47 static char *__VOICENAME___unit_name(cst_item *s);
48
49 extern cst_clunit_db __VOICENAME___db;
50 cst_voice *__VOICENAME___clunits = NULL;
51
52 extern const cst_cart __VOICENAME___dur_cart;
53 extern const dur_stat * const __VOICENAME___dur_stats[];
54
55 cst_voice *register___VOICENAME__(const char *voxdir)
56 {
57 cst_voice *v;
58 cst_lexicon *lex;
59
60 if (__VOICENAME___clunits)
61 return __VOICENAME___clunits; /* Already registered */
62
63 v = new_voice();
64 v->name = "__NICKNAME__";
65
66 /* Sets up language specific parameters in the __VOICENAME__. */
67 __FLITELANG___init(v);
68
69 /* Things that weren't filled in already. */
70 flite_feat_set_string(v->features,"name","__VOICENAME__");
71
72 /* Duration model */
73 flite_feat_set(v->features,"dur_cart",cart_val(&__VOICENAME___dur_cart));
74 flite_feat_set(v->features,"dur_stats",dur_stats_val((dur_stats *)__VOICENAME___dur_stats));
75
76 /* Lexicon */
77 lex = __FLITELEX___init();
78 flite_feat_set(v->features,"lexicon",lexicon_val(lex));
79 flite_feat_set(v->features,"postlex_func",uttfunc_val(lex->postlex));
80
81 /* Waveform synthesis */
82 flite_feat_set(v->features,"wave_synth_func",uttfunc_val(&clunits_synth));
83 flite_feat_set(v->features,"clunit_db",clunit_db_val(&__VOICENAME___db));
84 flite_feat_set_int(v->features,"sample_rate",__VOICENAME___db.sts->sample_rate);
85 flite_feat_set_string(v->features,"join_type","simple_join");
86 flite_feat_set_string(v->features,"resynth_type","fixed");
87
88 if ((voxdir != NULL) &&
89 (__VOICENAME___db.sts->sts == NULL) &&
90 (__VOICENAME___db.sts->sts_paged == NULL) &&
91 (__VOICENAME___db.sts->frames == NULL))
92 flite_mmap_clunit_voxdata(voxdir,v);
93
94 /* Unit selection */
95 __VOICENAME___db.unit_name_func = __VOICENAME___unit_name;
96
97 __VOICENAME___clunits = v;
98
99 return __VOICENAME___clunits;
100 }
101
102 void unregister___VOICENAME__(cst_voice *vox)
103 {
104 if (vox != __VOICENAME___clunits)
105 return;
106 delete_voice(vox);
107 __VOICENAME___clunits = NULL;
108 }
109
110 static const char *__VOICENAME___nextvoicing(cst_item *s)
111 {
112 if (cst_streq("+",flite_ffeature_string(s,"n.ph_vc")))
113 return "V";
114 else if (cst_streq("+",flite_ffeature_string(s,"n.ph_cvox")))
115 return "CVox";
116 else
117 return "UV";
118 }
119
120 static char *__VOICENAME___unit_name(cst_item *s)
121 {
122 const char *name;
123 /* This *is* long enough as long as you don't change external things */
124 char cname[30];
125
126 name = flite_ffeature_string(s,"name");
127 /* Comment this out if you have more complex unit names */
128 #if 1
129 if (1 == 1)
130 return cst_strdup(name);
131 else
132 #endif
133 if (cst_streq("+",flite_ffeature_string(s,"ph_vc")))
134 {
135 cst_sprintf(cname,"%s_%s_%s",name,
136 flite_ffeature_string(s,"R:SylStructure.parent.stress"),
137 __VOICENAME___nextvoicing(s));
138 }
139 else
140 {
141 cst_sprintf(cname,"%s_%s",name,
142 __VOICENAME___nextvoicing(s));
143 }
144
145 return cst_strdup(cname);
146 }