libsent/src/hmminfo/rdhmmdef_options.c

Go to the documentation of this file.
00001 
00017 /*
00018  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00019  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00020  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00021  * All rights reserved
00022  */
00023 
00024 #include <sent/stddefs.h>
00025 #include <sent/htk_param.h>
00026 #include <sent/htk_hmm.h>
00027 
00029 static OptionStr optcov[] = {   /* covariance matrix type */
00030   {"DIAGC", C_DIAG_C, "Diag", TRUE},
00031   {"INVDIAGC", C_INV_DIAG, "InvDiag", FALSE},
00032   {"FULLC", C_FULL, "Full", FALSE},
00033   {"LLTC", C_LLT, "LLT", FALSE}, /* not used in HTK V2.0 */
00034   {"XFORMC", C_XFORM, "Xform", FALSE},  /* not used in HTK V2.0 */
00035   {NULL,0,NULL,FALSE}
00036 };
00038 static OptionStr optdur[] = {   /* duration types */
00039   {"NULLD", D_NULL, "Null", TRUE},
00040   {"POISSOND", D_POISSON, "Poisson", FALSE},
00041   {"GAMMAD", D_GAMMA, "Gamma", FALSE},
00042   {"GEND", D_GEN, "Gen", FALSE},
00043   {NULL,0,NULL,FALSE}
00044 };
00045 
00046 extern char *rdhmmdef_token;    
00047 
00048 
00055 static void
00056 read_global_opt(FILE *fp, HTK_HMM_Options *op)
00057 {
00058   int i;
00059   short tmptype;
00060 
00061   for (;;) {
00062     if (rdhmmdef_token == NULL) break;
00063     if (currentis("HMMSETID")) { /* <HMMSETID> */
00064       read_token(fp);
00065       NoTokErr("missing HMMSETID argument");
00066     } else if (currentis("STREAMINFO")) { /* <STREAMINFO> */
00067       read_token(fp);
00068       NoTokErr("missing STREAMINFO num");
00069       op->stream_info.num = atoi(rdhmmdef_token);
00070       /*DM("%d STREAMs:", op->stream_info.num);*/
00071       if (op->stream_info.num > 50) {
00072         j_printerr("stream num exceeded %d\n", 50);
00073         rderr(NULL);
00074       }
00075       for (i=0;i<op->stream_info.num;i++) {
00076         read_token(fp);
00077         NoTokErr("missing STREAMINFO vector size");
00078         op->stream_info.vsize[i] = atoi(rdhmmdef_token);
00079         /*DM(" %d",op->stream_info.vsize[i]);*/
00080       }
00081       /*DM("\n");*/
00082       
00083     } else if (currentis("VECSIZE")) {  /* <VECSIZE> */
00084       read_token(fp);
00085       NoTokErr("missing VECSIZE value");
00086       op->vec_size = atoi(rdhmmdef_token);
00087       /*DM("vector size: %d\n", op->vec_size);*/
00088       
00089     } else {
00090       /* covariance matrix type */
00091       for (i=0;optcov[i].name!=NULL;i++) {
00092         if (currentis(optcov[i].name)) {
00093           op->cov_type = optcov[i].type;
00094           /*DM("covariance matrix type: %s\n", optcov[i].desc);*/
00095           goto optloop;
00096         }
00097       }
00098       /* duration type */
00099       for (i=0;optdur[i].name!=NULL;i++) {
00100         if (currentis(optdur[i].name)) {
00101           op->dur_type = optdur[i].type;
00102           /*DM("duration type: %s\n", optdur[i].desc);*/
00103           goto optloop;
00104         }
00105       }
00106       /* parameter type */
00107       tmptype = param_str2code(rdhmmdef_token);
00108       if (tmptype != F_ERR_INVALID) { /* conv success */
00109         op->param_type = tmptype;
00110         /*DM("param type: %s", param_code2str(buf, op->param_type, FALSE));*/
00111         goto optloop;
00112       } else {
00113         /* nothing of above --- not option */
00114         if(rdhmmdef_token[0] != '~') {
00115           j_printerr("Error: unknown option in header: %s\n", rdhmmdef_token);
00116           rderr("unknown option in header");
00117         }
00118         return;
00119       }
00120     }
00121   optloop:
00122     read_token(fp);
00123   }
00124 }
00125 
00132 void
00133 set_global_opt(FILE *fp, HTK_HMM_INFO *hmm)
00134 {
00135   read_global_opt(fp,&(hmm->opt));
00136 }
00137 
00138 
00147 static char *
00148 get_opttype_str(OptionStr *confdata, short type)
00149 {
00150   int i;
00151   for (i = 0; confdata[i].name != NULL; i++) {
00152     if (confdata[i].type == type) {
00153       return(confdata[i].name);
00154     }
00155   }
00156   rderr("unknown typecode in header!");
00157   return(NULL);
00158 }
00159 
00167 char *
00168 get_cov_str(short covtype)
00169 {
00170   return(get_opttype_str(optcov, covtype));
00171 }
00172 
00180 char *
00181 get_dur_str(short durtype)
00182 {
00183   return(get_opttype_str(optdur, durtype));
00184 }

Generated on Tue Dec 26 16:16:33 2006 for Julius by  doxygen 1.5.0