00001
00022
00023
00024
00025
00026
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))
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 "+"
00075 #define HMM_LC_DLIM "-"
00076 #define HMM_RC_DLIM_C '+'
00077 #define HMM_LC_DLIM_C '-'
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
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
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 void htk_hmm_set_pause_model(HTK_HMM_INFO *hmminfo, char *spmodel_name);
00418
00419 void rderr(char *str);
00420 char *read_token(FILE *fp);
00421 boolean rdhmmdef(FILE *, HTK_HMM_INFO *);
00422 void htk_hmm_inverse_variances(HTK_HMM_INFO *hmm);
00423 #ifdef ENABLE_MSD
00424 void htk_hmm_check_msd(HTK_HMM_INFO *hmm);
00425 #endif
00426
00427 boolean set_global_opt(FILE *fp, HTK_HMM_INFO *hmm);
00428 char *get_cov_str(short covtype);
00429 char *get_dur_str(short durtype);
00430
00431 void trans_add(HTK_HMM_INFO *hmm, HTK_HMM_Trans *newParam);
00432 HTK_HMM_Trans *get_trans_data(FILE *, HTK_HMM_INFO *);
00433 void def_trans_macro(char *, FILE *, HTK_HMM_INFO *);
00434
00435 HTK_HMM_State *get_state_data(FILE *, HTK_HMM_INFO *);
00436 void def_state_macro(char *, FILE *, HTK_HMM_INFO *);
00437 HTK_HMM_State *state_lookup(HTK_HMM_INFO *hmm, char *keyname);
00438 void state_add(HTK_HMM_INFO *hmm, HTK_HMM_State *newParam);
00439
00440 void mpdf_add(HTK_HMM_INFO *hmm, HTK_HMM_PDF *newParam);
00441 HTK_HMM_PDF *mpdf_lookup(HTK_HMM_INFO *hmm, char *keyname);
00442 HTK_HMM_PDF *get_mpdf_data(FILE *fp, HTK_HMM_INFO *hmm, int mix_num, short stream_id);
00443 void def_mpdf_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm);
00444
00445 HTK_HMM_Dens *get_dens_data(FILE *, HTK_HMM_INFO *);
00446 void def_dens_macro(char *, FILE *, HTK_HMM_INFO *);
00447 HTK_HMM_Dens *dens_lookup(HTK_HMM_INFO *hmm, char *keyname);
00448 void dens_add(HTK_HMM_INFO *hmm, HTK_HMM_Dens *newParam);
00449
00450 HTK_HMM_Var *get_var_data(FILE *, HTK_HMM_INFO *);
00451 void def_var_macro(char *, FILE *, HTK_HMM_INFO *);
00452 void var_add(HTK_HMM_INFO *hmm, HTK_HMM_Var *newParam);
00453
00454 HTK_HMM_StreamWeight *get_streamweight_data(FILE *fp, HTK_HMM_INFO *hmm);
00455 void def_streamweight_macro(char *, FILE *, HTK_HMM_INFO *);
00456 void sw_add(HTK_HMM_INFO *hmm, HTK_HMM_StreamWeight *newParam);
00457
00458 void def_HMM(char *, FILE *, HTK_HMM_INFO *);
00459 HTK_HMM_Data *htk_hmmdata_new(HTK_HMM_INFO *);
00460 void htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *newParam);
00461
00462 void tmix_read(FILE *fp, HTK_HMM_PDF *mpdf, HTK_HMM_INFO *hmm);
00463 void codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *newParam);
00464
00465 void def_regtree_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm);
00466
00467 boolean rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo);
00468 boolean save_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo);
00469 boolean load_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo);
00470
00471
00472 void put_htk_trans(FILE *fp, HTK_HMM_Trans *t);
00473 void put_htk_var(FILE *fp, HTK_HMM_Var *v);
00474 void put_htk_dens(FILE *fp, HTK_HMM_Dens *d);
00475 void put_htk_mpdf(FILE *fp, HTK_HMM_PDF *m);
00476 void put_htk_state(FILE *fp, HTK_HMM_State *s);
00477 void put_htk_hmm(FILE *fp, HTK_HMM_Data *h);
00478 void put_logical_hmm(FILE *fp, HMM_Logical *l);
00479 void print_hmmdef_info(FILE *fp, HTK_HMM_INFO *);
00480
00481 HTK_HMM_INFO *hmminfo_new();
00482 boolean hmminfo_free(HTK_HMM_INFO *);
00483 boolean init_hmminfo(HTK_HMM_INFO *hmminfo, char *filename, char *mapfile, Value *para);
00484 HTK_HMM_Data *htk_hmmdata_lookup_physical(HTK_HMM_INFO *, char *);
00485 HMM_Logical *htk_hmmdata_lookup_logical(HTK_HMM_INFO *, char *);
00486 void hmm_add_physical_to_logical(HTK_HMM_INFO *);
00487 void hmm_add_pseudo_phones(HTK_HMM_INFO *hmminfo);
00488
00489 void make_hmm_basephone_list(HTK_HMM_INFO *hmminfo);
00490
00491
00492 boolean htk_hmm_has_several_arc_on_edge(HTK_HMM_INFO *hmminfo);
00493 boolean check_hmm_limit(HTK_HMM_Data *dt);
00494 boolean check_all_hmm_limit(HTK_HMM_INFO *hmm);
00495 boolean check_hmm_options(HTK_HMM_INFO *hmm);
00496 boolean is_skippable_model(HTK_HMM_Data *d);
00497
00498
00499 boolean guess_if_cd_hmm(HTK_HMM_INFO *hmm);
00500 HMM_Logical *get_right_context_HMM(HMM_Logical *base, char *rc_name, HTK_HMM_INFO *hmminfo);
00501 HMM_Logical *get_left_context_HMM(HMM_Logical *base, char *lc_name, HTK_HMM_INFO *hmminfo);
00502 void add_right_context(char name[], char *rc);
00503 void add_left_context(char name[], char *lc);
00504 char *center_name(char *hmmname, char *buf);
00505 char *leftcenter_name(char *hmmname, char *buf);
00506 char *rightcenter_name(char *hmmname, char *buf);
00507
00508
00509 boolean regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname, BMALLOC_BASE **mroot);
00510 boolean make_cdset(HTK_HMM_INFO *hmminfo);
00511 void put_all_cdinfo(HTK_HMM_INFO *hmminfo);
00512 void free_cdset(APATNODE **root, BMALLOC_BASE **mroot);
00513 CD_Set *cdset_lookup(HTK_HMM_INFO *hmminfo, char *cdstr);
00514 CD_Set *lcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00515 CD_Set *rcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00516 int hmm_logical_state_num(HMM_Logical *lg);
00517 HTK_HMM_Trans *hmm_logical_trans(HMM_Logical *lg);
00518
00519 #include <sent/htk_param.h>
00520 boolean check_param_coherence(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00521 boolean check_param_basetype(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00522 int param_check_and_adjust(HTK_HMM_INFO *hmm, HTK_Param *pinfo, boolean vflag);
00523
00524
00525
00526 boolean write_binhmm(FILE *fp, HTK_HMM_INFO *hmm, Value *para);
00527 boolean read_binhmm(FILE *fp, HTK_HMM_INFO *hmm, boolean gzfile_p, Value *para);
00528
00529 #endif