src/libpocketsphinx/pocketsphinx_internal.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 2008 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 
00044 #ifndef __POCKETSPHINX_INTERNAL_H__
00045 #define __POCKETSPHINX_INTERNAL_H__
00046 
00047 /* SphinxBase headers. */
00048 #include <cmd_ln.h>
00049 #include <logmath.h>
00050 #include <fe.h>
00051 #include <feat.h>
00052 #include <profile.h>
00053 
00054 /* Local headers. */
00055 #include "pocketsphinx.h"
00056 #include "acmod.h"
00057 #include "s3dict.h"
00058 #include "dict2pid.h"
00059 
00063 typedef struct ps_search_s ps_search_t;
00064 
00068 typedef struct ps_searchfuncs_s {
00069     char const *name;
00070 
00071     int (*start)(ps_search_t *search);
00072     int (*step)(ps_search_t *search, int frame_idx);
00073     int (*finish)(ps_search_t *search);
00074     int (*reinit)(ps_search_t *search);
00075     void (*free)(ps_search_t *search);
00076 
00077     ps_lattice_t *(*lattice)(ps_search_t *search);
00078     char const *(*hyp)(ps_search_t *search, int32 *out_score);
00079     int32 (*prob)(ps_search_t *search);
00080     ps_seg_t *(*seg_iter)(ps_search_t *search, int32 *out_score);
00081 } ps_searchfuncs_t;
00082 
00086 struct ps_search_s {
00087     ps_searchfuncs_t *vt;  
00088     ps_search_t *pls;      
00089     cmd_ln_t *config;      
00090     acmod_t *acmod;        
00091     s3dict_t *dict;        
00092     dict2pid_t *d2p;       
00093     char *hyp_str;         
00094     ps_lattice_t *dag;     
00095     ps_latlink_t *last_link; 
00096     int32 post;            
00098     /* Magical word IDs that must exist in the dictionary: */
00099     int32 start_wid;       
00100     int32 silence_wid;     
00101     int32 finish_wid;      
00102 };
00103 
00104 #define ps_search_base(s) ((ps_search_t *)s)
00105 #define ps_search_config(s) ps_search_base(s)->config
00106 #define ps_search_acmod(s) ps_search_base(s)->acmod
00107 #define ps_search_dict(s) ps_search_base(s)->dict
00108 #define ps_search_dict2pid(s) ps_search_base(s)->d2p
00109 #define ps_search_dag(s) ps_search_base(s)->dag
00110 #define ps_search_last_link(s) ps_search_base(s)->last_link
00111 #define ps_search_post(s) ps_search_base(s)->post
00112 #define ps_search_lookahead(s) ps_search_base(s)->pls
00113 
00114 #define ps_search_name(s) ps_search_base(s)->vt->name
00115 #define ps_search_start(s) (*(ps_search_base(s)->vt->start))(s)
00116 #define ps_search_step(s,i) (*(ps_search_base(s)->vt->step))(s,i)
00117 #define ps_search_finish(s) (*(ps_search_base(s)->vt->finish))(s)
00118 #define ps_search_reinit(s) (*(ps_search_base(s)->vt->reinit))(s)
00119 #define ps_search_free(s) (*(ps_search_base(s)->vt->free))(s)
00120 #define ps_search_lattice(s) (*(ps_search_base(s)->vt->lattice))(s)
00121 #define ps_search_hyp(s,sc) (*(ps_search_base(s)->vt->hyp))(s,sc)
00122 #define ps_search_prob(s) (*(ps_search_base(s)->vt->prob))(s)
00123 #define ps_search_seg_iter(s,sc) (*(ps_search_base(s)->vt->seg_iter))(s,sc)
00124 
00125 /* For convenience... */
00126 #define ps_search_n_words(s) s3dict_size(ps_search_dict(s))
00127 #define ps_search_silence_wid(s) ps_search_base(s)->silence_wid
00128 #define ps_search_start_wid(s) ps_search_base(s)->start_wid
00129 #define ps_search_finish_wid(s) ps_search_base(s)->finish_wid
00130 
00134 void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt,
00135                     cmd_ln_t *config, acmod_t *acmod, s3dict_t *dict,
00136                     dict2pid_t *d2p);
00137 
00141 void ps_search_deinit(ps_search_t *search);
00142 
00143 typedef struct ps_segfuncs_s {
00144     ps_seg_t *(*seg_next)(ps_seg_t *seg);
00145     void (*seg_free)(ps_seg_t *seg);
00146 } ps_segfuncs_t;
00147 
00151 struct ps_seg_s {
00152     ps_segfuncs_t *vt;     
00153     ps_search_t *search;   
00154     char const *word;      
00155     int16 sf;                
00156     int16 ef;                
00157     int32 ascr;            
00158     int32 lscr;            
00159     int32 prob;            
00160     /* This doesn't need to be 32 bits, so once the scores above are
00161      * reduced to 16 bits (or less!), this will be too. */
00162     int32 lback;           
00163     /* Not sure if this should be here at all. */
00164     float32 lwf;           
00165 };
00166 
00167 #define ps_search_seg_next(seg) (*(seg->vt->seg_next))(seg)
00168 #define ps_search_seg_free(s) (*(seg->vt->seg_free))(seg)
00169 
00170 
00174 struct ps_decoder_s {
00175     /* Model parameters and such. */
00176     cmd_ln_t *config;  
00177     int refcount;      
00179     /* Basic units of computation. */
00180     acmod_t *acmod;    
00181     s3dict_t *dict;    
00182     dict2pid_t *d2p;   
00183     logmath_t *lmath;  
00185     /* Search modules. */
00186     glist_t searches;        
00187     ps_search_t *search;     
00188     ps_search_t *phone_loop; 
00189     int pl_window;           
00191     /* Utterance-processing related stuff. */
00192     uint32 uttno;       
00193     char *uttid;        
00194     ptmr_t perf;        
00195     uint32 n_frame;     
00196     char const *mfclogdir; 
00197     char const *rawlogdir; 
00198 };
00199 
00200 #endif /* __POCKETSPHINX_INTERNAL_H__ */

Generated on Mon Jan 24 21:50:16 2011 for PocketSphinx by  doxygen 1.4.7