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

src/libpocketsphinx/bin_mdef.h

Go to the documentation of this file.
00001 /* -*- c-file-style: "linux" -*- */
00002 /* ====================================================================
00003  * Copyright (c) 2005 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  */
00045 #ifndef __BIN_MDEF_H__
00046 #define __BIN_MDEF_H__
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #if 0
00051 }; /* Fool Emacs */
00052 #endif
00053 #endif /* __cplusplus */
00054 
00055 /* SphinxBase headers. */
00056 #include <mdef.h>
00057 #include <mmio.h>
00058 #include <cmd_ln.h>
00059 
00060 #define BIN_MDEF_FORMAT_VERSION 1
00061 /* Little-endian machines will write "BMDF" to disk, big-endian ones "FDMB". */
00062 #define BIN_MDEF_NATIVE_ENDIAN 0x46444d42 /* 'BMDF' in little-endian order */
00063 #define BIN_MDEF_OTHER_ENDIAN 0x424d4446  /* 'BMDF' in big-endian order */
00064 #ifdef __GNUC__
00065 #define ATTRIBUTE_PACKED __attribute__((packed))
00066 #else
00067 #define ATTRIBUTE_PACKED
00068 #endif
00069 
00073 typedef struct mdef_entry_s mdef_entry_t;
00074 struct mdef_entry_s {
00075         int32 ssid; 
00076         int32 tmat; 
00077         /* FIXME: is any of this actually necessary? */
00078         union {
00080                 struct {
00081                         uint8 filler;
00082                         uint8 reserved[3];
00083                 } ci;
00085                 struct {
00086                         uint8 wpos;
00087                         uint8 ctx[3]; 
00088                 } cd;
00089         } info;
00090 } ATTRIBUTE_PACKED;
00091 
00095 typedef struct cd_tree_s cd_tree_t;
00096 struct cd_tree_s {
00097         int16 ctx; 
00098         int16 n_down; 
00099         union {
00100                 int32 pid; 
00101                 int32 down; 
00102         } c;
00103 };
00104 
00108 typedef struct bin_mdef_s bin_mdef_t;
00109 struct bin_mdef_s {
00110         int32 n_ciphone;    
00111         int32 n_phone;      
00112         int32 n_emit_state; 
00113         int32 n_ci_sen;     
00114         int32 n_sen;        
00115         int32 n_tmat;       
00116         int32 n_sseq;       
00117         int32 n_ctx;        
00118         int32 n_cd_tree;    
00119         int16 sil;          
00121         mmio_file_t *filemap;
00122         char **ciname;       
00123         cd_tree_t *cd_tree;  
00124         mdef_entry_t *phone; 
00125         int16 **sseq;        
00126         uint8 *sseq_len;     
00128         /* These two are not stored on disk, but are generated at load time. */
00129         int16 *cd2cisen;        
00130         int16 *sen2cimap;       
00133         enum { BIN_MDEF_FROM_TEXT, BIN_MDEF_IN_MEMORY, BIN_MDEF_ON_DISK } alloc_mode;
00134 };
00135 
00136 #define bin_mdef_is_fillerphone(m,p)    (((p) < (m)->n_ciphone) \
00137                                          ? (m)->phone[p].info.ci.filler \
00138                                          : (m)->phone[(m)->phone[p].info.cd.ctx[0]].info.ci.filler)
00139 #define bin_mdef_is_ciphone(m,p)        ((p) < (m)->n_ciphone)
00140 #define bin_mdef_n_ciphone(m)           ((m)->n_ciphone)
00141 #define bin_mdef_n_phone(m)             ((m)->n_phone)
00142 #define bin_mdef_n_sseq(m)              ((m)->n_sseq)
00143 #define bin_mdef_n_emit_state(m)        ((m)->n_emit_state)
00144 #define bin_mdef_n_emit_state_phone(m,p) ((m)->n_emit_state ? (m)->n_emit_state \
00145                                           : (m)->sseq_len[(m)->phone[p].ssid])
00146 #define bin_mdef_n_sen(m)               ((m)->n_sen)
00147 #define bin_mdef_n_tmat(m)              ((m)->n_tmat)
00148 #define bin_mdef_pid2ssid(m,p)          ((m)->phone[p].ssid)
00149 #define bin_mdef_pid2tmatid(m,p)        ((m)->phone[p].tmat)
00150 #define bin_mdef_silphone(m)            ((m)->sil)
00151 #define bin_mdef_sseq2sen(m,ss,pos)     ((m)->sseq[ss][pos])
00152 #define bin_mdef_pid2ci(m,p)            (((p) < (m)->n_ciphone) ? (p) \
00153                                          : (m)->phone[p].info.cd.ctx[0])
00154 
00156 bin_mdef_t *bin_mdef_read(cmd_ln_t *config, const char *filename);
00158 bin_mdef_t *bin_mdef_read_text(cmd_ln_t *config, const char *filename);
00160 int bin_mdef_write(bin_mdef_t *m, const char *filename);
00162 int bin_mdef_write_text(bin_mdef_t *m, const char *filename);
00163 
00165 void bin_mdef_free(bin_mdef_t *m);
00166 
00171 int bin_mdef_ciphone_id (bin_mdef_t *m, /* In: Model structure being queried */
00172                          const char *ciphone); /* In: ciphone for which id wanted */
00173 
00178 int bin_mdef_ciphone_id_nocase(bin_mdef_t *m,   /* In: Model structure being queried */
00179                                const char *ciphone); /* In: ciphone for which id wanted */
00180 
00181 /* Return value: READ-ONLY ciphone string name for the given ciphone id */
00182 const char *bin_mdef_ciphone_str (bin_mdef_t *m,        /* In: Model structure being queried */
00183                                   int32 ci);    /* In: ciphone id for which name wanted */
00184 
00185 /* Return value: phone id for the given constituents if found, else -1 */
00186 int bin_mdef_phone_id (bin_mdef_t *m,   /* In: Model structure being queried */
00187                        int32 b,         /* In: base ciphone id */
00188                        int32 l,         /* In: left context ciphone id */
00189                        int32 r,         /* In: right context ciphone id */
00190                        int32 pos);      /* In: Word position */
00191 
00197 int bin_mdef_phone_str (bin_mdef_t *m,  /* In: Model structure being queried */
00198                         int pid,        /* In: phone id being queried */
00199                         char *buf);     /* Out: On return, buf has the string */
00200 
00201 #ifdef __cplusplus
00202 }; /* extern "C" */
00203 #endif /* __cplusplus */
00204 
00205 #endif /* __BIN_MDEF_H__ */

Generated on Thu Jan 27 2011 for PocketSphinx by  doxygen 1.7.1