libsent/src/hmminfo/rdhmmdef_options.c

Go to the documentation of this file.
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 
00062   for (;;) {
00063     if (rdhmmdef_token == NULL) break;
00064     if (currentis("HMMSETID")) { /* <HMMSETID> */
00065       read_token(fp);
00066       NoTokErr("missing HMMSETID argument");
00067     } else if (currentis("STREAMINFO")) { /* <STREAMINFO> */
00068       read_token(fp);
00069       NoTokErr("missing STREAMINFO num");
00070       op->stream_info.num = atoi(rdhmmdef_token);
00071       /*DM("%d STREAMs:", op->stream_info.num);*/
00072       if (op->stream_info.num > 50) {
00073         jlog("Error: rdhmmdef_options: stream num exceeded %d\n", 50);
00074         rderr(NULL);
00075       }
00076       for (i=0;i<op->stream_info.num;i++) {
00077         read_token(fp);
00078         NoTokErr("missing STREAMINFO vector size");
00079         op->stream_info.vsize[i] = atoi(rdhmmdef_token);
00080         /*DM(" %d",op->stream_info.vsize[i]);*/
00081       }
00082       /*DM("\n");*/
00083       
00084     } else if (currentis("VECSIZE")) {  /* <VECSIZE> */
00085       read_token(fp);
00086       NoTokErr("missing VECSIZE value");
00087       op->vec_size = atoi(rdhmmdef_token);
00088       /*DM("vector size: %d\n", op->vec_size);*/
00089       
00090     } else {
00091       /* covariance matrix type */
00092       for (i=0;optcov[i].name!=NULL;i++) {
00093         if (currentis(optcov[i].name)) {
00094           op->cov_type = optcov[i].type;
00095           /*DM("covariance matrix type: %s\n", optcov[i].desc);*/
00096           goto optloop;
00097         }
00098       }
00099       /* duration type */
00100       for (i=0;optdur[i].name!=NULL;i++) {
00101         if (currentis(optdur[i].name)) {
00102           op->dur_type = optdur[i].type;
00103           /*DM("duration type: %s\n", optdur[i].desc);*/
00104           goto optloop;
00105         }
00106       }
00107       /* parameter type */
00108       tmptype = param_str2code(rdhmmdef_token);
00109       if (tmptype != F_ERR_INVALID) { /* conv success */
00110         op->param_type = tmptype;
00111         /*DM("param type: %s", param_code2str(buf, op->param_type, FALSE));*/
00112         goto optloop;
00113       } else {
00114         /* nothing of above --- not option */
00115         if(rdhmmdef_token[0] != '~') {
00116           jlog("Error: rdhmmdef_options: unknown option in header: %s\n", rdhmmdef_token);
00117           rderr("unknown option in header");
00118         }
00119         return;
00120       }
00121     }
00122   optloop:
00123     read_token(fp);
00124   }
00125 }
00126 
00133 void
00134 set_global_opt(FILE *fp, HTK_HMM_INFO *hmm)
00135 {
00136   read_global_opt(fp,&(hmm->opt));
00137 }
00138 
00139 
00148 static char *
00149 get_opttype_str(OptionStr *confdata, short type)
00150 {
00151   int i;
00152   for (i = 0; confdata[i].name != NULL; i++) {
00153     if (confdata[i].type == type) {
00154       return(confdata[i].name);
00155     }
00156   }
00157   rderr("unknown typecode in header!");
00158   return(NULL);
00159 }
00160 
00168 char *
00169 get_cov_str(short covtype)
00170 {
00171   return(get_opttype_str(optcov, covtype));
00172 }
00173 
00181 char *
00182 get_dur_str(short durtype)
00183 {
00184   return(get_opttype_str(optdur, durtype));
00185 }

Generated on Tue Dec 18 15:59:55 2007 for Julius by  doxygen 1.5.4