Julius 4.2
|
00001 00019 /* 00020 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00021 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00022 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00023 * All rights reserved 00024 */ 00025 00026 #include <sent/stddefs.h> 00027 #include <sent/htk_param.h> 00028 00034 void 00035 param_init_content(HTK_Param *p) 00036 { 00037 p->samplenum = 0; 00038 } 00039 00053 boolean 00054 param_alloc(HTK_Param *p, unsigned int samplenum, short veclen) 00055 { 00056 unsigned int t; 00057 VECT **new; 00058 unsigned int newlen; 00059 00060 if (p->parvec == NULL) { 00061 /* at least some length should be allocated */ 00062 if (samplenum < HTK_PARAM_INCREMENT_STEP_FRAME) { 00063 p->samplenum_alloc = HTK_PARAM_INCREMENT_STEP_FRAME; 00064 } else { 00065 p->samplenum_alloc = samplenum; 00066 } 00067 /* first time: just allocate veclen x samplenum */ 00068 p->parvec = (VECT **)mybmalloc2(sizeof(VECT *) * p->samplenum_alloc, &(p->mroot)); 00069 for(t=0;t<p->samplenum_alloc;t++) { 00070 p->parvec[t] = (VECT *)mybmalloc2(sizeof(VECT) * veclen, &(p->mroot)); 00071 } 00072 p->veclen_alloc = veclen; 00073 } else { 00074 /* already allocated */ 00075 /* check required vector length */ 00076 if (veclen > p->veclen_alloc) { 00077 jlog("Error: param_malloc: longer vector required, re-allocate all\n"); 00078 jlog("Error: param_malloc: allocated = %d, required = %d\n", p->veclen_alloc, veclen); 00079 return FALSE; 00080 } 00081 if (samplenum > p->samplenum_alloc) { 00082 /* need frame expansion */ 00083 newlen = p->samplenum_alloc; 00084 while(newlen < samplenum) newlen += HTK_PARAM_INCREMENT_STEP_FRAME; 00085 //jlog("Debug: param_malloc: parvec extend to %d\n", newlen); 00086 new = (VECT **)mybmalloc2(sizeof(VECT *) * newlen, &(p->mroot)); 00087 for(t = 0; t < p->samplenum_alloc; t++) { 00088 new[t] = p->parvec[t]; 00089 } 00090 for(t = p->samplenum_alloc; t < newlen; t++) { 00091 new[t] = (VECT *)mybmalloc2(sizeof(VECT) * p->veclen_alloc, &(p->mroot)); 00092 } 00093 p->parvec = new; 00094 p->samplenum_alloc = newlen; 00095 } 00096 } 00097 return TRUE; 00098 } 00099 00105 void 00106 param_free_content(HTK_Param *p) 00107 { 00108 mybfree2(&(p->mroot)); 00109 p->parvec = NULL; 00110 p->samplenum_alloc = 0; 00111 param_init_content(p); 00112 } 00113 00114 00120 HTK_Param * 00121 new_param() 00122 { 00123 HTK_Param *new; 00124 new = (HTK_Param *)mymalloc(sizeof(HTK_Param)); 00125 new->mroot = NULL; 00126 new->parvec = NULL; 00127 new->samplenum_alloc = 0; 00128 param_init_content(new); 00129 return(new); 00130 } 00131 00137 void 00138 free_param(HTK_Param *pinfo) 00139 { 00140 param_free_content(pinfo); 00141 free(pinfo); 00142 } 00143