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

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 "dict.h"
00058 
00062 typedef struct ps_search_s ps_search_t;
00063 
00067 typedef struct ps_searchfuncs_s {
00068     char const *name;
00069 
00070     int (*start)(ps_search_t *search);
00071     int (*step)(ps_search_t *search);
00072     int (*finish)(ps_search_t *search);
00073     int (*reinit)(ps_search_t *search);
00074     void (*free)(ps_search_t *search);
00075 
00076     ps_lattice_t *(*lattice)(ps_search_t *search);
00077     char const *(*hyp)(ps_search_t *search, int32 *out_score);
00078     int32 (*prob)(ps_search_t *search);
00079     ps_seg_t *(*seg_iter)(ps_search_t *search, int32 *out_score);
00080 } ps_searchfuncs_t;
00081 
00085 struct ps_search_s {
00086     ps_searchfuncs_t *vt;  
00087     cmd_ln_t *config;      
00088     acmod_t *acmod;        
00089     dict_t *dict;          
00090     char *hyp_str;         
00091     ps_lattice_t *dag;     
00092     ps_latlink_t *last_link; 
00093     int32 post;            
00095     /* Magical word IDs that must exist in the dictionary: */
00096     int32 start_wid;       
00097     int32 silence_wid;     
00098     int32 finish_wid;      
00099 };
00100 
00101 #define ps_search_base(s) ((ps_search_t *)s)
00102 #define ps_search_config(s) ps_search_base(s)->config
00103 #define ps_search_acmod(s) ps_search_base(s)->acmod
00104 #define ps_search_dict(s) ps_search_base(s)->dict
00105 #define ps_search_dag(s) ps_search_base(s)->dag
00106 #define ps_search_last_link(s) ps_search_base(s)->last_link
00107 #define ps_search_post(s) ps_search_base(s)->post
00108 
00109 #define ps_search_name(s) ps_search_base(s)->vt->name
00110 #define ps_search_start(s) (*(ps_search_base(s)->vt->start))(s)
00111 #define ps_search_step(s) (*(ps_search_base(s)->vt->step))(s)
00112 #define ps_search_finish(s) (*(ps_search_base(s)->vt->finish))(s)
00113 #define ps_search_reinit(s) (*(ps_search_base(s)->vt->reinit))(s)
00114 #define ps_search_free(s) (*(ps_search_base(s)->vt->free))(s)
00115 #define ps_search_lattice(s) (*(ps_search_base(s)->vt->lattice))(s)
00116 #define ps_search_hyp(s,sc) (*(ps_search_base(s)->vt->hyp))(s,sc)
00117 #define ps_search_prob(s) (*(ps_search_base(s)->vt->prob))(s)
00118 #define ps_search_seg_iter(s,sc) (*(ps_search_base(s)->vt->seg_iter))(s,sc)
00119 
00120 /* For convenience... */
00121 #define ps_search_n_words(s) dict_n_words(ps_search_dict(s))
00122 #define ps_search_silence_wid(s) ps_search_base(s)->silence_wid
00123 #define ps_search_start_wid(s) ps_search_base(s)->start_wid
00124 #define ps_search_finish_wid(s) ps_search_base(s)->finish_wid
00125 
00126 /* FIXME: This code makes some irritating assumptions about the
00127  * ordering of the dictionary. */
00128 #define ISA_FILLER_WORD(s,x)    ((x) ? (x) >= ps_search_silence_wid(s) : FALSE)
00129 #define ISA_REAL_WORD(s,x)      ((x) ? (x) < ps_search_finish_wid(s) : TRUE)
00130 
00134 void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt,
00135                     cmd_ln_t *config, acmod_t *acmod, dict_t *dict);
00136 
00140 void ps_search_deinit(ps_search_t *search);
00141 
00142 typedef struct ps_segfuncs_s {
00143     ps_seg_t *(*seg_next)(ps_seg_t *seg);
00144     void (*seg_free)(ps_seg_t *seg);
00145 } ps_segfuncs_t;
00146 
00150 struct ps_seg_s {
00151     ps_segfuncs_t *vt;     
00152     ps_search_t *search;   
00153     char const *word;      
00154     int16 sf;                
00155     int16 ef;                
00156     int32 ascr;            
00157     int32 lscr;            
00158     int32 prob;            
00159     /* This doesn't need to be 32 bits, so once the scores above are
00160      * reduced to 16 bits (or less!), this will be too. */
00161     int32 lback;           
00162     /* Not sure if this should be here at all. */
00163     float32 lwf;           
00164 };
00165 
00166 #define ps_search_seg_next(seg) (*(seg->vt->seg_next))(seg)
00167 #define ps_search_seg_free(s) (*(seg->vt->seg_free))(seg)
00168 
00169 
00173 struct ps_decoder_s {
00174     /* Model parameters and such. */
00175     cmd_ln_t *config;  
00176     int refcount;      
00178     /* Basic units of computation. */
00179     acmod_t *acmod;    
00180     dict_t *dict;      
00181     logmath_t *lmath;  
00183     /* Search modules. */
00184     glist_t searches;   
00185     ps_search_t *search; 
00187     /* Utterance-processing related stuff. */
00188     uint32 uttno;       
00189     char *uttid;        
00190     ptmr_t perf;        
00191     uint32 n_frame;     
00192     char const *mfclogdir; 
00193     char const *rawlogdir; 
00194 };
00195 
00196 #endif /* __POCKETSPHINX_INTERNAL_H__ */

Generated on Thu Jan 27 2011 for PocketSphinx by  doxygen 1.7.1