00001
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __SENT_HTK_HMM_2_H__
00029 #define __SENT_HTK_HMM_2_H__
00030
00031 #include <sent/stddefs.h>
00032 #include <sent/htk_defs.h>
00033 #include <sent/ptree.h>
00034 #include <sent/mfcc.h>
00035
00037 #define currentis(A) (!strcasecmp(A, rdhmmdef_token))
00039 #define NoTokErr(S) if (!rdhmmdef_token) rderr(S)
00040
00042 #define HMMDEF_DELM " \t\n<>"
00043
00044
00068
00069
00071 #define MAX_STATE_NUM 65535
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 128
00084
00086 enum iwcd_type {
00087 IWCD_MAX,
00088 IWCD_AVG,
00089 IWCD_NBEST
00090 };
00091
00092
00093
00094
00096 typedef struct {
00097 short num;
00098 short vsize[50];
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
00110
00112 typedef struct _HTK_HMM_trans {
00113 char *name;
00114 short statenum;
00115 PROB **a;
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
00148 typedef struct _HTK_HMM_state {
00149 char *name;
00150 short mix_num;
00151 HTK_HMM_Dens **b;
00152 PROB *bweight;
00153 unsigned short id;
00154 struct _HTK_HMM_state *next;
00155 } HTK_HMM_State;
00156
00158 typedef struct _HTK_HMM_data {
00159 char *name;
00160 short state_num;
00161 HTK_HMM_State **s;
00162 HTK_HMM_Trans *tr;
00163 struct _HTK_HMM_data *next;
00164 } HTK_HMM_Data;
00165
00167 typedef struct {
00168 char *name;
00169 int num;
00170 HTK_HMM_Dens **d;
00171 unsigned short id;
00172 } GCODEBOOK;
00174
00176 typedef struct {
00177 HTK_HMM_State *state;
00178
00179 } GS_SET;
00180
00181
00224
00225
00227 typedef struct {
00228 HTK_HMM_State **s;
00229 unsigned short num;
00230 unsigned short maxnum;
00231 } CD_State_Set;
00239 typedef struct _cd_set{
00240 char *name;
00241 CD_State_Set *stateset;
00242 unsigned short state_num;
00243 HTK_HMM_Trans *tr;
00244 struct _cd_set *next;
00245 } CD_Set;
00247 typedef struct {
00248 APATNODE *cdtree;
00249 } HMM_CDSET_INFO;
00251
00252
00275 typedef struct _HMM_logical {
00276 char *name;
00277 boolean is_pseudo;
00278
00279 union {
00280 HTK_HMM_Data *defined;
00281 CD_Set *pseudo;
00282 } body;
00283 struct _HMM_logical *next;
00284 } HMM_Logical;
00285
00291 typedef struct {
00292 char *name;
00293 boolean bgnflag;
00294 boolean endflag;
00295 } BASEPHONE;
00301 typedef struct {
00302 int num;
00303 int bgnnum;
00304 int endnum;
00305 APATNODE *root;
00306 } HMM_basephone;
00307
00313 typedef struct {
00318 HTK_HMM_Options opt;
00319 HTK_HMM_Trans *trstart;
00320 HTK_HMM_Var *vrstart;
00321 HTK_HMM_Dens *dnstart;
00322 HTK_HMM_State *ststart;
00323 HTK_HMM_Data *start;
00324
00325
00330 HMM_Logical *lgstart;
00331
00332
00337 APATNODE *tr_root;
00338 APATNODE *vr_root;
00339 APATNODE *dn_root;
00340 APATNODE *st_root;
00341 APATNODE *physical_root;
00342 APATNODE *logical_root;
00343 APATNODE *codebook_root;
00344
00345
00350 HMM_basephone basephone;
00351 HMM_CDSET_INFO cdset_info;
00352
00353
00358 boolean is_triphone;
00359 boolean is_tied_mixture;
00360 short cdset_method;
00361 short cdmax_num;
00362 HMM_Logical *sp;
00363 #ifdef MULTIPATH_VERSION
00364 LOGPROB iwsp_penalty;
00365 #endif
00366 boolean variance_inversed;
00367
00368 int totalmixnum;
00369 int totalstatenum;
00370 int totalhmmnum;
00371 int totallogicalnum;
00372 int totalpseudonum;
00373 int codebooknum;
00374 int maxcodebooksize;
00375 int maxmixturenum;
00376 int maxstatenum;
00377
00378 BMALLOC_BASE *mroot;
00379 BMALLOC_BASE *lroot;
00380
00382 } HTK_HMM_INFO;
00383
00384
00385
00386
00387 void htk_hmm_set_pause_model(HTK_HMM_INFO *hmminfo, char *spmodel_name);
00388
00389 void rderr(char *str);
00390 char *read_token(FILE *fp);
00391 boolean rdhmmdef(FILE *, HTK_HMM_INFO *);
00392 void htk_hmm_inverse_variances(HTK_HMM_INFO *hmm);
00393
00394 void set_global_opt(FILE *fp, HTK_HMM_INFO *hmm);
00395 char *get_cov_str(short covtype);
00396 char *get_dur_str(short durtype);
00397
00398 void trans_add(HTK_HMM_INFO *hmm, HTK_HMM_Trans *new);
00399 HTK_HMM_Trans *get_trans_data(FILE *, HTK_HMM_INFO *);
00400 void def_trans_macro(char *, FILE *, HTK_HMM_INFO *);
00401
00402 HTK_HMM_State *get_state_data(FILE *, HTK_HMM_INFO *);
00403 void def_state_macro(char *, FILE *, HTK_HMM_INFO *);
00404 HTK_HMM_State *state_lookup(HTK_HMM_INFO *hmm, char *keyname);
00405 void state_add(HTK_HMM_INFO *hmm, HTK_HMM_State *new);
00406
00407 HTK_HMM_Dens *get_dens_data(FILE *, HTK_HMM_INFO *);
00408 void def_dens_macro(char *, FILE *, HTK_HMM_INFO *);
00409 HTK_HMM_Dens *dens_lookup(HTK_HMM_INFO *hmm, char *keyname);
00410 void dens_add(HTK_HMM_INFO *hmm, HTK_HMM_Dens *new);
00411
00412 HTK_HMM_Var *get_var_data(FILE *, HTK_HMM_INFO *);
00413 void def_var_macro(char *, FILE *, HTK_HMM_INFO *);
00414 void var_add(HTK_HMM_INFO *hmm, HTK_HMM_Var *new);
00415
00416 void def_HMM(char *, FILE *, HTK_HMM_INFO *);
00417 HTK_HMM_Data *htk_hmmdata_new(HTK_HMM_INFO *);
00418 void htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *new);
00419
00420 void tmix_read(FILE *fp, HTK_HMM_State *state, HTK_HMM_INFO *hmm);
00421 void codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *new);
00422
00423 void def_regtree_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm);
00424
00425 boolean rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo);
00426
00427 void put_htk_trans(HTK_HMM_Trans *t);
00428 void put_htk_var(HTK_HMM_Var *v);
00429 void put_htk_dens(HTK_HMM_Dens *d);
00430 void put_htk_state(HTK_HMM_State *s);
00431 void put_htk_hmm(HTK_HMM_Data *h);
00432 void put_logical_hmm(HMM_Logical *l);
00433 void print_hmmdef_info(HTK_HMM_INFO *);
00434 HTK_HMM_INFO *hmminfo_new();
00435 boolean hmminfo_free(HTK_HMM_INFO *);
00436 void init_hmminfo(HTK_HMM_INFO *hmminfo, char *filename, char *mapfile, Value *para);
00437 HTK_HMM_Data *htk_hmmdata_lookup_physical(HTK_HMM_INFO *, char *);
00438 HMM_Logical *htk_hmmdata_lookup_logical(HTK_HMM_INFO *, char *);
00439 void hmm_add_physical_to_logical(HTK_HMM_INFO *);
00440 void hmm_add_pseudo_phones(HTK_HMM_INFO *hmminfo);
00441
00442 void make_hmm_basephone_list(HTK_HMM_INFO *hmminfo);
00443
00444
00445 boolean check_hmm_limit(HTK_HMM_Data *dt);
00446 boolean check_all_hmm_limit(HTK_HMM_INFO *hmm);
00447 boolean check_hmm_options(HTK_HMM_INFO *hmm);
00448 #ifdef MULTIPATH_VERSION
00449 boolean is_skippable_model(HTK_HMM_Data *d);
00450 #endif
00451
00452
00453 boolean guess_if_cd_hmm(HTK_HMM_INFO *hmm);
00454 HMM_Logical *get_right_context_HMM(HMM_Logical *base, char *rc_name, HTK_HMM_INFO *hmminfo);
00455 HMM_Logical *get_left_context_HMM(HMM_Logical *base, char *lc_name, HTK_HMM_INFO *hmminfo);
00456 void add_right_context(char name[], char *rc);
00457 void add_left_context(char name[], char *lc);
00458 char *center_name(char *hmmname, char *buf);
00459 char *leftcenter_name(char *hmmname, char *buf);
00460 char *rightcenter_name(char *hmmname, char *buf);
00461
00462
00463 boolean regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname);
00464 boolean make_cdset(HTK_HMM_INFO *hmminfo);
00465 void put_all_cdinfo(HTK_HMM_INFO *hmminfo);
00466 void free_cdset(APATNODE **root);
00467 CD_Set *cdset_lookup(HTK_HMM_INFO *hmminfo, char *cdstr);
00468 CD_Set *lcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00469 CD_Set *rcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00470 int hmm_logical_state_num(HMM_Logical *lg);
00471 HTK_HMM_Trans *hmm_logical_trans(HMM_Logical *lg);
00472
00473 #include <sent/htk_param.h>
00474 boolean check_param_coherence(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00475 boolean check_param_basetype(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00476 HTK_Param *new_param_check_and_adjust(HTK_HMM_INFO *hmm, HTK_Param *pinfo, boolean vflag);
00477
00478
00479
00480 boolean write_binhmm(FILE *fp, HTK_HMM_INFO *hmm, Value *para);
00481 boolean read_binhmm(FILE *fp, HTK_HMM_INFO *hmm, boolean gzfile_p, Value *para);
00482
00483 #endif