Julius 4.2
|
00001 00022 /* 00023 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00024 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00025 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00026 * All rights reserved 00027 */ 00028 00029 #ifndef __SENT_HTK_HMM_2_H__ 00030 #define __SENT_HTK_HMM_2_H__ 00031 00032 #include <sent/stddefs.h> 00033 #include <sent/htk_defs.h> 00034 #include <sent/ptree.h> 00035 #include <sent/mfcc.h> 00036 00038 #define currentis(A) (!strcasecmp(A, rdhmmdef_token)) 00039 00040 #define NoTokErr(S) if (!rdhmmdef_token) rderr(S) 00041 00043 #define HMMDEF_DELM " \t\n<>" 00044 00068 00069 00071 #define MAX_STATE_NUM 2147483647 00072 00074 #define HMM_RC_DLIM "+" ///< Right context delimiter in string 00075 #define HMM_LC_DLIM "-" ///< Left context delimiter in string 00076 #define HMM_RC_DLIM_C '+' ///< Right context delimiter in character 00077 #define HMM_LC_DLIM_C '-' ///< Left context delimiter in character 00078 00080 #define SPMODEL_NAME_DEFAULT "sp" 00081 00083 #define MAX_HMMNAME_LEN 256 00084 00086 enum iwcd_type { 00087 IWCD_UNDEF, 00088 IWCD_MAX, 00089 IWCD_AVG, 00090 IWCD_NBEST 00091 }; 00092 00093 /* options info */ 00094 00096 typedef struct { 00097 short num; 00098 short vsize[MAXSTREAMNUM]; 00099 } HTK_HMM_StreamInfo; 00100 00102 typedef struct { 00103 HTK_HMM_StreamInfo stream_info; 00104 short vec_size; 00105 short cov_type; 00106 short dur_type; 00107 short param_type; 00108 } HTK_HMM_Options; 00109 00111 typedef struct _HTK_HMM_trans { 00112 char *name; 00113 short statenum; 00114 PROB **a; 00115 int id; 00116 struct _HTK_HMM_trans *next; 00117 } HTK_HMM_Trans; 00118 00120 typedef struct _HTK_HMM_variance { 00121 char *name; 00122 VECT *vec; 00123 short len; 00124 struct _HTK_HMM_variance *next; 00125 } HTK_HMM_Var; 00126 00128 typedef struct _HTK_HMM_dens { 00129 char *name; 00130 VECT *mean; 00131 short meanlen; 00132 HTK_HMM_Var *var; 00133 00137 LOGPROB gconst; 00138 struct _HTK_HMM_dens *next; 00139 } HTK_HMM_Dens; 00140 00142 typedef struct _HTK_HMM_stream_weight { 00143 char *name; 00144 VECT *weight; 00145 short len; 00146 struct _HTK_HMM_stream_weight *next; 00147 } HTK_HMM_StreamWeight; 00148 00157 typedef struct _HTK_HMM_PDF { 00158 char *name; 00159 boolean tmix; 00160 short stream_id; 00161 short mix_num; 00162 HTK_HMM_Dens **b; 00163 PROB *bweight; 00164 struct _HTK_HMM_PDF *next; 00165 } HTK_HMM_PDF; 00166 00171 typedef struct _HTK_HMM_state { 00172 char *name; 00173 short nstream; 00174 HTK_HMM_StreamWeight *w; 00175 HTK_HMM_PDF **pdf; 00176 int id; 00177 struct _HTK_HMM_state *next; 00178 } HTK_HMM_State; 00179 00181 typedef struct _HTK_HMM_data { 00182 char *name; 00183 short state_num; 00184 HTK_HMM_State **s; 00185 HTK_HMM_Trans *tr; 00186 struct _HTK_HMM_data *next; 00187 } HTK_HMM_Data; 00188 00190 typedef struct { 00191 char *name; 00192 int num; 00193 HTK_HMM_Dens **d; 00194 unsigned short id; 00195 } GCODEBOOK; 00197 00199 typedef struct { 00200 HTK_HMM_State *state; 00201 /* GCODEBOOK *book;*/ /* pointer to the corresponding codebook in hmminfo */ 00202 } GS_SET; 00203 00246 00247 00249 typedef struct { 00250 HTK_HMM_State **s; 00251 unsigned short num; 00252 unsigned short maxnum; 00253 } CD_State_Set; 00261 typedef struct _cd_set{ 00262 char *name; 00263 CD_State_Set *stateset; 00264 unsigned short state_num; 00265 HTK_HMM_Trans *tr; 00266 struct _cd_set *next; 00267 } CD_Set; 00269 typedef struct { 00270 boolean binary_malloc; 00271 APATNODE *cdtree; 00272 } HMM_CDSET_INFO; 00274 00297 typedef struct _HMM_logical { 00298 char *name; 00299 boolean is_pseudo; 00300 00301 union { 00302 HTK_HMM_Data *defined; 00303 CD_Set *pseudo; 00304 } body; 00305 struct _HMM_logical *next; 00306 } HMM_Logical; 00307 00313 typedef struct { 00314 char *name; 00315 boolean bgnflag; 00316 boolean endflag; 00317 } BASEPHONE; 00323 typedef struct { 00324 int num; 00325 int bgnnum; 00326 int endnum; 00327 APATNODE *root; 00328 } HMM_basephone; 00329 00335 typedef struct { 00340 HTK_HMM_Options opt; 00341 HTK_HMM_Trans *trstart; 00342 HTK_HMM_Var *vrstart; 00343 HTK_HMM_Dens *dnstart; 00344 HTK_HMM_PDF *pdfstart; 00345 HTK_HMM_StreamWeight *swstart; 00346 HTK_HMM_State *ststart; 00347 HTK_HMM_Data *start; 00348 00349 00354 HMM_Logical *lgstart; 00355 00356 00361 APATNODE *tr_root; 00362 APATNODE *vr_root; 00363 APATNODE *sw_root; 00364 APATNODE *dn_root; 00365 APATNODE *pdf_root; 00366 APATNODE *st_root; 00367 APATNODE *physical_root; 00368 APATNODE *logical_root; 00369 APATNODE *codebook_root; 00370 00371 00376 HMM_basephone basephone; 00377 HMM_CDSET_INFO cdset_info; 00378 00379 00384 boolean need_multipath; 00385 boolean multipath; 00386 boolean is_triphone; 00387 boolean is_tied_mixture; 00388 short cdset_method; 00389 short cdmax_num; 00390 HMM_Logical *sp; 00391 LOGPROB iwsp_penalty; 00392 boolean variance_inversed; 00393 00394 int totaltransnum; 00395 int totalmixnum; 00396 int totalstatenum; 00397 int totalhmmnum; 00398 int totallogicalnum; 00399 int totalpseudonum; 00400 int totalpdfnum; 00401 int codebooknum; 00402 int maxcodebooksize; 00403 int maxmixturenum; 00404 int maxstatenum; 00405 00406 BMALLOC_BASE *mroot; 00407 BMALLOC_BASE *lroot; 00408 BMALLOC_BASE *cdset_root; 00409 00410 int *tmp_mixnum; 00411 00412 #ifdef ENABLE_MSD 00413 boolean has_msd; 00414 #endif 00415 00416 void *hook; 00417 00419 } HTK_HMM_INFO; 00420 00421 00422 #ifdef __cplusplus 00423 extern "C" { 00424 #endif 00425 00426 /* init_phmm.c */ 00427 void htk_hmm_set_pause_model(HTK_HMM_INFO *hmminfo, char *spmodel_name); 00428 /* rdhmmdef.c */ 00429 void rderr(char *str); 00430 char *read_token(FILE *fp); 00431 boolean rdhmmdef(FILE *, HTK_HMM_INFO *); 00432 void htk_hmm_inverse_variances(HTK_HMM_INFO *hmm); 00433 #ifdef ENABLE_MSD 00434 void htk_hmm_check_msd(HTK_HMM_INFO *hmm); 00435 #endif 00436 /* rdhmmdef_options.c */ 00437 boolean set_global_opt(FILE *fp, HTK_HMM_INFO *hmm); 00438 char *get_cov_str(short covtype); 00439 char *get_dur_str(short durtype); 00440 /* rdhmmdef_trans.c */ 00441 void trans_add(HTK_HMM_INFO *hmm, HTK_HMM_Trans *newParam); 00442 HTK_HMM_Trans *get_trans_data(FILE *, HTK_HMM_INFO *); 00443 void def_trans_macro(char *, FILE *, HTK_HMM_INFO *); 00444 /* rdhmmdef_state.c */ 00445 HTK_HMM_State *get_state_data(FILE *, HTK_HMM_INFO *); 00446 void def_state_macro(char *, FILE *, HTK_HMM_INFO *); 00447 HTK_HMM_State *state_lookup(HTK_HMM_INFO *hmm, char *keyname); 00448 void state_add(HTK_HMM_INFO *hmm, HTK_HMM_State *newParam); 00449 /* rdhmmdef_mpdf.c */ 00450 void mpdf_add(HTK_HMM_INFO *hmm, HTK_HMM_PDF *newParam); 00451 HTK_HMM_PDF *mpdf_lookup(HTK_HMM_INFO *hmm, char *keyname); 00452 HTK_HMM_PDF *get_mpdf_data(FILE *fp, HTK_HMM_INFO *hmm, int mix_num, short stream_id); 00453 void def_mpdf_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm); 00454 /* rdhmmdef_dens.c */ 00455 HTK_HMM_Dens *get_dens_data(FILE *, HTK_HMM_INFO *); 00456 void def_dens_macro(char *, FILE *, HTK_HMM_INFO *); 00457 HTK_HMM_Dens *dens_lookup(HTK_HMM_INFO *hmm, char *keyname); 00458 void dens_add(HTK_HMM_INFO *hmm, HTK_HMM_Dens *newParam); 00459 /* rdhmmdef_var.c */ 00460 HTK_HMM_Var *get_var_data(FILE *, HTK_HMM_INFO *); 00461 void def_var_macro(char *, FILE *, HTK_HMM_INFO *); 00462 void var_add(HTK_HMM_INFO *hmm, HTK_HMM_Var *newParam); 00463 /* rdhmmdef_streamweight.c */ 00464 HTK_HMM_StreamWeight *get_streamweight_data(FILE *fp, HTK_HMM_INFO *hmm); 00465 void def_streamweight_macro(char *, FILE *, HTK_HMM_INFO *); 00466 void sw_add(HTK_HMM_INFO *hmm, HTK_HMM_StreamWeight *newParam); 00467 /* rdhmmdef_data.c */ 00468 void def_HMM(char *, FILE *, HTK_HMM_INFO *); 00469 HTK_HMM_Data *htk_hmmdata_new(HTK_HMM_INFO *); 00470 void htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *newParam); 00471 /* rdhmmdef_tiedmix.c */ 00472 void tmix_read(FILE *fp, HTK_HMM_PDF *mpdf, HTK_HMM_INFO *hmm); 00473 void codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *newParam); 00474 /* rdhmmdef_regtree.c */ 00475 void def_regtree_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm); 00476 /* rdhmmdef_hmmlist.c */ 00477 boolean rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo); 00478 boolean save_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo); 00479 boolean load_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo); 00480 00481 /* put_htkdata_info.c */ 00482 void put_htk_trans(FILE *fp, HTK_HMM_Trans *t); 00483 void put_htk_var(FILE *fp, HTK_HMM_Var *v); 00484 void put_htk_dens(FILE *fp, HTK_HMM_Dens *d); 00485 void put_htk_mpdf(FILE *fp, HTK_HMM_PDF *m); 00486 void put_htk_state(FILE *fp, HTK_HMM_State *s); 00487 void put_htk_hmm(FILE *fp, HTK_HMM_Data *h); 00488 void put_logical_hmm(FILE *fp, HMM_Logical *l); 00489 void print_hmmdef_info(FILE *fp, HTK_HMM_INFO *); 00490 00491 HTK_HMM_INFO *hmminfo_new(); 00492 boolean hmminfo_free(HTK_HMM_INFO *); 00493 boolean init_hmminfo(HTK_HMM_INFO *hmminfo, char *filename, char *mapfile, Value *para); 00494 HTK_HMM_Data *htk_hmmdata_lookup_physical(HTK_HMM_INFO *, char *); 00495 HMM_Logical *htk_hmmdata_lookup_logical(HTK_HMM_INFO *, char *); 00496 void hmm_add_physical_to_logical(HTK_HMM_INFO *); 00497 void hmm_add_pseudo_phones(HTK_HMM_INFO *hmminfo); 00498 /* chkhmmlist.c */ 00499 void make_hmm_basephone_list(HTK_HMM_INFO *hmminfo); 00500 00501 /* HMM type check functions */ 00502 boolean htk_hmm_has_several_arc_on_edge(HTK_HMM_INFO *hmminfo); 00503 boolean check_hmm_limit(HTK_HMM_Data *dt); 00504 boolean check_all_hmm_limit(HTK_HMM_INFO *hmm); 00505 boolean check_hmm_options(HTK_HMM_INFO *hmm); 00506 boolean is_skippable_model(HTK_HMM_Data *d); 00507 00508 /* CCD related */ 00509 boolean guess_if_cd_hmm(HTK_HMM_INFO *hmm); 00510 HMM_Logical *get_right_context_HMM(HMM_Logical *base, char *rc_name, HTK_HMM_INFO *hmminfo); 00511 HMM_Logical *get_left_context_HMM(HMM_Logical *base, char *lc_name, HTK_HMM_INFO *hmminfo); 00512 void add_right_context(char name[], char *rc); 00513 void add_left_context(char name[], char *lc); 00514 char *center_name(char *hmmname, char *buf); 00515 char *leftcenter_name(char *hmmname, char *buf); 00516 char *rightcenter_name(char *hmmname, char *buf); 00517 00518 /* CD_SET related */ 00519 boolean regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname, BMALLOC_BASE **mroot); 00520 boolean make_cdset(HTK_HMM_INFO *hmminfo); 00521 void put_all_cdinfo(HTK_HMM_INFO *hmminfo); 00522 void free_cdset(APATNODE **root, BMALLOC_BASE **mroot); 00523 CD_Set *cdset_lookup(HTK_HMM_INFO *hmminfo, char *cdstr); 00524 CD_Set *lcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname); 00525 CD_Set *rcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname); 00526 int hmm_logical_state_num(HMM_Logical *lg); 00527 HTK_HMM_Trans *hmm_logical_trans(HMM_Logical *lg); 00528 00529 #include <sent/htk_param.h> 00530 boolean check_param_coherence(HTK_HMM_INFO *hmm, HTK_Param *pinfo); 00531 boolean check_param_basetype(HTK_HMM_INFO *hmm, HTK_Param *pinfo); 00532 int param_check_and_adjust(HTK_HMM_INFO *hmm, HTK_Param *pinfo, boolean vflag); 00533 00534 00535 /* binary format */ 00536 boolean write_binhmm(FILE *fp, HTK_HMM_INFO *hmm, Value *para); 00537 boolean read_binhmm(FILE *fp, HTK_HMM_INFO *hmm, boolean gzfile_p, Value *para); 00538 00539 #ifdef __cplusplus 00540 } 00541 #endif 00542 00543 00544 #endif /* __SENT_HTK_HMM_2_H__ */