Julius 4.1.5
|
00001 00018 /* 00019 * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University 00020 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00021 * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology 00022 * All rights reserved 00023 */ 00024 00025 #include <sent/stddefs.h> 00026 #include <sent/htk_param.h> 00027 #include <sent/htk_hmm.h> 00028 00030 static OptionStr optcov[] = { /* covariance matrix type */ 00031 {"DIAGC", C_DIAG_C, "Diag", TRUE}, 00032 {"INVDIAGC", C_INV_DIAG, "InvDiag", FALSE}, 00033 {"FULLC", C_FULL, "Full", FALSE}, 00034 {"LLTC", C_LLT, "LLT", FALSE}, /* not used in HTK V2.0 */ 00035 {"XFORMC", C_XFORM, "Xform", FALSE}, /* not used in HTK V2.0 */ 00036 {NULL,0,NULL,FALSE} 00037 }; 00039 static OptionStr optdur[] = { /* duration types */ 00040 {"NULLD", D_NULL, "Null", TRUE}, 00041 {"POISSOND", D_POISSON, "Poisson", FALSE}, 00042 {"GAMMAD", D_GAMMA, "Gamma", FALSE}, 00043 {"GEND", D_GEN, "Gen", FALSE}, 00044 {NULL,0,NULL,FALSE} 00045 }; 00046 00047 extern char *rdhmmdef_token; 00048 00049 00056 static void 00057 read_global_opt(FILE *fp, HTK_HMM_Options *op) 00058 { 00059 int i; 00060 short tmptype; 00061 int num; 00062 00063 for (;;) { 00064 if (rdhmmdef_token == NULL) break; 00065 if (currentis("HMMSETID")) { /* <HMMSETID> */ 00066 read_token(fp); 00067 NoTokErr("missing HMMSETID argument"); 00068 } else if (currentis("STREAMINFO")) { /* <STREAMINFO> */ 00069 read_token(fp); 00070 NoTokErr("missing STREAMINFO num"); 00071 op->stream_info.num = atoi(rdhmmdef_token); 00072 /*DM("%d STREAMs:", op->stream_info.num);*/ 00073 if (op->stream_info.num > MAXSTREAMNUM) { 00074 jlog("Error: rdhmmdef_options: stream num exceeded %d\n", MAXSTREAMNUM); 00075 rderr(NULL); 00076 } 00077 for (i=0;i<op->stream_info.num;i++) { 00078 read_token(fp); 00079 NoTokErr("missing STREAMINFO vector size"); 00080 op->stream_info.vsize[i] = atoi(rdhmmdef_token); 00081 /*DM(" %d",op->stream_info.vsize[i]);*/ 00082 } 00083 /*DM("\n");*/ 00084 00085 } else if (currentis("VECSIZE")) { /* <VECSIZE> */ 00086 read_token(fp); 00087 NoTokErr("missing VECSIZE value"); 00088 op->vec_size = atoi(rdhmmdef_token); 00089 /*DM("vector size: %d\n", op->vec_size);*/ 00090 00091 } else if (currentis("MSDINFO")) { /* <MSDINFO> by HTS */ 00092 /* Julius can auto-detect MSD-HMM, so just skip this */ 00093 read_token(fp); 00094 NoTokErr("missing MSDINFO num"); 00095 num = atoi(rdhmmdef_token); 00096 for (i=0;i<num;i++) { 00097 read_token(fp); 00098 } 00099 00100 } else { 00101 /* covariance matrix type */ 00102 for (i=0;optcov[i].name!=NULL;i++) { 00103 if (currentis(optcov[i].name)) { 00104 op->cov_type = optcov[i].type; 00105 /*DM("covariance matrix type: %s\n", optcov[i].desc);*/ 00106 goto optloop; 00107 } 00108 } 00109 /* duration type */ 00110 for (i=0;optdur[i].name!=NULL;i++) { 00111 if (currentis(optdur[i].name)) { 00112 op->dur_type = optdur[i].type; 00113 /*DM("duration type: %s\n", optdur[i].desc);*/ 00114 goto optloop; 00115 } 00116 } 00117 /* parameter type */ 00118 tmptype = param_str2code(rdhmmdef_token); 00119 if (tmptype != F_ERR_INVALID) { /* conv success */ 00120 op->param_type = tmptype; 00121 /*DM("param type: %s", param_code2str(buf, op->param_type, FALSE));*/ 00122 goto optloop; 00123 } else { 00124 /* nothing of above --- not option */ 00125 if(rdhmmdef_token[0] != '~') { 00126 jlog("Error: rdhmmdef_options: unknown option in header: %s\n", rdhmmdef_token); 00127 rderr("unknown option in header"); 00128 } 00129 return; 00130 } 00131 } 00132 optloop: 00133 read_token(fp); 00134 } 00135 } 00136 00145 boolean 00146 set_global_opt(FILE *fp, HTK_HMM_INFO *hmm) 00147 { 00148 int i,n; 00149 read_global_opt(fp,&(hmm->opt)); 00150 if (hmm->opt.stream_info.num == 0) { /* no STREAMINFO */ 00151 hmm->opt.stream_info.num = 1; 00152 hmm->opt.stream_info.vsize[0] = hmm->opt.vec_size; 00153 } else { 00154 /* vector length check */ 00155 n = 0; 00156 for(i=0;i<hmm->opt.stream_info.num;i++) { 00157 n += hmm->opt.stream_info.vsize[i]; 00158 } 00159 if (n != hmm->opt.vec_size) { 00160 jlog("Error: rdhmmdef_options: total length in <StreamInfo> and <VecSize> does not match! (%d, %d)\n", n, hmm->opt.vec_size); 00161 return FALSE; 00162 } 00163 } 00164 return TRUE; 00165 } 00166 00167 00176 static char * 00177 get_opttype_str(OptionStr *confdata, short type) 00178 { 00179 int i; 00180 for (i = 0; confdata[i].name != NULL; i++) { 00181 if (confdata[i].type == type) { 00182 return(confdata[i].name); 00183 } 00184 } 00185 rderr("unknown typecode in header!"); 00186 return(NULL); 00187 } 00188 00196 char * 00197 get_cov_str(short covtype) 00198 { 00199 return(get_opttype_str(optcov, covtype)); 00200 } 00201 00209 char * 00210 get_dur_str(short durtype) 00211 { 00212 return(get_opttype_str(optdur, durtype)); 00213 }