PocketSphinx  0.6
src/libpocketsphinx/mdef.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 
00038 /*
00039  * mdef.h -- HMM model definition: base (CI) phones and triphones
00040  *
00041  * **********************************************
00042  * CMU ARPA Speech Project
00043  *
00044  * Copyright (c) 1999 Carnegie Mellon University.
00045  * ALL RIGHTS RESERVED.
00046  * **********************************************
00047  */
00048 
00049 
00050 #ifndef __MDEF_H__
00051 #define __MDEF_H__
00052 
00053 
00054 /* System headers. */
00055 #include <stdio.h>
00056 
00057 /* SphinxBase headers. */
00058 #include <sphinxbase/hash_table.h>
00059 
00060 #ifdef __cplusplus
00061 extern "C" {
00062 #endif
00063 #if 0
00064 } /* Fool Emacs into not indenting things. */
00065 #endif
00066 
00075 typedef enum {
00076     WORD_POSN_INTERNAL = 0,     
00077     WORD_POSN_BEGIN = 1,        
00078     WORD_POSN_END = 2,          
00079     WORD_POSN_SINGLE = 3,       
00080     WORD_POSN_UNDEFINED = 4     
00081 } word_posn_t;
00082 #define N_WORD_POSN     4       
00083 #define WPOS_NAME       "ibesu" 
00084 #define S3_SILENCE_CIPHONE "SIL" 
00090 typedef struct {
00091     char *name;                 
00092     int32 filler;               
00094 } ciphone_t;
00095 
00100 typedef struct {
00101     int32 ssid;                 
00104     int32 tmat;                 
00105     int16 ci, lc, rc;           
00106     word_posn_t wpos;           
00107     int16 *state;               
00109 } phone_t;
00110 
00116 typedef struct ph_rc_s {
00117     int16 rc;                   
00118     int32 pid;                  
00119     struct ph_rc_s *next;       
00120 } ph_rc_t;
00121 
00127 typedef struct ph_lc_s {
00128     int16 lc;                   
00129     ph_rc_t *rclist;            
00130     struct ph_lc_s *next;       
00131 } ph_lc_t;
00132 
00133 
00139 typedef struct {
00140     int32 n_ciphone;            
00141     int32 n_phone;              
00142     int32 n_emit_state;         
00143     int32 n_ci_sen;             
00144     int32 n_sen;                
00145     int32 n_tmat;               
00147     hash_table_t *ciphone_ht;   
00148     ciphone_t *ciphone;         
00149     phone_t *phone;             
00150     uint16 **sseq;              
00152     int32 n_sseq;               
00154     int16 *cd2cisen;            
00157     int16 *sen2cimap;           
00159     int16 sil;                  
00161     ph_lc_t ***wpos_ci_lclist;  
00167     int16 *st2senmap;    
00172 } mdef_t;
00173 
00175 #define mdef_is_fillerphone(m,p)        ((m)->ciphone[p].filler)
00176 #define mdef_n_ciphone(m)               ((m)->n_ciphone)
00177 #define mdef_n_phone(m)                 ((m)->n_phone)
00178 #define mdef_n_sseq(m)                  ((m)->n_sseq)
00179 #define mdef_n_emit_state(m)            ((m)->n_emit_state)
00180 #define mdef_n_sen(m)                   ((m)->n_sen)
00181 #define mdef_n_tmat(m)                  ((m)->n_tmat)
00182 #define mdef_pid2ssid(m,p)              ((m)->phone[p].ssid)
00183 #define mdef_pid2tmatid(m,p)            ((m)->phone[p].tmat)
00184 #define mdef_silphone(m)                ((m)->sil)
00185 #define mdef_sen2cimap(m)               ((m)->sen2cimap)
00186 #define mdef_sseq2sen(m,ss,pos)         ((m)->sseq[ss][pos])
00187 #define mdef_pid2ci(m,p)                ((m)->phone[p].ci)
00188 #define mdef_cd2cisen(m)                ((m)->cd2cisen)
00189 
00195 mdef_t *mdef_init (char *mdeffile, 
00196                    int breport     
00197     );
00198 
00199 
00204 int mdef_ciphone_id(mdef_t *m,          
00205                     char *ciphone       
00206     );
00207 
00212 const char *mdef_ciphone_str(mdef_t *m, 
00213                              int ci     
00214     );
00215 
00220 int mdef_is_ciphone (mdef_t *m,         
00221                      int p              
00222     );
00223 
00228 int mdef_is_cisenone(mdef_t *m,               
00229                      int s                      
00230     );
00231 
00236 int mdef_phone_id (mdef_t *m,           
00237                    int b,               
00238                    int l,               
00239                    int r,               
00240                    word_posn_t pos      
00241     );
00242 
00247 int mdef_phone_str(mdef_t *m,           
00248                    int pid,             
00249                    char *buf            
00250     );
00251 
00257 int mdef_hmm_cmp (mdef_t *m,    
00258                   int p1,       
00259                   int p2        
00260     );
00261 
00263 void mdef_report(mdef_t *m 
00264     );
00265 
00267 void mdef_free_recursive_lc (ph_lc_t *lc 
00268     );
00269 void mdef_free_recursive_rc (ph_rc_t *rc 
00270     );
00271 
00273 void mdef_free (mdef_t *mdef 
00274     );
00275 
00276 
00277 #if 0
00278 { /* Stop indent from complaining */
00279 #endif
00280 #ifdef __cplusplus
00281 }
00282 #endif
00283 
00284 #endif