00001 00039 /* 00040 * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University 00041 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00042 * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology, Nagoya Institute of Technology 00043 * All rights reserved 00044 */ 00045 00046 #include <sent/stddefs.h> 00047 #include <sent/htk_hmm.h> 00048 #include <sent/htk_param.h> 00049 #include <sent/hmm.h> 00050 #include <sent/gprune.h> 00051 00052 #define GLOBAL_VARIABLE_DEFINE 00053 #include "globalvars.h" 00054 00055 00061 boolean 00062 outprob_init(HTK_HMM_INFO *hmminfo, 00063 HTK_HMM_INFO *gshmm, int gms_num, 00064 int gprune_method, int gprune_mixnum 00065 ) 00066 { 00068 /* select pruning function to compute likelihood of a mixture component 00069 and set the pointer to global */ 00070 switch(gprune_method) { 00071 case GPRUNE_SEL_NONE: 00072 compute_gaussset = gprune_none; 00073 compute_gaussset_init = gprune_none_init; 00074 break; 00075 case GPRUNE_SEL_SAFE: 00076 compute_gaussset = gprune_safe; 00077 compute_gaussset_init = gprune_safe_init; 00078 break; 00079 case GPRUNE_SEL_HEURISTIC: 00080 compute_gaussset = gprune_heu; 00081 compute_gaussset_init = gprune_heu_init; 00082 break; 00083 case GPRUNE_SEL_BEAM: 00084 compute_gaussset = gprune_beam; 00085 compute_gaussset_init = gprune_beam_init; 00086 break; 00087 } 00088 /* select caching function to compute output probability of a mixture */ 00089 if (hmminfo->is_tied_mixture) { 00090 calc_outprob = calc_tied_mix; /* enable book-level cache, typically for a tied-mixture model */ 00091 } else { 00092 calc_outprob = calc_mix; /* no mixture-level cache, for a shared-state, non tied-mixture model */ 00093 } 00094 00095 /* select back-off functon for state probability calculation */ 00096 if (gshmm != NULL) { 00097 calc_outprob_state = gms_state; /* enable GMS */ 00098 } else { 00099 calc_outprob_state = calc_outprob; /* call mixture outprob directly */ 00100 } 00101 00102 /* store common variable to global */ 00103 OP_hmminfo = hmminfo; 00104 OP_gshmm = gshmm; /* NULL if GMS not used */ 00105 OP_gprune_num = gprune_mixnum; 00106 00107 /* generate addlog table */ 00108 make_log_tbl(); 00109 00110 /* initialize work area for mixture component pruning function */ 00111 if (compute_gaussset_init() == FALSE) return FALSE; /* OP_gprune may change */ 00112 /* initialize work area for book level cache on tied-mixture model */ 00113 if (hmminfo->is_tied_mixture) { 00114 if (calc_tied_mix_init() == FALSE) return FALSE; 00115 } 00116 /* initialize work area for GMS */ 00117 if (OP_gshmm != NULL) { 00118 if (gms_init(gms_num) == FALSE) return FALSE; 00119 } 00120 /* initialize cache for all output probabilities */ 00121 if (outprob_cache_init() == FALSE) return FALSE; 00122 00123 /* initialize word area for computation of pseudo HMM set when N-max is specified */ 00124 if (hmminfo->cdset_method == IWCD_NBEST) { 00125 outprob_cd_nbest_init(hmminfo->cdmax_num); 00126 } 00127 00128 return TRUE; 00129 } 00130 00138 boolean 00139 outprob_prepare(int framenum) 00140 { 00141 if (outprob_cache_prepare() == FALSE) return FALSE; 00142 if (OP_gshmm != NULL) { 00143 if (gms_prepare(framenum) == FALSE) return FALSE; 00144 } 00145 if (OP_hmminfo->is_tied_mixture) { 00146 if (calc_tied_mix_prepare(framenum) == FALSE) return FALSE; 00147 } 00148 /* reset last time */ 00149 OP_last_time = OP_time = -1; 00150 return TRUE; 00151 }