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

src/libpocketsphinx/acmod.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 
00043 #ifndef __ACMOD_H__
00044 #define __ACMOD_H__
00045 
00046 /* System headers. */
00047 #include <stdio.h>
00048 
00049 /* SphinxBase headers. */
00050 #include <cmd_ln.h>
00051 #include <logmath.h>
00052 #include <fe.h>
00053 #include <feat.h>
00054 #include <bitvec.h>
00055 #include <err.h>
00056 
00057 /* Local headers. */
00058 #include "ps_mllr.h"
00059 #include "bin_mdef.h"
00060 #include "tmat.h"
00061 #include "hmm.h"
00062 
00066 typedef enum acmod_state_e {
00067     ACMOD_IDLE,         
00068     ACMOD_STARTED,      
00069     ACMOD_PROCESSING,   
00070     ACMOD_ENDED         
00071 } acmod_state_t;
00072 
00076 struct ps_mllr_s {
00077     int refcnt;     
00078     int n_class;    
00079     int n_feat;     
00080     int *veclen;    
00081     float32 ****A;  
00082     float32 ***b;   
00083     float32 ***h;   
00084     int32 *cb2mllr; 
00085 };
00086 
00090 typedef struct ps_mgau_s ps_mgau_t;
00091 
00092 typedef struct ps_mgaufuncs_s {
00093     char const *name;
00094 
00095     int (*frame_eval)(ps_mgau_t *mgau,
00096                       int16 *senscr,
00097                       uint8 *senone_active,
00098                       int32 n_senone_active,
00099                       mfcc_t ** feat,
00100                       int32 frame,
00101                       int32 compallsen);
00102     int (*transform)(ps_mgau_t *mgau,
00103                      ps_mllr_t *mllr);
00104     void (*free)(ps_mgau_t *mgau);
00105 } ps_mgaufuncs_t;    
00106 
00107 struct ps_mgau_s {
00108     ps_mgaufuncs_t *vt;  
00109     int frame_idx;       
00110 };
00111 
00112 #define ps_mgau_base(mg) ((ps_mgau_t *)(mg))
00113 #define ps_mgau_frame_eval(mg,senscr,senone_active,n_senone_active,feat,frame,compallsen) \
00114     (*ps_mgau_base(mg)->vt->frame_eval)                                 \
00115     (mg, senscr, senone_active, n_senone_active, feat, frame, compallsen)
00116 #define ps_mgau_transform(mg, mllr)                                  \
00117     (*ps_mgau_base(mg)->vt->transform)(mg, mllr)
00118 #define ps_mgau_free(mg)                                  \
00119     (*ps_mgau_base(mg)->vt->free)(mg)
00120 
00142 struct acmod_s {
00143     /* Global objects, not retained. */
00144     cmd_ln_t *config;          
00145     logmath_t *lmath;          
00146     glist_t strings;           
00148     /* Feature computation: */
00149     fe_t *fe;                  
00150     feat_t *fcb;               
00152     /* Model parameters: */
00153     bin_mdef_t *mdef;          
00154     tmat_t *tmat;              
00155     ps_mgau_t *mgau;           
00156     ps_mllr_t *mllr;           
00158     /* Senone scoring: */
00159     int16 *senone_scores;      
00160     bitvec_t *senone_active_vec; 
00161     uint8 *senone_active;      
00162     int senscr_frame;          
00163     int n_senone_active;       
00164     int log_zero;              
00166     /* Utterance processing: */
00167     mfcc_t **mfc_buf;   
00168     mfcc_t ***feat_buf; 
00169     FILE *rawfh;        
00170     FILE *mfcfh;        
00172     /* A whole bunch of flags and counters: */
00173     uint8 state;        
00174     uint8 compallsen;   
00175     uint8 grow_feat;    
00176     uint8 reserved;
00177     int16 output_frame; 
00178     int16 n_mfc_alloc;  
00179     int16 n_mfc_frame;  
00180     int16 mfc_outidx;   
00181     int16 n_feat_alloc; 
00182     int16 n_feat_frame; 
00183     int16 feat_outidx;  
00184 };
00185 typedef struct acmod_s acmod_t;
00186 
00203 acmod_t *acmod_init(cmd_ln_t *config, logmath_t *lmath, fe_t *fe, feat_t *fcb);
00204 
00216 ps_mllr_t *acmod_update_mllr(acmod_t *acmod, ps_mllr_t *mllr);
00217 
00225 int acmod_set_mfcfh(acmod_t *acmod, FILE *logfh);
00226 
00234 int acmod_set_rawfh(acmod_t *acmod, FILE *logfh);
00235 
00239 void acmod_free(acmod_t *acmod);
00240 
00244 int acmod_start_utt(acmod_t *acmod);
00245 
00249 int acmod_end_utt(acmod_t *acmod);
00250 
00263 int acmod_rewind(acmod_t *acmod);
00264 
00274 int acmod_advance(acmod_t *acmod);
00275 
00284 int acmod_set_grow(acmod_t *acmod, int grow_feat);
00285 
00304 int acmod_process_raw(acmod_t *acmod,
00305                       int16 const **inout_raw,
00306                       size_t *inout_n_samps,
00307                       int full_utt);
00308 
00320 int acmod_process_cep(acmod_t *acmod,
00321                       mfcc_t ***inout_cep,
00322                       int *inout_n_frames,
00323                       int full_utt);
00324 
00338 int acmod_process_feat(acmod_t *acmod,
00339                        mfcc_t **feat);
00340 
00354 int16 const *acmod_score(acmod_t *acmod,
00355                          int *inout_frame_idx);
00356 
00360 int acmod_best_score(acmod_t *acmod, int *out_best_senid);
00361 
00365 void acmod_clear_active(acmod_t *acmod);
00366 
00370 void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm);
00371 
00372 #endif /* __ACMOD_H__ */

Generated on Sat Jan 8 2011 for PocketSphinx by  doxygen 1.7.1