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 (tomoki@ics.nitech.ac.jp) */ 81 /* June 2004 */ 82 /* Integrate as a Voice Conversion module */ 83 /* */ 84 /*-------------------------------------------------------------------*/ 85 /* */ 86 /* Author : Tomoki Toda (tomoki@ics.nitech.ac.jp) */ 87 /* Date : June 2004 */ 88 /* */ 89 /*-------------------------------------------------------------------*/ 90 /* Integrated into a single C file for festival/flite integration */ 91 /* May 2008 awb@cs.cmu.edu */ 92 /*-------------------------------------------------------------------*/ 93 94 #ifndef _MLPG_H 95 #define _MLPG_H 96 97 #include "vc.h" 98 99 #define INFTY ((double) 1.0e+38) 100 #define INFTY2 ((double) 1.0e+19) 101 #define INVINF ((double) 1.0e-38) 102 #define INVINF2 ((double) 1.0e-19) 103 104 #ifdef PI 105 /* ok */ 106 #elif defined(M_PI) 107 #define PI M_PI 108 #else 109 #define PI 3.1415926535897932385 110 #endif 111 112 #define WLEFT 0 113 #define WRIGHT 1 114 115 typedef struct _DWin { 116 int num; /* number of static + deltas */ 117 int **width; /* width [0..num-1][0(left) 1(right)] */ 118 double **coef; /* coefficient [0..num-1][length[0]..length[1]] */ 119 double **coef_ptrs; /* keeps the pointers so we can free them */ 120 int maxw[2]; /* max width [0(left) 1(right)] */ 121 } MLPG_DWin; 122 123 typedef struct _PStreamChol { 124 int vSize; // size of ovserved vector 125 int order; // order of cepstrum 126 int T; // number of frames 127 int width; // width of WSW 128 MLPG_DWin dw; 129 double **mseq; // sequence of mean vector 130 double **ivseq; // sequence of invarsed covariance vector 131 double ***ifvseq; // sequence of invarsed full covariance vector 132 double **R; // WSW[T][range] 133 double *r; // WSM [T] 134 double *g; // g [T] 135 double **c; // parameter c 136 } PStreamChol; 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 #if 0 160 static double get_like_gv(long dim2, long dnum, MLPGPARA param); 161 static void sm_mvav(DMATRIX mat, long hlen); 162 #endif 163 #if 0 164 /* Full Covariance Version */ 165 static void InitPStreamCholFC(PStreamChol *pst, char *dynwinf, char *accwinf, 166 int order, int T); 167 static void mlgparaCholFC(DMATRIX pdf, PStreamChol *pst, DMATRIX mlgp); 168 static void mlpgCholFC(PStreamChol *pst); 169 static void calc_R_and_r_FC(PStreamChol *pst); 170 static void CholeskiFC(PStreamChol *pst); 171 static void Choleski_forwardFC(PStreamChol *pst); 172 static void Choleski_backwardFC(PStreamChol *pst); 173 #endif 174 175 /**********************************/ 176 /* ML Considering Global Variance */ 177 /**********************************/ 178 #if 0 179 static void varconv(double **c, const int m, const int T, const double var); 180 static void calc_varstats(double **c, const int m, const int T, 181 double *av, double *var, double *dif); 182 /* Diagonal Covariance Version */ 183 static void mlgparaGrad(DMATRIX pdf, PStreamChol *pst, DMATRIX mlgp, 184 const int max, double th, double e, double alpha, 185 DVECTOR vm, DVECTOR vv, XBOOL nrmflag, XBOOL extvflag); 186 static void mlpgGrad(PStreamChol *pst, const int max, double th, double e, 187 double alpha, DVECTOR vm, DVECTOR vv, XBOOL nrmflag); 188 static void calc_grad(PStreamChol *pst, const int m); 189 static void calc_vargrad(PStreamChol *pst, const int m, double alpha, double n, 190 double vm, double vv); 191 static double get_gauss_dia5(double det, 192 double weight, 193 DVECTOR vec, // dim 194 DVECTOR meanvec, // dim 195 DVECTOR invcovvec); // dim 196 #endif 197 198 199 #if 0 200 static void get_gv_mlpgpara(MLPGPARA param, char *vmfile, char *vvfile, 201 long dim2, XBOOL msg_flag); 202 #endif 203 204 #endif /* _MLPG_H */ 205