Debian Codegraph @

src/cg/cst_mlpg.h

raw
1 /* --------------------------------------------------------------- */
2 /* The HMM-Based Speech Synthesis System (HTS): version 1.1.1 */
3 /* HTS Working Group */
4 /* */
5 /* Department of Computer Science */
6 /* Nagoya Institute of Technology */
7 /* and */
8 /* Interdisciplinary Graduate School of Science and Engineering */
9 /* Tokyo Institute of Technology */
10 /* Copyright (c) 2001-2003 */
11 /* All Rights Reserved. */
12 /* */
13 /* Permission is hereby granted, free of charge, to use and */
14 /* distribute this software and its documentation without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of this work, and to permit persons to whom this */
18 /* work is furnished to do so, subject to the following conditions: */
19 /* */
20 /* 1. The code must retain the above copyright notice, this list */
21 /* of conditions and the following disclaimer. */
22 /* */
23 /* 2. Any modifications must be clearly marked as such. */
24 /* */
25 /* NAGOYA INSTITUTE OF TECHNOLOGY, TOKYO INSITITUTE OF TECHNOLOGY, */
26 /* HTS WORKING GROUP, AND THE CONTRIBUTORS TO THIS WORK DISCLAIM */
27 /* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL */
28 /* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
29 /* SHALL NAGOYA INSTITUTE OF TECHNOLOGY, TOKYO INSITITUTE OF */
30 /* TECHNOLOGY, HTS WORKING GROUP, NOR THE CONTRIBUTORS BE LIABLE */
31 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY */
32 /* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, */
33 /* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS */
34 /* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR */
35 /* PERFORMANCE OF THIS SOFTWARE. */
36 /* */
37 /* --------------------------------------------------------------- */
38 /* mlpg.c : speech parameter generation from pdf sequence */
39 /* */
40 /* 2003/12/26 by Heiga Zen */
41 /* --------------------------------------------------------------- */
42
43 /*********************************************************************/
44 /* */
45 /* Nagoya Institute of Technology, Aichi, Japan, */
46 /* and */
47 /* Carnegie Mellon University, Pittsburgh, PA */
48 /* Copyright (c) 2003-2004 */
49 /* All Rights Reserved. */
50 /* */
51 /* Permission is hereby granted, free of charge, to use and */
52 /* distribute this software and its documentation without */
53 /* restriction, including without limitation the rights to use, */
54 /* copy, modify, merge, publish, distribute, sublicense, and/or */
55 /* sell copies of this work, and to permit persons to whom this */
56 /* work is furnished to do so, subject to the following conditions: */
57 /* */
58 /* 1. The code must retain the above copyright notice, this list */
59 /* of conditions and the following disclaimer. */
60 /* 2. Any modifications must be clearly marked as such. */
61 /* 3. Original authors' names are not deleted. */
62 /* */
63 /* NAGOYA INSTITUTE OF TECHNOLOGY, CARNEGIE MELLON UNIVERSITY, AND */
64 /* THE CONTRIBUTORS TO THIS WORK DISCLAIM ALL WARRANTIES WITH */
65 /* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF */
66 /* MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NAGOYA INSTITUTE */
67 /* OF TECHNOLOGY, CARNEGIE MELLON UNIVERSITY, NOR THE CONTRIBUTORS */
68 /* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR */
69 /* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR */
70 /* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER */
71 /* TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE */
72 /* OR PERFORMANCE OF THIS SOFTWARE. */
73 /* */
74 /*********************************************************************/
75 /* */
76 /* ML-Based Parameter Generation */
77 /* 2003/12/26 by Heiga Zen */
78 /* */
79 /* Basic functions are extracted from HTS and */
80 /* modified by Tomoki Toda ([email protected]) */
81 /* June 2004 */
82 /* Integrate as a Voice Conversion module */
83 /* */
84 /*-------------------------------------------------------------------*/
85 /* */
86 /* Author : Tomoki Toda ([email protected]) */
87 /* Date : June 2004 */
88 /* */
89 /*-------------------------------------------------------------------*/
90 /* Integrated into a single C file for festival/flite integration */
91 /* May 2008 [email protected] */
92 /*-------------------------------------------------------------------*/
93
94 #ifndef _MLPG_H
95 #define _MLPG_H
96
97 #include "cst_cg.h"
98
99 #define LENGTH 256
100 #define INFTY ((double) 1.0e+38)
101 #define INFTY2 ((double) 1.0e+19)
102 #define INVINF ((double) 1.0e-38)
103 #define INVINF2 ((double) 1.0e-19)
104
105 #ifdef M_PI
106 #define PI M_PI
107 #else
108 #define PI 3.1415926535897932385
109 #endif
110
111 #define WLEFT 0
112 #define WRIGHT 1
113
114 typedef struct _DWin {
115 int num; /* number of static + deltas */
116 int **width; /* width [0..num-1][0(left) 1(right)] */
117 double **coef; /* coefficient [0..num-1][length[0]..length[1]] */
118 double **coef_ptrs; /* keeps the pointers so we can free them */
119 int maxw[2]; /* max width [0(left) 1(right)] */
120 } DWin;
121
122 typedef struct _PStreamChol {
123 int vSize; /* size of ovserved vector */
124 int order; /* order of cepstrum */
125 int T; /* number of frames */
126 int width; /* width of WSW */
127 DWin dw;
128 double **mseq; /* sequence of mean vector */
129 double **ivseq; /* sequence of invarsed covariance vector */
130 double ***ifvseq; /* sequence of invarsed full covariance vector */
131 double **R; /* WSW[T][range] */
132 double *r; /* WSM [T] */
133 double *g; /* g [T] */
134 double **c; /* parameter c */
135 } PStreamChol;
136
137
138 typedef struct MLPGPARA_STRUCT {
139 DVECTOR ov;
140 DVECTOR iuv;
141 DVECTOR iumv;
142 DVECTOR flkv;
143 DMATRIX stm;
144 DMATRIX dltm;
145 DMATRIX pdf;
146 DVECTOR detvec;
147 DMATRIX wght;
148 DMATRIX mean;
149 DMATRIX cov;
150 LVECTOR clsidxv;
151 DVECTOR clsdetv;
152 DMATRIX clscov;
153 double vdet;
154 DVECTOR vm;
155 DVECTOR vv;
156 DVECTOR var;
157 } *MLPGPARA;
158
159 static MLPGPARA xmlpgpara_init(int dim, int dim2, int dnum, int clsnum);
160 static void xmlpgparafree(MLPGPARA param);
161 static double get_like_pdfseq_vit(int dim, int dim2, int dnum, int clsnum,
162 MLPGPARA param,
163 float **model,
164 XBOOL dia_flag);
165 #if 0
166 static double get_like_gv(long dim2, long dnum, MLPGPARA param);
167 static void sm_mvav(DMATRIX mat, long hlen);
168 #endif
169 static void get_dltmat(DMATRIX mat, DWin *dw, int dno, DMATRIX dmat);
170
171
172 static double *dcalloc(int x, int xoff);
173 static double **ddcalloc(int x, int y, int xoff, int yoff);
174
175 /***********************************/
176 /* ML using Choleski decomposition */
177 /***********************************/
178 /* Diagonal Covariance Version */
179 static void InitDWin(PStreamChol *pst, const float *dynwin, int fsize);
180 static void InitPStreamChol(PStreamChol *pst, const float *dynwin, int fsize,
181 int order, int T);
182 static void mlgparaChol(DMATRIX pdf, PStreamChol *pst, DMATRIX mlgp);
183 static void mlpgChol(PStreamChol *pst);
184 static void calc_R_and_r(PStreamChol *pst, const int m);
185 static void Choleski(PStreamChol *pst);
186 static void Choleski_forward(PStreamChol *pst);
187 static void Choleski_backward(PStreamChol *pst, const int m);
188 #if 0
189 /* Full Covariance Version */
190 static void InitPStreamCholFC(PStreamChol *pst, char *dynwinf, char *accwinf,
191 int order, int T);
192 static void mlgparaCholFC(DMATRIX pdf, PStreamChol *pst, DMATRIX mlgp);
193 static void mlpgCholFC(PStreamChol *pst);
194 static void calc_R_and_r_FC(PStreamChol *pst);
195 static void CholeskiFC(PStreamChol *pst);
196 static void Choleski_forwardFC(PStreamChol *pst);
197 static void Choleski_backwardFC(PStreamChol *pst);
198 #endif
199
200 /**********************************/
201 /* ML Considering Global Variance */
202 /**********************************/
203 #if 0
204 static void varconv(double **c, const int m, const int T, const double var);
205 static void calc_varstats(double **c, const int m, const int T,
206 double *av, double *var, double *dif);
207 /* Diagonal Covariance Version */
208 static void mlgparaGrad(DMATRIX pdf, PStreamChol *pst, DMATRIX mlgp,
209 const int max, double th, double e, double alpha,
210 DVECTOR vm, DVECTOR vv, XBOOL nrmflag, XBOOL extvflag);
211 static void mlpgGrad(PStreamChol *pst, const int max, double th, double e,
212 double alpha, DVECTOR vm, DVECTOR vv, XBOOL nrmflag);
213 static void calc_grad(PStreamChol *pst, const int m);
214 static void calc_vargrad(PStreamChol *pst, const int m, double alpha, double n,
215 double vm, double vv);
216 static double get_gauss_dia5(double det,
217 double weight,
218 DVECTOR vec, /* dim */
219 DVECTOR meanvec, /* dim */
220 DVECTOR invcovvec); /* dim */
221 #endif
222
223 static double get_gauss_full(long clsidx,
224 DVECTOR vec, /* [dim] */
225 DVECTOR detvec, /* [clsnum] */
226 DMATRIX weightmat, /* [clsnum][1] */
227 DMATRIX meanvec, /* [clsnum][dim] */
228 DMATRIX invcovmat); /* [clsnum * dim][dim] */
229 static double get_gauss_dia(long clsidx,
230 DVECTOR vec, /* [dim] */
231 DVECTOR detvec, /* [clsnum] */
232 DMATRIX weightmat, /* [clsnum][1] */
233 DMATRIX meanmat, /* [clsnum][dim] */
234 DMATRIX invcovmat); /* [clsnum][dim] */
235 static double cal_xmcxmc(long clsidx,
236 DVECTOR x,
237 DMATRIX mm, /* [num class][dim] */
238 DMATRIX cm); /* [num class * dim][dim] */
239
240 #if 0
241 static void get_gv_mlpgpara(MLPGPARA param, char *vmfile, char *vvfile,
242 long dim2, XBOOL msg_flag);
243 #endif
244
245 /* User level function */
246 cst_track *mlpg(const cst_track *param_track, cst_cg_db *cg_db);
247
248 #endif /* _MLPG_H */