1 /* ----------------------------------------------------------------------------------------------- */ 2 /* */ 3 /* This file is part of MAGE / pHTS( the performative HMM-based speech synthesis system ) */ 4 /* */ 5 /* MAGE / pHTS is free software: you can redistribute it and/or modify it under the terms */ 6 /* of the GNU General Public License as published by the Free Software Foundation, either */ 7 /* version 3 of the license, or any later version. */ 8 /* */ 9 /* MAGE / pHTS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; */ 10 /* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ 11 /* See the GNU General Public License for more details. */ 12 /* */ 13 /* You should have received a copy of the GNU General Public License along with MAGE / pHTS. */ 14 /* If not, see http://www.gnu.org/licenses/ */ 15 /* */ 16 /* */ 17 /* Copyright 2011 University of Mons : */ 18 /* */ 19 /* Numediart Institute for New Media Art( www.numediart.org ) */ 20 /* Acapela Group ( www.acapela-group.com ) */ 21 /* */ 22 /* */ 23 /* Developed by : */ 24 /* */ 25 /* Maria Astrinaki, Alexis Moinet, Geoffrey Wilfart, Nicolas d'Alessandro, Thierry Dutoit */ 26 /* */ 27 /* ----------------------------------------------------------------------------------------------- */ 28 29 #pragma once 30 31 #include "Constants.h" 32 #include "State.h" 33 #include "Label.h" 34 #include "hts.h" 35 36 #include <vector> 37 #include <cstring> 38 39 namespace MAGE 40 { 41 /** 42 * \brief The memory used for every Model. 43 * \details This class is used to define the memory structures that are needed for a single Model. 44 * 45 * \authors Maria Astrinaki, Alexis Moinet, Geoffrey Wilfart, Nicolas d'Alessandro, Thierry Dutoit 46 * 47 * \version 2.00 48 * \date 2011 - 2012 49 * \copyright 50 * Numediart Institute for New Media Art ( www.numediart.org ) \n 51 * Acapela Group ( www.acapela-group.com ) \n 52 * GNU Public License (see the licence in the file). 53 */ 54 class ModelMemory 55 { 56 public : 57 58 /** 59 * Constructor that allocates the required memory for a single Model. 60 */ 61 ModelMemory(); 62 63 /** 64 * Destructor that disallocates all the memory used from a single Model. 65 */ 66 ~ModelMemory(); 67 68 /** 69 * \var double * duration_mean. 70 * \brief It contains the mean value of the duration for every State of a given HMM. 71 */ 72 double * duration_mean; 73 74 /** 75 * \var double * duration_vari. 76 * \brief It contains the variance value of the duration for every State of a given HMM. 77 */ 78 double * duration_vari; 79 80 /** 81 * \var double * duration_array. 82 * \brief It contains the duration for every State of a given HMM. 83 */ 84 int * duration_array; 85 86 // # of MGC coefficients for the MLSA filter & # of derivations: ∆( 0 ), ∆( 1 ), ∆( 3 ) 87 // fundamental frequency & # of derivations: ∆( 0 ), ∆( 1 ), ∆( 3 ) 88 // # of low-pass filter coefficients & # of derivations: ∆( 0 ), ∆( 1 ), ∆( 3 ) 89 90 /** 91 * \var double * stream_mean. 92 * \brief It contains the mean value of the spectral coefficients stream, 93 * the fundamental frequency coefficient stream and the low-pass 94 * filter coefficients stream (including static and dynamic features) 95 * for every State of a given HMM. 96 */ 97 double ** stream_mean; // [nOfStreams][maxStreamLen] 98 99 /** 100 * \var double * stream_vari. 101 * \brief It contains the variance value of the spectral coefficients stream, 102 * the fundamental frequency coefficient stream and the low-pass 103 * filter coefficients stream (including static and dynamic features) 104 * for every State of a given HMM. 105 */ 106 double ** stream_vari; // [nOfStreams][maxStreamLen] 107 108 /** 109 * \var char strQuery. 110 * \brief It contains the string query to retrieve the coefficients for every stream (mean & variance) for every 111 * State of the Model. 112 */ 113 char strQuery[maxStrLen]; 114 }; 115 116 /** 117 * \brief The HMM Model used. 118 * \details This class is used to define the Model structures that are needed for an HMM Model. 119 * 120 * \authors Maria Astrinaki, Alexis Moinet, Geoffrey Wilfart, Nicolas d'Alessandro, Thierry Dutoit 121 * 122 * \version 2.00 123 * \date 2011 - 2012 124 * \copyright 125 * Numediart Institute for New Media Art ( www.numediart.org ) \n 126 * Acapela Group ( www.acapela-group.com ) \n 127 * GNU Public License (see the licence in the file). 128 */ 129 class Model 130 { 131 public : 132 133 /** 134 * Constructor that allocates the required memory for a Model and initializes the parameters used. 135 */ 136 Model(); 137 138 /** 139 * Destructor that disallocates all the memory used from a Model. 140 */ 141 ~Model(); 142 143 // getters 144 145 /** 146 * This function gets a Model State. 147 * 148 * @param index Number / index of the State to be returned. 149 * @return A Model State given an index. 150 */ 151 const State& getState( int index ) const; 152 153 /** 154 * This function gets the total duration of the Model. 155 * 156 * @return The total duration of the Model. 157 */ 158 int getDuration( void ); 159 160 //setters 161 162 /** 163 * This function sets a Model State. 164 * 165 * @param state The State to be set. 166 * @param index Number / index of the State to be set. 167 */ 168 void setState( State state, int index ); 169 170 /** 171 * This function sets the total duration of the Model. 172 * 173 * @param duration The total duration to be set for the Model. 174 */ 175 void setDuration( int duration ); 176 177 // methods 178 179 /** 180 * This function initializes the duration of every State of the Model to zero. 181 * 182 */ 183 void initDuration ( void ); 184 185 /** 186 * This function initializes the mean and variance of every coefficients stream to zero. 187 * 188 */ 189 void initParameters( void ); 190 191 /** 192 * This function changes the duration of every State of the Model. 193 * 194 * @param updateFunction The new durations to be passed. 195 * @param action The action that will be taken between the existing and the passed durations ( overwritten, shifted or scaled ). 196 */ 197 void updateDuration( double * updateFunction, int action ); // to put a speed profile on State duration( put it inside compute duration ? ) 198 199 /** 200 * This function computes the duration of every State of the Model. 201 * 202 * @param engine The engine to be used. 203 * @param label The string query for which the durations are going to be computed. 204 * @param interpolationWeight The possible interpolation weights to be taken into account for the computation. 205 * If this argument is set to NULL then by default the interpolation weights taken into account are set to 1. 206 */ 207 void computeDuration ( MAGE::Engine * engine, MAGE::Label * label, double * interpolationWeight ); 208 209 /** 210 * This function computes the parameters for every coefficients stream of every State of the Model. 211 * 212 * @param engine The engine to be used. 213 * @param label The string query for which the parameters are going to be computed. 214 * @param interpolationWeight The possible interpolation weights to be taken into account for the computation. 215 * If this argument is set to NULL then by default the interpolation weights taken into account are set 216 * to one as default value. 217 */ 218 void computeParameters( MAGE::Engine * engine, MAGE::Label * label, double * interpolationWeight ); 219 220 /** 221 * This function computes the global variances for every coefficients stream of every State of the Model. 222 * 223 * @param engine The engine to be used. 224 * @param label The string query for which the global variances are going to be computed. 225 */ 226 void computeGlobalVariances( MAGE::Engine * engine, MAGE::Label * label ); 227 228 /** 229 * This function checks and normalizes the interpolation weights for every coefficients stream of every State of 230 * the Model that are passed directly to the given engine from the configuration file. 231 * 232 * @param engine The engine to be used. 233 * @param forced The flag to recall this function several times. 234 */ 235 void checkInterpolationWeights( MAGE::Engine * engine, bool forced = false ); 236 237 protected : 238 239 /** 240 * \var int duration. 241 * \brief It contains the total duration of the Model. 242 */ 243 int duration; 244 245 /** 246 * \var State state. 247 * \brief It contains the total number of states discribing the Model. 248 */ 249 State state[nOfStates]; 250 251 /** 252 * \var ModelMemory modelMemory. 253 * \brief It contains the total amount used by the Model. 254 */ 255 ModelMemory modelMemory; 256 257 private : 258 259 // The string query for which all the coefficients are going to be computed. 260 char strQuery[maxStrLen]; 261 262 // Flag checking if the weights have been already checked. 263 bool weightsChecked; 264 }; 265 } // namespace 266