Julius 4.1.5
|
00001 00022 /* 00023 * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University 00024 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00025 * Copyright (c) 2005-2007 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 struct _HTK_HMM_trans *next; 00116 } HTK_HMM_Trans; 00117 00119 typedef struct _HTK_HMM_variance { 00120 char *name; 00121 VECT *vec; 00122 short len; 00123 struct _HTK_HMM_variance *next; 00124 } HTK_HMM_Var; 00125 00127 typedef struct _HTK_HMM_dens { 00128 char *name; 00129 VECT *mean; 00130 short meanlen; 00131 HTK_HMM_Var *var; 00132 00136 LOGPROB gconst; 00137 struct _HTK_HMM_dens *next; 00138 } HTK_HMM_Dens; 00139 00141 typedef struct _HTK_HMM_stream_weight { 00142 char *name; 00143 VECT *weight; 00144 short len; 00145 struct _HTK_HMM_stream_weight *next; 00146 } HTK_HMM_StreamWeight; 00147 00156 typedef struct _HTK_HMM_PDF { 00157 char *name; 00158 boolean tmix; 00159 short stream_id; 00160 short mix_num; 00161 HTK_HMM_Dens **b; 00162 PROB *bweight; 00163 struct _HTK_HMM_PDF *next; 00164 } HTK_HMM_PDF; 00165 00170 typedef struct _HTK_HMM_state { 00171 char *name; 00172 short nstream; 00173 HTK_HMM_StreamWeight *w; 00174 HTK_HMM_PDF **pdf; 00175 int id; 00176 struct _HTK_HMM_state *next; 00177 } HTK_HMM_State; 00178 00180 typedef struct _HTK_HMM_data { 00181 char *name; 00182 short state_num; 00183 HTK_HMM_State **s; 00184 HTK_HMM_Trans *tr; 00185 struct _HTK_HMM_data *next; 00186 } HTK_HMM_Data; 00187 00189 typedef struct { 00190 char *name; 00191 int num; 00192 HTK_HMM_Dens **d; 00193 unsigned short id; 00194 } GCODEBOOK; 00196 00198 typedef struct { 00199 HTK_HMM_State *state; 00200 /* GCODEBOOK *book;*/ /* pointer to the corresponding codebook in hmminfo */ 00201 } GS_SET; 00202 00245 00246 00248 typedef struct { 00249 HTK_HMM_State **s; 00250 unsigned short num; 00251 unsigned short maxnum; 00252 } CD_State_Set; 00260 typedef struct _cd_set{ 00261 char *name; 00262 CD_State_Set *stateset; 00263 unsigned short state_num; 00264 HTK_HMM_Trans *tr; 00265 struct _cd_set *next; 00266 } CD_Set; 00268 typedef struct { 00269 APATNODE *cdtree; 00270 } HMM_CDSET_INFO; 00272 00295 typedef struct _HMM_logical { 00296 char *name; 00297 boolean is_pseudo; 00298 00299 union { 00300 HTK_HMM_Data *defined; 00301 CD_Set *pseudo; 00302 } body; 00303 struct _HMM_logical *next; 00304 } HMM_Logical; 00305 00311 typedef struct { 00312 char *name; 00313 boolean bgnflag; 00314 boolean endflag; 00315 } BASEPHONE; 00321 typedef struct { 00322 int num; 00323 int bgnnum; 00324 int endnum; 00325 APATNODE *root; 00326 } HMM_basephone; 00327 00333 typedef struct { 00338 HTK_HMM_Options opt; 00339 HTK_HMM_Trans *trstart; 00340 HTK_HMM_Var *vrstart; 00341 HTK_HMM_Dens *dnstart; 00342 HTK_HMM_PDF *pdfstart; 00343 HTK_HMM_StreamWeight *swstart; 00344 HTK_HMM_State *ststart; 00345 HTK_HMM_Data *start; 00346 00347 00352 HMM_Logical *lgstart; 00353 00354 00359 APATNODE *tr_root; 00360 APATNODE *vr_root; 00361 APATNODE *sw_root; 00362 APATNODE *dn_root; 00363 APATNODE *pdf_root; 00364 APATNODE *st_root; 00365 APATNODE *physical_root; 00366 APATNODE *logical_root; 00367 APATNODE *codebook_root; 00368 00369 00374 HMM_basephone basephone; 00375 HMM_CDSET_INFO cdset_info; 00376 00377 00382 boolean need_multipath; 00383 boolean multipath; 00384 boolean is_triphone; 00385 boolean is_tied_mixture; 00386 short cdset_method; 00387 short cdmax_num; 00388 HMM_Logical *sp; 00389 LOGPROB iwsp_penalty; 00390 boolean variance_inversed; 00391 00392 int totalmixnum; 00393 int totalstatenum; 00394 int totalhmmnum; 00395 int totallogicalnum; 00396 int totalpseudonum; 00397 int totalpdfnum; 00398 int codebooknum; 00399 int maxcodebooksize; 00400 int maxmixturenum; 00401 int maxstatenum; 00402 00403 BMALLOC_BASE *mroot; 00404 BMALLOC_BASE *lroot; 00405 BMALLOC_BASE *cdset_root; 00406 00407 int *tmp_mixnum; 00408 00409 #ifdef ENABLE_MSD 00410 boolean has_msd; 00411 #endif 00412 00414 } HTK_HMM_INFO; 00415 00416 00417 #ifdef __cplusplus 00418 extern "C" { 00419 #endif 00420 00421 /* init_phmm.c */ 00422 void htk_hmm_set_pause_model(HTK_HMM_INFO *hmminfo, char *spmodel_name); 00423 /* rdhmmdef.c */ 00424 void rderr(char *str); 00425 char *read_token(FILE *fp); 00426 boolean rdhmmdef(FILE *, HTK_HMM_INFO *); 00427 void htk_hmm_inverse_variances(HTK_HMM_INFO *hmm); 00428 #ifdef ENABLE_MSD 00429 void htk_hmm_check_msd(HTK_HMM_INFO *hmm); 00430 #endif 00431 /* rdhmmdef_options.c */ 00432 boolean set_global_opt(FILE *fp, HTK_HMM_INFO *hmm); 00433 char *get_cov_str(short covtype); 00434 char *get_dur_str(short durtype); 00435 /* rdhmmdef_trans.c */ 00436 void trans_add(HTK_HMM_INFO *hmm, HTK_HMM_Trans *newParam); 00437 HTK_HMM_Trans *get_trans_data(FILE *, HTK_HMM_INFO *); 00438 void def_trans_macro(char *, FILE *, HTK_HMM_INFO *); 00439 /* rdhmmdef_state.c */ 00440 HTK_HMM_State *get_state_data(FILE *, HTK_HMM_INFO *); 00441 void def_state_macro(char *, FILE *, HTK_HMM_INFO *); 00442 HTK_HMM_State *state_lookup(HTK_HMM_INFO *hmm, char *keyname); 00443 void state_add(HTK_HMM_INFO *hmm, HTK_HMM_State *newParam); 00444 /* rdhmmdef_mpdf.c */ 00445 void mpdf_add(HTK_HMM_INFO *hmm, HTK_HMM_PDF *newParam); 00446 HTK_HMM_PDF *mpdf_lookup(HTK_HMM_INFO *hmm, char *keyname); 00447 HTK_HMM_PDF *get_mpdf_data(FILE *fp, HTK_HMM_INFO *hmm, int mix_num, short stream_id); 00448 void def_mpdf_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm); 00449 /* rdhmmdef_dens.c */ 00450 HTK_HMM_Dens *get_dens_data(FILE *, HTK_HMM_INFO *); 00451 void def_dens_macro(char *, FILE *, HTK_HMM_INFO *); 00452 HTK_HMM_Dens *dens_lookup(HTK_HMM_INFO *hmm, char *keyname); 00453 void dens_add(HTK_HMM_INFO *hmm, HTK_HMM_Dens *newParam); 00454 /* rdhmmdef_var.c */ 00455 HTK_HMM_Var *get_var_data(FILE *, HTK_HMM_INFO *); 00456 void def_var_macro(char *, FILE *, HTK_HMM_INFO *); 00457 void var_add(HTK_HMM_INFO *hmm, HTK_HMM_Var *newParam); 00458 /* rdhmmdef_streamweight.c */ 00459 HTK_HMM_StreamWeight *get_streamweight_data(FILE *fp, HTK_HMM_INFO *hmm); 00460 void def_streamweight_macro(char *, FILE *, HTK_HMM_INFO *); 00461 void sw_add(HTK_HMM_INFO *hmm, HTK_HMM_StreamWeight *newParam); 00462 /* rdhmmdef_data.c */ 00463 void def_HMM(char *, FILE *, HTK_HMM_INFO *); 00464 HTK_HMM_Data *htk_hmmdata_new(HTK_HMM_INFO *); 00465 void htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *newParam); 00466 /* rdhmmdef_tiedmix.c */ 00467 void tmix_read(FILE *fp, HTK_HMM_PDF *mpdf, HTK_HMM_INFO *hmm); 00468 void codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *newParam); 00469 /* rdhmmdef_regtree.c */ 00470 void def_regtree_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm); 00471 /* rdhmmdef_hmmlist.c */ 00472 boolean rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo); 00473 boolean save_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo); 00474 boolean load_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo); 00475 00476 /* put_htkdata_info.c */ 00477 void put_htk_trans(FILE *fp, HTK_HMM_Trans *t); 00478 void put_htk_var(FILE *fp, HTK_HMM_Var *v); 00479 void put_htk_dens(FILE *fp, HTK_HMM_Dens *d); 00480 void put_htk_mpdf(FILE *fp, HTK_HMM_PDF *m); 00481 void put_htk_state(FILE *fp, HTK_HMM_State *s); 00482 void put_htk_hmm(FILE *fp, HTK_HMM_Data *h); 00483 void put_logical_hmm(FILE *fp, HMM_Logical *l); 00484 void print_hmmdef_info(FILE *fp, HTK_HMM_INFO *); 00485 00486 HTK_HMM_INFO *hmminfo_new(); 00487 boolean hmminfo_free(HTK_HMM_INFO *); 00488 boolean init_hmminfo(HTK_HMM_INFO *hmminfo, char *filename, char *mapfile, Value *para); 00489 HTK_HMM_Data *htk_hmmdata_lookup_physical(HTK_HMM_INFO *, char *); 00490 HMM_Logical *htk_hmmdata_lookup_logical(HTK_HMM_INFO *, char *); 00491 void hmm_add_physical_to_logical(HTK_HMM_INFO *); 00492 void hmm_add_pseudo_phones(HTK_HMM_INFO *hmminfo); 00493 /* chkhmmlist.c */ 00494 void make_hmm_basephone_list(HTK_HMM_INFO *hmminfo); 00495 00496 /* HMM type check functions */ 00497 boolean htk_hmm_has_several_arc_on_edge(HTK_HMM_INFO *hmminfo); 00498 boolean check_hmm_limit(HTK_HMM_Data *dt); 00499 boolean check_all_hmm_limit(HTK_HMM_INFO *hmm); 00500 boolean check_hmm_options(HTK_HMM_INFO *hmm); 00501 boolean is_skippable_model(HTK_HMM_Data *d); 00502 00503 /* CCD related */ 00504 boolean guess_if_cd_hmm(HTK_HMM_INFO *hmm); 00505 HMM_Logical *get_right_context_HMM(HMM_Logical *base, char *rc_name, HTK_HMM_INFO *hmminfo); 00506 HMM_Logical *get_left_context_HMM(HMM_Logical *base, char *lc_name, HTK_HMM_INFO *hmminfo); 00507 void add_right_context(char name[], char *rc); 00508 void add_left_context(char name[], char *lc); 00509 char *center_name(char *hmmname, char *buf); 00510 char *leftcenter_name(char *hmmname, char *buf); 00511 char *rightcenter_name(char *hmmname, char *buf); 00512 00513 /* CD_SET related */ 00514 boolean regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname, BMALLOC_BASE **mroot); 00515 boolean make_cdset(HTK_HMM_INFO *hmminfo); 00516 void put_all_cdinfo(HTK_HMM_INFO *hmminfo); 00517 void free_cdset(APATNODE **root, BMALLOC_BASE **mroot); 00518 CD_Set *cdset_lookup(HTK_HMM_INFO *hmminfo, char *cdstr); 00519 CD_Set *lcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname); 00520 CD_Set *rcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname); 00521 int hmm_logical_state_num(HMM_Logical *lg); 00522 HTK_HMM_Trans *hmm_logical_trans(HMM_Logical *lg); 00523 00524 #include <sent/htk_param.h> 00525 boolean check_param_coherence(HTK_HMM_INFO *hmm, HTK_Param *pinfo); 00526 boolean check_param_basetype(HTK_HMM_INFO *hmm, HTK_Param *pinfo); 00527 int param_check_and_adjust(HTK_HMM_INFO *hmm, HTK_Param *pinfo, boolean vflag); 00528 00529 00530 /* binary format */ 00531 boolean write_binhmm(FILE *fp, HTK_HMM_INFO *hmm, Value *para); 00532 boolean read_binhmm(FILE *fp, HTK_HMM_INFO *hmm, boolean gzfile_p, Value *para); 00533 00534 #ifdef __cplusplus 00535 } 00536 #endif 00537 00538 00539 #endif /* __SENT_HTK_HMM_2_H__ */