• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

src/libpocketsphinx/hmm.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00037 
00042 #ifndef __HMM_H__
00043 #define __HMM_H__
00044 
00045 /* System headers. */
00046 #include <stdio.h>
00047 
00048 /* SphinxBase headers. */
00049 #include <fixpoint.h>
00050 #include <listelem_alloc.h>
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 #if 0
00056 } /* Fool Emacs into not indenting things. */
00057 #endif
00058 
00060 #define SENSCR_SHIFT 10
00061 
00072 #define WORST_SCORE             ((int)0xE0000000)
00073 
00074 #ifdef FIXED_POINT
00075 
00076 typedef fixed32 mean_t;
00077 typedef int32 var_t;
00078 #else
00079 typedef float32 mean_t;
00080 typedef float32 var_t;
00081 #endif
00082 
00127 typedef struct hmm_context_s {
00128     int32 n_emit_state;     
00129     int32 ** const *tp;     
00130     int16 const *senscore;  
00132     int16 * const *sseq;    
00133     int32 *st_sen_scr;      
00134     listelem_alloc_t *mpx_ssid_alloc; 
00135     void *udata;            
00136 } hmm_context_t;
00137 
00142 typedef struct {
00143     int32 score;        
00144     int32 history;      
00145 } hmm_state_t;
00146 
00150 #define HMM_MAX_NSTATE 5
00151 
00160 typedef struct hmm_s {
00161     hmm_context_t *ctx;   
00162     hmm_state_t state[HMM_MAX_NSTATE]; 
00163     hmm_state_t out;      
00164     union {
00165         int32 *mpx_ssid; 
00166         int32 ssid;      
00167     } s;
00168     int32 bestscore;    
00169     int16 tmatid;       
00170     int16 frame;        
00171     uint8 mpx;          
00172     uint8 n_emit_state; 
00173 } hmm_t;
00174 
00176 #define hmm_context(h) (h)->ctx
00177 #define hmm_is_mpx(h) (h)->mpx
00178 #define hmm_state(h,st) (h)->state[st]
00179 
00180 #define hmm_in_score(h) hmm_state(h,0).score
00181 #define hmm_score(h,st) hmm_state(h,st).score
00182 #define hmm_out_score(h) (h)->out.score
00183 
00184 #define hmm_in_history(h) hmm_state(h,0).history
00185 #define hmm_history(h,st) hmm_state(h,st).history
00186 #define hmm_out_history(h) (h)->out.history
00187 
00188 #define hmm_bestscore(h) (h)->bestscore
00189 #define hmm_frame(h) (h)->frame
00190 #define hmm_mpx_ssid(h,st) (h)->s.mpx_ssid[st]
00191 #define hmm_nonmpx_ssid(h) (h)->s.ssid
00192 #define hmm_ssid(h,st) (hmm_is_mpx(h)                           \
00193                         ? hmm_mpx_ssid(h,st) : (h)->s.ssid)
00194 #define hmm_senid(h,st) (hmm_ssid(h,st) == -1                           \
00195                          ? -1 : (h)->ctx->sseq[hmm_ssid(h,st)][st])
00196 #define hmm_senscr(h,st) (hmm_ssid(h,st) == -1                          \
00197                           ? WORST_SCORE                                 \
00198                           : -(h)->ctx->senscore[hmm_senid(h,st)] << SENSCR_SHIFT)
00199 #define hmm_tmatid(h) (h)->tmatid
00200 #define hmm_tprob(h,i,j) (h)->ctx->tp[hmm_tmatid(h)][i][j]
00201 #define hmm_n_emit_state(h) ((h)->n_emit_state)
00202 #define hmm_n_state(h) ((h)->n_emit_state + 1)
00203 
00207 hmm_context_t *hmm_context_init(int32 n_emit_state,
00208                                 int32 ** const *tp,
00209                                 int16 const *senscore,
00210                                 int16 * const *sseq);
00211 
00215 #define hmm_context_set_senscore(ctx, senscr) ((ctx)->senscore = (senscr))
00216 
00224 void hmm_context_free(hmm_context_t *ctx);
00225 
00229 void hmm_init(hmm_context_t *ctx, hmm_t *hmm, int mpx, int ssid, int tmatid);
00230 
00234 void hmm_deinit(hmm_t *hmm);
00235 
00241 void hmm_clear(hmm_t *h);
00242 
00246 void hmm_clear_scores(hmm_t *h);
00247 
00251 void hmm_normalize(hmm_t *h, int32 bestscr);
00252 
00256 void hmm_enter(hmm_t *h, int32 score,
00257                int32 histid, int frame);
00258 
00271 int32 hmm_vit_eval(hmm_t *hmm);
00272   
00273 
00277 int32 hmm_dump_vit_eval(hmm_t *hmm,  
00278                         FILE *fp 
00279     );
00280 
00285 void hmm_dump(hmm_t *h,  
00286               FILE *fp 
00287     );
00288 
00289 
00290 #if 0
00291 { /* Stop indent from complaining */
00292 #endif
00293 #ifdef __cplusplus
00294 }
00295 #endif
00296 
00297 #endif /* __HMM_H__ */

Generated on Thu Jan 27 2011 for PocketSphinx by  doxygen 1.7.1