PocketSphinx 5prealpha
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
61extern "C" {
62#endif
63
79#define N_WORD_POSN 4
80#define WPOS_NAME "ibesu"
81#define S3_SILENCE_CIPHONE "SIL"
87typedef struct {
88 char *name;
89 int32 filler;
91} ciphone_t;
92
97typedef struct {
98 int32 ssid;
101 int32 tmat;
102 int16 ci, lc, rc;
105} phone_t;
106
112typedef struct ph_rc_s {
113 int16 rc;
114 int32 pid;
115 struct ph_rc_s *next;
116} ph_rc_t;
117
123typedef struct ph_lc_s {
124 int16 lc;
126 struct ph_lc_s *next;
127} ph_lc_t;
128
129
135typedef struct {
136 int32 n_ciphone;
137 int32 n_phone;
139 int32 n_ci_sen;
140 int32 n_sen;
141 int32 n_tmat;
143 hash_table_t *ciphone_ht;
146 uint16 **sseq;
148 int32 n_sseq;
150 int16 *cd2cisen;
153 int16 *sen2cimap;
155 int16 sil;
162} mdef_t;
163
165#define mdef_is_fillerphone(m,p) ((m)->ciphone[p].filler)
166#define mdef_n_ciphone(m) ((m)->n_ciphone)
167#define mdef_n_phone(m) ((m)->n_phone)
168#define mdef_n_sseq(m) ((m)->n_sseq)
169#define mdef_n_emit_state(m) ((m)->n_emit_state)
170#define mdef_n_sen(m) ((m)->n_sen)
171#define mdef_n_tmat(m) ((m)->n_tmat)
172#define mdef_pid2ssid(m,p) ((m)->phone[p].ssid)
173#define mdef_pid2tmatid(m,p) ((m)->phone[p].tmat)
174#define mdef_silphone(m) ((m)->sil)
175#define mdef_sen2cimap(m) ((m)->sen2cimap)
176#define mdef_sseq2sen(m,ss,pos) ((m)->sseq[ss][pos])
177#define mdef_pid2ci(m,p) ((m)->phone[p].ci)
178#define mdef_cd2cisen(m) ((m)->cd2cisen)
179
185mdef_t *mdef_init (char *mdeffile,
186 int breport
187 );
188
189
194int mdef_ciphone_id(mdef_t *m,
195 char *ciphone
196 );
197
202const char *mdef_ciphone_str(mdef_t *m,
203 int ci
204 );
205
210int mdef_is_ciphone (mdef_t *m,
211 int p
212 );
213
219 int s
220 );
221
226int mdef_phone_id (mdef_t *m,
227 int b,
228 int l,
229 int r,
230 word_posn_t pos
231 );
232
237int mdef_phone_str(mdef_t *m,
238 int pid,
239 char *buf
240 );
241
248 int p1,
249 int p2
250 );
251
253void mdef_report(mdef_t *m
254 );
255
258 );
260 );
261
263void mdef_free (mdef_t *mdef
264 );
265
266
267#ifdef __cplusplus
268}
269#endif
270
271#endif
void mdef_free_recursive_lc(ph_lc_t *lc)
RAH, For freeing memory.
Definition mdef.c:688
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_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
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
void mdef_free(mdef_t *mdef)
Free an mdef_t.
Definition mdef.c:720
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...
word_posn_t
Union of different type of word position.
Definition mdef.h:72
@ WORD_POSN_INTERNAL
Internal phone of word.
Definition mdef.h:73
@ WORD_POSN_SINGLE
Single phone word (i.e.
Definition mdef.h:76
@ WORD_POSN_UNDEFINED
Undefined value, used for initial conditions, etc.
Definition mdef.h:77
@ WORD_POSN_END
Ending phone of word.
Definition mdef.h:75
@ WORD_POSN_BEGIN
Beginning phone of word.
Definition mdef.h:74
mdef_t * mdef_init(char *mdeffile, int breport)
Initialize the phone structure from the given model definition file.
int mdef_is_ciphone(mdef_t *m, int p)
Decide whether the phone is ci phone.
Definition mdef.c:251
int mdef_ciphone_id(mdef_t *m, char *ciphone)
Get the ciphone id given a string name.
Definition mdef.c:176
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
void mdef_free_recursive_rc(ph_rc_t *rc)
Definition mdef.c:703
void mdef_report(mdef_t *m)
Report the model definition's parameters.
Definition mdef.c:665
CI phone information.
Definition mdef.h:87
char * name
The name of the CI phone.
Definition mdef.h:88
int32 filler
Whether a filler phone; if so, can be substituted by silence phone in left or right context position.
Definition mdef.h:89
The main model definition structure.
Definition mdef.h:135
hash_table_t * ciphone_ht
Hash table for mapping ciphone strings to ids.
Definition mdef.h:143
uint16 ** sseq
Unique state (or senone) sequences in this model, shared among all phones/triphones.
Definition mdef.h:146
phone_t * phone
Information for all ciphones and triphones.
Definition mdef.h:145
int32 n_tmat
number transition matrices
Definition mdef.h:141
int32 n_emit_state
number emitting states per phone
Definition mdef.h:138
int16 * sen2cimap
Parent CI-phone for each senone (CI or CD)
Definition mdef.h:153
ph_lc_t *** wpos_ci_lclist
wpos_ci_lclist[wpos][ci] = list of lc for <wpos,ci>.
Definition mdef.h:157
int32 n_ci_sen
number CI senones; these are the first
Definition mdef.h:139
int32 n_sen
number senones (CI+CD)
Definition mdef.h:140
int32 n_phone
number basephones + number triphones actually present
Definition mdef.h:137
ciphone_t * ciphone
CI-phone information for all ciphones.
Definition mdef.h:144
int16 sil
SILENCE_CIPHONE id.
Definition mdef.h:155
int32 n_sseq
No.
Definition mdef.h:148
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:150
int32 n_ciphone
number basephones actually present
Definition mdef.h:136
struct ph_lc_s * next
Next lc entry for same parent <wpos,ci>
Definition mdef.h:126
ph_rc_t * rclist
rc list for above lc instance
Definition mdef.h:125
int16 lc
Specific lc for a parent <wpos,ci>
Definition mdef.h:124
Structures for storing the left context.
int32 pid
Triphone id for above rc instance.
Definition mdef.h:114
int16 rc
Specific rc for a parent <wpos,ci,lc>
Definition mdef.h:113
struct ph_rc_s * next
Next rc entry for same parent <wpos,ci,lc>
Definition mdef.h:115
Structures needed for mapping <ci,lc,rc,wpos> into pid.
Triphone information, including base phones as a subset.
Definition mdef.h:97
int16 rc
Base, left, right context ciphones.
Definition mdef.h:102
word_posn_t wpos
Word position.
Definition mdef.h:103
int32 tmat
Transition matrix id.
Definition mdef.h:101
int32 ssid
State sequence (or senone sequence) ID, considering the n_emit_state senone-ids are a unit.
Definition mdef.h:98