libsent/include/sent/htk_hmm.h

Go to the documentation of this file.
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))
00040 #define NoTokErr(S)      if (!rdhmmdef_token) rderr(S)
00041 
00043 #define HMMDEF_DELM " \t\n<>"
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_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[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 
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 
00147 typedef struct _HTK_HMM_state {
00148   char *name;                   
00149   short mix_num;                
00150   HTK_HMM_Dens **b;             
00151   PROB *bweight;                
00152   unsigned short id;            
00153   struct _HTK_HMM_state *next;  
00154 } HTK_HMM_State;
00155 
00157 typedef struct _HTK_HMM_data {
00158   char *name;                   
00159   short state_num;              
00160   HTK_HMM_State **s;            
00161   HTK_HMM_Trans *tr;            
00162   struct _HTK_HMM_data *next;   
00163 } HTK_HMM_Data;
00164 
00166 typedef struct {
00167   char *name;                   
00168   int num;                      
00169   HTK_HMM_Dens **d;             
00170   unsigned short id;            
00171 } GCODEBOOK;
00173 
00175 typedef struct {
00176   HTK_HMM_State *state;         
00177   /* GCODEBOOK *book;*/         /* pointer to the corresponding codebook in hmminfo */
00178 } GS_SET;
00179 
00222 
00223 
00225 typedef struct {
00226   HTK_HMM_State **s;            
00227   unsigned short num;           
00228   unsigned short maxnum;        
00229 } CD_State_Set;
00237 typedef struct _cd_set{
00238   char *name;                   
00239   CD_State_Set *stateset;       
00240   unsigned short state_num;     
00241   HTK_HMM_Trans *tr;            
00242   struct _cd_set *next;         
00243 } CD_Set;
00245 typedef struct {
00246   APATNODE *cdtree;             
00247 } HMM_CDSET_INFO;
00249 
00272 typedef struct _HMM_logical {
00273   char *name;                   
00274   boolean is_pseudo;            
00275 
00276   union {
00277     HTK_HMM_Data *defined;      
00278     CD_Set *pseudo;             
00279   } body;
00280   struct _HMM_logical *next;   
00281 } HMM_Logical;
00282 
00288 typedef struct {
00289   char *name;                   
00290   boolean bgnflag;              
00291   boolean endflag;              
00292 } BASEPHONE;
00298 typedef struct {
00299   int num;                      
00300   int bgnnum;                   
00301   int endnum;                   
00302   APATNODE *root;               
00303 } HMM_basephone;
00304 
00310 typedef struct {
00315   HTK_HMM_Options opt;          
00316   HTK_HMM_Trans *trstart;       
00317   HTK_HMM_Var *vrstart;         
00318   HTK_HMM_Dens *dnstart;        
00319   HTK_HMM_State *ststart;       
00320   HTK_HMM_Data *start;          
00321 
00322 
00327   HMM_Logical *lgstart;         
00328 
00329   
00334   APATNODE *tr_root;            
00335   APATNODE *vr_root;            
00336   APATNODE *dn_root;            
00337   APATNODE *st_root;            
00338   APATNODE *physical_root;      
00339   APATNODE *logical_root;       
00340   APATNODE *codebook_root;      
00341 
00342 
00347   HMM_basephone basephone;      
00348   HMM_CDSET_INFO cdset_info;    
00349 
00350   
00355   boolean need_multipath; 
00356   boolean multipath;            
00357   boolean is_triphone;          
00358   boolean is_tied_mixture;      
00359   short cdset_method;           
00360   short cdmax_num;              
00361   HMM_Logical *sp;              
00362   LOGPROB iwsp_penalty;         
00363   boolean variance_inversed;    
00364   
00365   int totalmixnum;              
00366   int totalstatenum;            
00367   int totalhmmnum;              
00368   int totallogicalnum;          
00369   int totalpseudonum;           
00370   int codebooknum;              
00371   int maxcodebooksize;          
00372   int maxmixturenum;            
00373   int maxstatenum;              
00374 
00375   BMALLOC_BASE *mroot;          
00376   BMALLOC_BASE *lroot;          
00377 
00379 } HTK_HMM_INFO;
00380 
00381 /* init_phmm.c */
00382 void htk_hmm_set_pause_model(HTK_HMM_INFO *hmminfo, char *spmodel_name);
00383 /* rdhmmdef.c */
00384 void rderr(char *str);
00385 char *read_token(FILE *fp);
00386 boolean rdhmmdef(FILE *, HTK_HMM_INFO *);
00387 void htk_hmm_inverse_variances(HTK_HMM_INFO *hmm);
00388 /* rdhmmdef_options.c */
00389 void set_global_opt(FILE *fp, HTK_HMM_INFO *hmm);
00390 char *get_cov_str(short covtype);
00391 char *get_dur_str(short durtype);
00392 /* rdhmmdef_trans.c */
00393 void trans_add(HTK_HMM_INFO *hmm, HTK_HMM_Trans *new);
00394 HTK_HMM_Trans *get_trans_data(FILE *, HTK_HMM_INFO *);
00395 void def_trans_macro(char *, FILE *, HTK_HMM_INFO *);
00396 /* rdhmmdef_state.c */
00397 HTK_HMM_State *get_state_data(FILE *, HTK_HMM_INFO *);
00398 void def_state_macro(char *, FILE *, HTK_HMM_INFO *);
00399 HTK_HMM_State *state_lookup(HTK_HMM_INFO *hmm, char *keyname);
00400 void state_add(HTK_HMM_INFO *hmm, HTK_HMM_State *new);
00401 /* rdhmmdef_dens.c */
00402 HTK_HMM_Dens *get_dens_data(FILE *, HTK_HMM_INFO *);
00403 void def_dens_macro(char *, FILE *, HTK_HMM_INFO *);
00404 HTK_HMM_Dens *dens_lookup(HTK_HMM_INFO *hmm, char *keyname);
00405 void dens_add(HTK_HMM_INFO *hmm, HTK_HMM_Dens *new);
00406 /* rdhmmdef_var.c */
00407 HTK_HMM_Var *get_var_data(FILE *, HTK_HMM_INFO *);
00408 void def_var_macro(char *, FILE *, HTK_HMM_INFO *);
00409 void var_add(HTK_HMM_INFO *hmm, HTK_HMM_Var *new);
00410 /* rdhmmdef_data.c */
00411 void def_HMM(char *, FILE *, HTK_HMM_INFO *);
00412 HTK_HMM_Data *htk_hmmdata_new(HTK_HMM_INFO *);
00413 void htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *new);
00414 /* rdhmmdef_tiedmix.c */
00415 void tmix_read(FILE *fp, HTK_HMM_State *state, HTK_HMM_INFO *hmm);
00416 void codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *new);
00417 /* rdhmmdef_regtree.c */
00418 void def_regtree_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm);
00419 /* rdhmmdef_hmmlist.c */
00420 boolean rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo);
00421 /* put_htkdata_info.c */
00422 void put_htk_trans(FILE *fp, HTK_HMM_Trans *t);
00423 void put_htk_var(FILE *fp, HTK_HMM_Var *v);
00424 void put_htk_dens(FILE *fp, HTK_HMM_Dens *d);
00425 void put_htk_state(FILE *fp, HTK_HMM_State *s);
00426 void put_htk_hmm(FILE *fp, HTK_HMM_Data *h);
00427 void put_logical_hmm(FILE *fp, HMM_Logical *l);
00428 void print_hmmdef_info(FILE *fp, HTK_HMM_INFO *);
00429 
00430 HTK_HMM_INFO *hmminfo_new();
00431 boolean hmminfo_free(HTK_HMM_INFO *);
00432 boolean init_hmminfo(HTK_HMM_INFO *hmminfo, char *filename, char *mapfile, Value *para);
00433 HTK_HMM_Data *htk_hmmdata_lookup_physical(HTK_HMM_INFO *, char *);
00434 HMM_Logical *htk_hmmdata_lookup_logical(HTK_HMM_INFO *, char *);
00435 void hmm_add_physical_to_logical(HTK_HMM_INFO *);
00436 void hmm_add_pseudo_phones(HTK_HMM_INFO *hmminfo);
00437 /* chkhmmlist.c */
00438 void make_hmm_basephone_list(HTK_HMM_INFO *hmminfo);
00439 
00440 /* HMM type check functions */
00441 boolean htk_hmm_has_several_arc_on_edge(HTK_HMM_INFO *hmminfo);
00442 boolean check_hmm_limit(HTK_HMM_Data *dt);
00443 boolean check_all_hmm_limit(HTK_HMM_INFO *hmm);
00444 boolean check_hmm_options(HTK_HMM_INFO *hmm);
00445 boolean is_skippable_model(HTK_HMM_Data *d);
00446 
00447 /* CCD related */
00448 boolean guess_if_cd_hmm(HTK_HMM_INFO *hmm);
00449 HMM_Logical *get_right_context_HMM(HMM_Logical *base, char *rc_name, HTK_HMM_INFO *hmminfo);
00450 HMM_Logical *get_left_context_HMM(HMM_Logical *base, char *lc_name, HTK_HMM_INFO *hmminfo);
00451 void add_right_context(char name[], char *rc);
00452 void add_left_context(char name[], char *lc);
00453 char *center_name(char *hmmname, char *buf);
00454 char *leftcenter_name(char *hmmname, char *buf);
00455 char *rightcenter_name(char *hmmname, char *buf);
00456 
00457 /* CD_SET related */
00458 boolean regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname);
00459 boolean make_cdset(HTK_HMM_INFO *hmminfo);
00460 void put_all_cdinfo(HTK_HMM_INFO *hmminfo);
00461 void free_cdset(APATNODE **root);
00462 CD_Set *cdset_lookup(HTK_HMM_INFO *hmminfo, char *cdstr);
00463 CD_Set *lcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00464 CD_Set *rcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00465 int hmm_logical_state_num(HMM_Logical *lg);
00466 HTK_HMM_Trans *hmm_logical_trans(HMM_Logical *lg);
00467 
00468 #include <sent/htk_param.h>
00469 boolean check_param_coherence(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00470 boolean check_param_basetype(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00471 int param_check_and_adjust(HTK_HMM_INFO *hmm, HTK_Param *pinfo, boolean vflag);
00472 
00473 
00474 /* binary format */
00475 boolean write_binhmm(FILE *fp, HTK_HMM_INFO *hmm, Value *para);
00476 boolean read_binhmm(FILE *fp, HTK_HMM_INFO *hmm, boolean gzfile_p, Value *para);
00477 
00478 #endif /* __SENT_HTK_HMM_2_H__ */

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