PocketSphinx  0.6
mdef.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 
38 /*
39  * mdef.h -- HMM model definition: base (CI) phones and triphones
40  *
41  * **********************************************
42  * CMU ARPA Speech Project
43  *
44  * Copyright (c) 1999 Carnegie Mellon University.
45  * ALL RIGHTS RESERVED.
46  * **********************************************
47  */
48 
49 
50 #ifndef __MDEF_H__
51 #define __MDEF_H__
52 
53 
54 /* System headers. */
55 #include <stdio.h>
56 
57 /* SphinxBase headers. */
58 #include <sphinxbase/hash_table.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 #if 0
64 } /* Fool Emacs into not indenting things. */
65 #endif
66 
75 typedef enum {
81 } word_posn_t;
82 #define N_WORD_POSN 4
83 #define WPOS_NAME "ibesu"
84 #define S3_SILENCE_CIPHONE "SIL"
90 typedef struct {
91  char *name;
92  int32 filler;
94 } ciphone_t;
95 
100 typedef struct {
101  int32 ssid;
104  int32 tmat;
105  int16 ci, lc, rc;
108 } phone_t;
109 
115 typedef struct ph_rc_s {
116  int16 rc;
117  int32 pid;
118  struct ph_rc_s *next;
119 } ph_rc_t;
120 
126 typedef struct ph_lc_s {
127  int16 lc;
129  struct ph_lc_s *next;
130 } ph_lc_t;
131 
132 
138 typedef struct {
139  int32 n_ciphone;
140  int32 n_phone;
141  int32 n_emit_state;
142  int32 n_ci_sen;
143  int32 n_sen;
144  int32 n_tmat;
146  hash_table_t *ciphone_ht;
149  uint16 **sseq;
151  int32 n_sseq;
153  int16 *cd2cisen;
156  int16 *sen2cimap;
158  int16 sil;
165 } mdef_t;
166 
168 #define mdef_is_fillerphone(m,p) ((m)->ciphone[p].filler)
169 #define mdef_n_ciphone(m) ((m)->n_ciphone)
170 #define mdef_n_phone(m) ((m)->n_phone)
171 #define mdef_n_sseq(m) ((m)->n_sseq)
172 #define mdef_n_emit_state(m) ((m)->n_emit_state)
173 #define mdef_n_sen(m) ((m)->n_sen)
174 #define mdef_n_tmat(m) ((m)->n_tmat)
175 #define mdef_pid2ssid(m,p) ((m)->phone[p].ssid)
176 #define mdef_pid2tmatid(m,p) ((m)->phone[p].tmat)
177 #define mdef_silphone(m) ((m)->sil)
178 #define mdef_sen2cimap(m) ((m)->sen2cimap)
179 #define mdef_sseq2sen(m,ss,pos) ((m)->sseq[ss][pos])
180 #define mdef_pid2ci(m,p) ((m)->phone[p].ci)
181 #define mdef_cd2cisen(m) ((m)->cd2cisen)
182 
188 mdef_t *mdef_init (char *mdeffile,
189  int breport
190  );
191 
192 
197 int mdef_ciphone_id(mdef_t *m,
198  char *ciphone
199  );
200 
205 const char *mdef_ciphone_str(mdef_t *m,
206  int ci
207  );
208 
213 int mdef_is_ciphone (mdef_t *m,
214  int p
215  );
216 
221 int mdef_is_cisenone(mdef_t *m,
222  int s
223  );
224 
229 int mdef_phone_id (mdef_t *m,
230  int b,
231  int l,
232  int r,
233  word_posn_t pos
234  );
235 
240 int mdef_phone_str(mdef_t *m,
241  int pid,
242  char *buf
243  );
244 
250 int mdef_hmm_cmp (mdef_t *m,
251  int p1,
252  int p2
253  );
254 
256 void mdef_report(mdef_t *m
257  );
258 
261  );
263  );
264 
266 void mdef_free (mdef_t *mdef
267  );
268 
269 
270 #if 0
271 { /* Stop indent from complaining */
272 #endif
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif
int32 n_sseq
No.
Definition: mdef.h:151
The main model definition structure.
Definition: mdef.h:138
int32 n_ciphone
number basephones actually present
Definition: mdef.h:139
struct ph_lc_s * next
Next lc entry for same parent <wpos,ci>
Definition: mdef.h:129
word_posn_t wpos
Word position.
Definition: mdef.h:106
Definition: mdef.h:115
Single phone word (i.e.
Definition: mdef.h:79
int32 filler
Whether a filler phone; if so, can be substituted by silence phone in left or right context position...
Definition: mdef.h:92
Ending phone of word.
Definition: mdef.h:78
int32 n_phone
number basephones + number triphones actually present
Definition: mdef.h:140
int16 rc
Base, left, right context ciphones.
Definition: mdef.h:105
int mdef_is_ciphone(mdef_t *m, int p)
Decide whether the phone is ci phone.
Definition: mdef.c:251
char * name
The name of the CI phone.
Definition: mdef.h:91
int16 * cd2cisen
Parent CI-senone id for each senone; the first n_ci_sen are identity mappings; the CD-senones are con...
Definition: mdef.h:153
void mdef_free(mdef_t *mdef)
Free an mdef_t.
Definition: mdef.c:719
int32 n_ci_sen
number CI senones; these are the first
Definition: mdef.h:142
int32 ssid
State sequence (or senone sequence) ID, considering the n_emit_state senone-ids are a unit...
Definition: mdef.h:101
void mdef_report(mdef_t *m)
Report the model definition&#39;s parameters.
Definition: mdef.c:664
Structures for storing the left context.
int16 lc
Specific lc for a parent <wpos,ci>
Definition: mdef.h:127
int mdef_hmm_cmp(mdef_t *m, int p1, int p2)
Compare the underlying HMMs for two given phones (i.e., compare the two transition matrix IDs and the...
int mdef_phone_str(mdef_t *m, int pid, char *buf)
Create a phone string for the given phone (base or triphone) id in the given buf. ...
Definition: mdef.c:196
int16 rc
Specific rc for a parent <wpos,ci,lc>
Definition: mdef.h:116
uint16 ** sseq
Unique state (or senone) sequences in this model, shared among all phones/triphones.
Definition: mdef.h:149
int32 pid
Triphone id for above rc instance.
Definition: mdef.h:117
Undefined value, used for initial conditions, etc.
Definition: mdef.h:80
mdef_t * mdef_init(char *mdeffile, int breport)
Initialize the phone structure from the given model definition file.
Triphone information, including base phones as a subset.
Definition: mdef.h:100
ph_rc_t * rclist
rc list for above lc instance
Definition: mdef.h:128
const char * mdef_ciphone_str(mdef_t *m, int ci)
Get the phone string given the ci phone id.
Definition: mdef.c:186
int mdef_phone_id(mdef_t *m, int b, int l, int r, word_posn_t pos)
Decide the phone id given the left, right and base phones.
Definition: mdef.c:219
ciphone_t * ciphone
CI-phone information for all ciphones.
Definition: mdef.h:147
hash_table_t * ciphone_ht
Hash table for mapping ciphone strings to ids.
Definition: mdef.h:146
CI phone information.
Definition: mdef.h:90
void mdef_free_recursive_lc(ph_lc_t *lc)
RAH, For freeing memory.
Definition: mdef.c:687
int32 n_sen
number senones (CI+CD)
Definition: mdef.h:143
Beginning phone of word.
Definition: mdef.h:77
int32 tmat
Transition matrix id.
Definition: mdef.h:104
int mdef_ciphone_id(mdef_t *m, char *ciphone)
Get the ciphone id given a string name.
Definition: mdef.c:176
Definition: mdef.h:126
int16 * sen2cimap
Parent CI-phone for each senone (CI or CD)
Definition: mdef.h:156
struct ph_rc_s * next
Next rc entry for same parent <wpos,ci,lc>
Definition: mdef.h:118
Internal phone of word.
Definition: mdef.h:76
int32 n_tmat
number transition matrices
Definition: mdef.h:144
int mdef_is_cisenone(mdef_t *m, int s)
Decide whether the senone is a senone for a ci phone, or a ci senone.
Definition: mdef.c:260
word_posn_t
Union of different type of word position.
Definition: mdef.h:75
int32 n_emit_state
number emitting states per phone
Definition: mdef.h:141
int16 sil
SILENCE_CIPHONE id.
Definition: mdef.h:158
ph_lc_t *** wpos_ci_lclist
wpos_ci_lclist[wpos][ci] = list of lc for <wpos,ci>.
Definition: mdef.h:160
Structures needed for mapping <ci,lc,rc,wpos> into pid.
void mdef_free_recursive_rc(ph_rc_t *rc)
Definition: mdef.c:702
phone_t * phone
Information for all ciphones and triphones.
Definition: mdef.h:148