PocketSphinx
0.6
Main Page
Data Structures
Files
File List
Globals
hmm.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
42
#ifndef __HMM_H__
43
#define __HMM_H__
44
45
/* System headers. */
46
#include <stdio.h>
47
48
/* SphinxBase headers. */
49
#include <sphinxbase/fixpoint.h>
50
#include <sphinxbase/listelem_alloc.h>
51
52
/* PocketSphinx headers. */
53
#include "
bin_mdef.h
"
54
55
#ifdef __cplusplus
56
extern
"C"
{
57
#endif
58
#if 0
59
}
/* Fool Emacs into not indenting things. */
60
#endif
61
68
typedef
int16
frame_idx_t
;
69
73
#define MAX_N_FRAMES MAX_INT16
74
75
77
#define SENSCR_SHIFT 10
78
88
#define WORST_SCORE ((int)0xE0000000)
89
94
#define TMAT_WORST_SCORE (-255)
95
99
#define BETTER_THAN >
100
104
#define WORSE_THAN <
105
150
typedef
struct
hmm_context_s
{
151
int32
n_emit_state
;
152
uint8 **
const
*
tp
;
153
int16
const
*
senscore
;
155
uint16 *
const
*
sseq
;
156
int32 *
st_sen_scr
;
157
listelem_alloc_t *
mpx_ssid_alloc
;
158
void
*
udata
;
159
}
hmm_context_t
;
160
164
#define HMM_MAX_NSTATE 5
165
174
typedef
struct
hmm_s
{
175
hmm_context_t
*
ctx
;
176
int32
score
[
HMM_MAX_NSTATE
];
177
int32
history
[
HMM_MAX_NSTATE
];
178
int32
out_score
;
179
int32
out_history
;
180
uint16
ssid
;
181
uint16
senid
[
HMM_MAX_NSTATE
];
182
int32
bestscore
;
183
int16
tmatid
;
184
frame_idx_t
frame
;
185
uint8
mpx
;
186
uint8
n_emit_state
;
187
}
hmm_t
;
188
190
#define hmm_context(h) (h)->ctx
191
#define hmm_is_mpx(h) (h)->mpx
192
193
#define hmm_in_score(h) (h)->score[0]
194
#define hmm_score(h,st) (h)->score[st]
195
#define hmm_out_score(h) (h)->out_score
196
197
#define hmm_in_history(h) (h)->history[0]
198
#define hmm_history(h,st) (h)->history[st]
199
#define hmm_out_history(h) (h)->out_history
200
201
#define hmm_bestscore(h) (h)->bestscore
202
#define hmm_frame(h) (h)->frame
203
#define hmm_mpx_ssid(h,st) (h)->senid[st]
204
#define hmm_nonmpx_ssid(h) (h)->ssid
205
#define hmm_ssid(h,st) (hmm_is_mpx(h) \
206
? hmm_mpx_ssid(h,st) : hmm_nonmpx_ssid(h))
207
#define hmm_mpx_senid(h,st) (hmm_mpx_ssid(h,st) == BAD_SENID \
208
? BAD_SENID : (h)->ctx->sseq[hmm_mpx_ssid(h,st)][st])
209
#define hmm_nonmpx_senid(h,st) ((h)->senid[st])
210
#define hmm_senid(h,st) (hmm_is_mpx(h) \
211
? hmm_mpx_senid(h,st) : hmm_nonmpx_senid(h,st))
212
#define hmm_senscr(h,st) (hmm_senid(h,st) == BAD_SENID \
213
? WORST_SCORE \
214
: -(h)->ctx->senscore[hmm_senid(h,st)])
215
#define hmm_tmatid(h) (h)->tmatid
216
#define hmm_tprob(h,i,j) (-(h)->ctx->tp[hmm_tmatid(h)][i][j])
217
#define hmm_n_emit_state(h) ((h)->n_emit_state)
218
#define hmm_n_state(h) ((h)->n_emit_state + 1)
219
223
hmm_context_t
*hmm_context_init(int32 n_emit_state,
224
uint8 **
const
*tp,
225
int16
const
*senscore,
226
uint16 *
const
*sseq);
227
231
#define hmm_context_set_senscore(ctx, senscr) ((ctx)->senscore = (senscr))
232
240
void
hmm_context_free(
hmm_context_t
*ctx);
241
245
void
hmm_init(
hmm_context_t
*ctx,
hmm_t
*hmm,
int
mpx,
int
ssid,
int
tmatid);
246
250
void
hmm_deinit(
hmm_t
*hmm);
251
257
void
hmm_clear(
hmm_t
*h);
258
262
void
hmm_clear_scores(
hmm_t
*h);
263
267
void
hmm_normalize(
hmm_t
*h, int32 bestscr);
268
272
void
hmm_enter(
hmm_t
*h, int32 score,
273
int32 histid,
int
frame);
274
287
int32 hmm_vit_eval(
hmm_t
*hmm);
288
289
293
int32 hmm_dump_vit_eval(
hmm_t
*hmm,
294
FILE *fp
295
);
296
301
void
hmm_dump(
hmm_t
*h,
302
FILE *fp
303
);
304
305
306
#if 0
307
{
/* Stop indent from complaining */
308
#endif
309
#ifdef __cplusplus
310
}
311
#endif
312
313
#endif
/* __HMM_H__ */
src
libpocketsphinx
hmm.h
Generated by
1.8.3.1