PocketSphinx  0.6
acmod.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2008 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 
43 #ifndef __ACMOD_H__
44 #define __ACMOD_H__
45 
46 /* System headers. */
47 #include <stdio.h>
48 
49 /* SphinxBase headers. */
50 #include <sphinxbase/cmd_ln.h>
51 #include <sphinxbase/logmath.h>
52 #include <sphinxbase/fe.h>
53 #include <sphinxbase/feat.h>
54 #include <sphinxbase/bitvec.h>
55 #include <sphinxbase/err.h>
56 
57 /* Local headers. */
58 #include "ps_mllr.h"
59 #include "bin_mdef.h"
60 #include "tmat.h"
61 #include "hmm.h"
62 
66 typedef enum acmod_state_e {
72 
76 #define SENSCR_DUMMY 0x7fff
77 
81 struct ps_mllr_s {
82  int refcnt;
83  int n_class;
84  int n_feat;
85  int *veclen;
86  float32 ****A;
87  float32 ***b;
88  float32 ***h;
89  int32 *cb2mllr;
90 };
91 
95 typedef struct ps_mgau_s ps_mgau_t;
96 
97 typedef struct ps_mgaufuncs_s {
98  char const *name;
99 
100  int (*frame_eval)(ps_mgau_t *mgau,
101  int16 *senscr,
102  uint8 *senone_active,
103  int32 n_senone_active,
104  mfcc_t ** feat,
105  int32 frame,
106  int32 compallsen);
107  int (*transform)(ps_mgau_t *mgau,
108  ps_mllr_t *mllr);
109  void (*free)(ps_mgau_t *mgau);
110 } ps_mgaufuncs_t;
111 
112 struct ps_mgau_s {
114  int frame_idx;
115 };
116 
117 #define ps_mgau_base(mg) ((ps_mgau_t *)(mg))
118 #define ps_mgau_frame_eval(mg,senscr,senone_active,n_senone_active,feat,frame,compallsen) \
119  (*ps_mgau_base(mg)->vt->frame_eval) \
120  (mg, senscr, senone_active, n_senone_active, feat, frame, compallsen)
121 #define ps_mgau_transform(mg, mllr) \
122  (*ps_mgau_base(mg)->vt->transform)(mg, mllr)
123 #define ps_mgau_free(mg) \
124  (*ps_mgau_base(mg)->vt->free)(mg)
125 
147 struct acmod_s {
148  /* Global objects, not retained. */
149  cmd_ln_t *config;
150  logmath_t *lmath;
151  glist_t strings;
153  /* Feature computation: */
154  fe_t *fe;
155  feat_t *fcb;
157  /* Model parameters: */
163  /* Senone scoring: */
164  int16 *senone_scores;
165  bitvec_t *senone_active_vec;
166  uint8 *senone_active;
169  int log_zero;
171  /* Utterance processing: */
172  mfcc_t **mfc_buf;
173  mfcc_t ***feat_buf;
174  FILE *rawfh;
175  FILE *mfcfh;
176  FILE *senfh;
177  FILE *insenfh;
178  long *framepos;
180  /* A whole bunch of flags and counters: */
181  uint8 state;
182  uint8 compallsen;
183  uint8 grow_feat;
184  uint8 insen_swap;
185  int16 output_frame;
186  int16 n_mfc_alloc;
187  int16 n_mfc_frame;
188  int16 mfc_outidx;
189  int16 n_feat_alloc;
190  int16 n_feat_frame;
191  int16 feat_outidx;
192 };
193 typedef struct acmod_s acmod_t;
194 
211 acmod_t *acmod_init(cmd_ln_t *config, logmath_t *lmath, fe_t *fe, feat_t *fcb);
212 
225 
233 int acmod_set_senfh(acmod_t *acmod, FILE *senfh);
234 
242 int acmod_set_mfcfh(acmod_t *acmod, FILE *logfh);
243 
251 int acmod_set_rawfh(acmod_t *acmod, FILE *logfh);
252 
256 void acmod_free(acmod_t *acmod);
257 
261 int acmod_start_utt(acmod_t *acmod);
262 
266 int acmod_end_utt(acmod_t *acmod);
267 
280 int acmod_rewind(acmod_t *acmod);
281 
291 int acmod_advance(acmod_t *acmod);
292 
301 int acmod_set_grow(acmod_t *acmod, int grow_feat);
302 
321 int acmod_process_raw(acmod_t *acmod,
322  int16 const **inout_raw,
323  size_t *inout_n_samps,
324  int full_utt);
325 
337 int acmod_process_cep(acmod_t *acmod,
338  mfcc_t ***inout_cep,
339  int *inout_n_frames,
340  int full_utt);
341 
355 int acmod_process_feat(acmod_t *acmod,
356  mfcc_t **feat);
357 
364 int acmod_set_insenfh(acmod_t *acmod, FILE *insenfh);
365 
371 int acmod_read_scores(acmod_t *acmod);
372 
382 mfcc_t **acmod_get_frame(acmod_t *acmod, int *inout_frame_idx);
383 
397 int16 const *acmod_score(acmod_t *acmod,
398  int *inout_frame_idx);
399 
403 int acmod_write_senfh_header(acmod_t *acmod, FILE *logfh);
404 
408 int acmod_write_scores(acmod_t *acmod, int n_active, uint8 const *active,
409  int16 const *senscr, FILE *senfh);
410 
411 
415 int acmod_best_score(acmod_t *acmod, int *out_best_senid);
416 
420 void acmod_clear_active(acmod_t *acmod);
421 
425 void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm);
426 
430 #define acmod_activate_sen(acmod, sen) bitvec_set((acmod)->senone_active_vec, sen)
431 
435 int32 acmod_flags2list(acmod_t *acmod);
436 
437 #endif /* __ACMOD_H__ */