acmod.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 2008 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
#ifndef __ACMOD_H__
#define __ACMOD_H__
/* System headers. */
#include <stdio.h>
/* SphinxBase headers. */
#include <sphinxbase/cmd_ln.h>
#include <sphinxbase/logmath.h>
#include <sphinxbase/fe.h>
#include <sphinxbase/feat.h>
#include <sphinxbase/bitvec.h>
#include <sphinxbase/err.h>
#include <sphinxbase/prim_type.h>
/* Local headers. */
#include "ps_mllr.h"
#include "bin_mdef.h"
#include "tmat.h"
#include "hmm.h"
typedef enum acmod_state_e {
ACMOD_IDLE,
ACMOD_STARTED,
ACMOD_PROCESSING,
ACMOD_ENDED
} acmod_state_t;
#define SENSCR_DUMMY 0x7fff
struct ps_mllr_s {
int refcnt;
int n_class;
int n_feat;
int *veclen;
float32 ****A;
float32 ***b;
float32 ***h;
int32 *cb2mllr;
};
typedef struct ps_mgau_s ps_mgau_t;
typedef struct ps_mgaufuncs_s {
char const *name;
int (*frame_eval)(ps_mgau_t *mgau,
int16 *senscr,
uint8 *senone_active,
int32 n_senone_active,
mfcc_t ** feat,
int32 frame,
int32 compallsen);
int (*transform)(ps_mgau_t *mgau,
ps_mllr_t *mllr);
void (*free)(ps_mgau_t *mgau);
} ps_mgaufuncs_t;
struct ps_mgau_s {
ps_mgaufuncs_t *vt;
int frame_idx;
};
#define ps_mgau_base(mg) ((ps_mgau_t *)(mg))
#define ps_mgau_frame_eval(mg,senscr,senone_active,n_senone_active,feat,frame,compallsen) \
(*ps_mgau_base(mg)->vt->frame_eval) \
(mg, senscr, senone_active, n_senone_active, feat, frame, compallsen)
#define ps_mgau_transform(mg, mllr) \
(*ps_mgau_base(mg)->vt->transform)(mg, mllr)
#define ps_mgau_free(mg) \
(*ps_mgau_base(mg)->vt->free)(mg)
struct acmod_s {
/* Global objects, not retained. */
cmd_ln_t *config;
logmath_t *lmath;
glist_t strings;
/* Feature computation: */
fe_t *fe;
feat_t *fcb;
/* Model parameters: */
bin_mdef_t *mdef;
tmat_t *tmat;
ps_mgau_t *mgau;
ps_mllr_t *mllr;
/* Senone scoring: */
int16 *senone_scores;
bitvec_t *senone_active_vec;
uint8 *senone_active;
int senscr_frame;
int n_senone_active;
int log_zero;
/* Utterance processing: */
mfcc_t **mfc_buf;
mfcc_t ***feat_buf;
FILE *rawfh;
FILE *mfcfh;
FILE *senfh;
FILE *insenfh;
long *framepos;
/* Rawdata collected during decoding */
int16 *rawdata;
int32 rawdata_size;
int32 rawdata_pos;
/* A whole bunch of flags and counters: */
uint8 state;
uint8 compallsen;
uint8 grow_feat;
uint8 insen_swap;
frame_idx_t utt_start_frame;
frame_idx_t output_frame;
frame_idx_t n_mfc_alloc;
frame_idx_t n_mfc_frame;
frame_idx_t mfc_outidx;
frame_idx_t n_feat_alloc;
frame_idx_t n_feat_frame;
frame_idx_t feat_outidx;
};
typedef struct acmod_s acmod_t;
acmod_t *acmod_init(cmd_ln_t *config, logmath_t *lmath, fe_t *fe, feat_t *fcb);
ps_mllr_t *acmod_update_mllr(acmod_t *acmod, ps_mllr_t *mllr);
int acmod_set_senfh(acmod_t *acmod, FILE *senfh);
int acmod_set_mfcfh(acmod_t *acmod, FILE *logfh);
int acmod_set_rawfh(acmod_t *acmod, FILE *logfh);
void acmod_free(acmod_t *acmod);
int acmod_start_utt(acmod_t *acmod);
int acmod_end_utt(acmod_t *acmod);
int acmod_rewind(acmod_t *acmod);
int acmod_advance(acmod_t *acmod);
int acmod_set_grow(acmod_t *acmod, int grow_feat);
int acmod_process_raw(acmod_t *acmod,
int16 const **inout_raw,
size_t *inout_n_samps,
int full_utt);
int acmod_process_cep(acmod_t *acmod,
mfcc_t ***inout_cep,
int *inout_n_frames,
int full_utt);
int acmod_process_feat(acmod_t *acmod,
mfcc_t **feat);
int acmod_set_insenfh(acmod_t *acmod, FILE *insenfh);
int acmod_read_scores(acmod_t *acmod);
mfcc_t **acmod_get_frame(acmod_t *acmod, int *inout_frame_idx);
int16 const *acmod_score(acmod_t *acmod,
int *inout_frame_idx);
int acmod_write_senfh_header(acmod_t *acmod, FILE *logfh);
int acmod_write_scores(acmod_t *acmod, int n_active, uint8 const *active,
int16 const *senscr, FILE *senfh);
int acmod_best_score(acmod_t *acmod, int *out_best_senid);
void acmod_clear_active(acmod_t *acmod);
void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm);
#define acmod_activate_sen(acmod, sen) bitvec_set((acmod)->senone_active_vec, sen)
int32 acmod_flags2list(acmod_t *acmod);
int32 acmod_stream_offset(acmod_t *acmod);
void acmod_start_stream(acmod_t *acmod);
void acmod_set_rawdata_size(acmod_t *acmod, int32 size);
void acmod_get_rawdata(acmod_t *acmod, int16 **buffer, int32 *size);
#endif /* __ACMOD_H__ */
acmod_get_rawdata
void acmod_get_rawdata(acmod_t *acmod, int16 **buffer, int32 *size)
Retrieves the raw data collected during utterance decoding.
Definition acmod.c:1332
acmod_set_grow
int acmod_set_grow(acmod_t *acmod, int grow_feat)
Set memory allocation policy for utterance processing.
Definition acmod.c:410
acmod_free
void acmod_free(acmod_t *acmod)
Finalize an acoustic model.
Definition acmod.c:299
acmod_process_raw
int acmod_process_raw(acmod_t *acmod, int16 const **inout_raw, size_t *inout_n_samps, int full_utt)
TODO: Set queue length for utterance processing.
Definition acmod.c:607
acmod_end_utt
int acmod_end_utt(acmod_t *acmod)
Mark the end of an utterance.
Definition acmod.c:441
acmod_activate_hmm
void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm)
Activate senones associated with an HMM.
Definition acmod.c:1213
acmod_best_score
int acmod_best_score(acmod_t *acmod, int *out_best_senid)
Get best score and senone index for current frame.
Definition acmod.c:1168
acmod_advance
int acmod_advance(acmod_t *acmod)
Advance the frame index.
Definition acmod.c:899
acmod_get_frame
mfcc_t ** acmod_get_frame(acmod_t *acmod, int *inout_frame_idx)
Get a frame of dynamic feature data.
Definition acmod.c:1088
acmod_set_mfcfh
int acmod_set_mfcfh(acmod_t *acmod, FILE *logfh)
Start logging MFCCs to a filehandle.
Definition acmod.c:375
acmod_state_t
enum acmod_state_e acmod_state_t
States in utterance processing.
acmod_read_scores
int acmod_read_scores(acmod_t *acmod)
Read one frame of scores from senone score dump file.
Definition acmod.c:1012
acmod_score
int16 const * acmod_score(acmod_t *acmod, int *inout_frame_idx)
Score one frame of data.
Definition acmod.c:1106
acmod_write_scores
int acmod_write_scores(acmod_t *acmod, int n_active, uint8 const *active, int16 const *senscr, FILE *senfh)
Write a frame of senone scores to a dump file.
Definition acmod.c:911
acmod_set_rawfh
int acmod_set_rawfh(acmod_t *acmod, FILE *logfh)
Start logging raw audio to a filehandle.
Definition acmod.c:387
acmod_state_e
acmod_state_e
States in utterance processing.
Definition acmod.h:67
ACMOD_IDLE
@ ACMOD_IDLE
Not in an utterance.
Definition acmod.h:68
ACMOD_PROCESSING
@ ACMOD_PROCESSING
Utterance in progress.
Definition acmod.h:70
ACMOD_ENDED
@ ACMOD_ENDED
Utterance ended, still buffering.
Definition acmod.h:71
ACMOD_STARTED
@ ACMOD_STARTED
Utterance started, no data yet.
Definition acmod.h:69
acmod_rewind
int acmod_rewind(acmod_t *acmod)
Rewind the current utterance, allowing it to be rescored.
Definition acmod.c:877
acmod_stream_offset
int32 acmod_stream_offset(acmod_t *acmod)
Get the offset of the utterance start of the current stream, helpful for stream-wide timing.
Definition acmod.c:1308
acmod_set_rawdata_size
void acmod_set_rawdata_size(acmod_t *acmod, int32 size)
Sets the limit of the raw audio data to store.
Definition acmod.c:1321
acmod_set_senfh
int acmod_set_senfh(acmod_t *acmod, FILE *senfh)
Start logging senone scores to a filehandle.
Definition acmod.c:364
acmod_process_cep
int acmod_process_cep(acmod_t *acmod, mfcc_t ***inout_cep, int *inout_n_frames, int full_utt)
Feed acoustic feature data into the acoustic model for scoring.
Definition acmod.c:699
acmod_start_utt
int acmod_start_utt(acmod_t *acmod)
Mark the start of an utterance.
Definition acmod.c:423
acmod_process_feat
int acmod_process_feat(acmod_t *acmod, mfcc_t **feat)
Feed dynamic feature data into the acoustic model for scoring.
Definition acmod.c:797
acmod_write_senfh_header
int acmod_write_senfh_header(acmod_t *acmod, FILE *logfh)
Write senone dump file header.
Definition acmod.c:350
acmod_update_mllr
ps_mllr_t * acmod_update_mllr(acmod_t *acmod, ps_mllr_t *mllr)
Adapt acoustic model using a linear transform.
Definition acmod.c:339
acmod_flags2list
int32 acmod_flags2list(acmod_t *acmod)
Build active list from.
Definition acmod.c:1254
acmod_set_insenfh
int acmod_set_insenfh(acmod_t *acmod, FILE *insenfh)
Set up a senone score dump file for input.
Definition acmod.c:864
acmod_start_stream
void acmod_start_stream(acmod_t *acmod)
Reset the current stream.
Definition acmod.c:1314
acmod_init
acmod_t * acmod_init(cmd_ln_t *config, logmath_t *lmath, fe_t *fe, feat_t *fcb)
Initialize an acoustic model.
Definition acmod.c:228
acmod_clear_active
void acmod_clear_active(acmod_t *acmod)
Clear set of active senones.
Definition acmod.c:1197
bin_mdef.h
Binary format model definition files, with support for heterogeneous topologies and variable-size N-p...
hmm.h
Implementation of HMM base structure.
frame_idx_t
int32 frame_idx_t
Type for frame index values.
Definition hmm.h:64
ps_mllr.h
Model-space linear transforms for speaker adaptation.
acmod_s
Acoustic model structure.
Definition acmod.h:148
acmod_s::mgau
ps_mgau_t * mgau
Model parameters.
Definition acmod.h:161
acmod_s::state
uint8 state
State of utterance processing.
Definition acmod.h:187
acmod_s::n_mfc_frame
frame_idx_t n_mfc_frame
Number of frames active in mfc_buf.
Definition acmod.h:196
acmod_s::mdef
bin_mdef_t * mdef
Model definition.
Definition acmod.h:159
acmod_s::config
cmd_ln_t * config
Configuration.
Definition acmod.h:150
acmod_s::fcb
feat_t * fcb
Dynamic feature computation.
Definition acmod.h:156
acmod_s::senone_active_vec
bitvec_t * senone_active_vec
Active GMMs in current frame.
Definition acmod.h:166
acmod_s::mllr
ps_mllr_t * mllr
Speaker transformation.
Definition acmod.h:162
acmod_s::n_senone_active
int n_senone_active
Number of active GMMs.
Definition acmod.h:169
acmod_s::fe
fe_t * fe
Acoustic feature computation.
Definition acmod.h:155
acmod_s::senone_active
uint8 * senone_active
Array of deltas to active GMMs.
Definition acmod.h:167
acmod_s::mfc_buf
mfcc_t ** mfc_buf
Temporary buffer of acoustic features.
Definition acmod.h:173
acmod_s::mfcfh
FILE * mfcfh
File for writing acoustic feature data.
Definition acmod.h:176
acmod_s::n_feat_alloc
frame_idx_t n_feat_alloc
Number of frames allocated in feat_buf.
Definition acmod.h:198
acmod_s::n_feat_frame
frame_idx_t n_feat_frame
Number of frames active in feat_buf.
Definition acmod.h:199
acmod_s::log_zero
int log_zero
Zero log-probability value.
Definition acmod.h:170
acmod_s::lmath
logmath_t * lmath
Log-math computation.
Definition acmod.h:151
acmod_s::strings
glist_t strings
Temporary acoustic model filenames.
Definition acmod.h:152
acmod_s::senone_scores
int16 * senone_scores
GMM scores for current frame.
Definition acmod.h:165
acmod_s::tmat
tmat_t * tmat
Transition matrices.
Definition acmod.h:160
acmod_s::senscr_frame
int senscr_frame
Frame index for senone_scores.
Definition acmod.h:168
acmod_s::senfh
FILE * senfh
File for writing senone score data.
Definition acmod.h:177
acmod_s::framepos
long * framepos
File positions of recent frames in senone file.
Definition acmod.h:179
acmod_s::compallsen
uint8 compallsen
Compute all senones?
Definition acmod.h:188
acmod_s::grow_feat
uint8 grow_feat
Whether to grow feat_buf.
Definition acmod.h:189
acmod_s::insenfh
FILE * insenfh
Input senone score file.
Definition acmod.h:178
acmod_s::feat_outidx
frame_idx_t feat_outidx
Start of active frames in feat_buf.
Definition acmod.h:200
acmod_s::insen_swap
uint8 insen_swap
Whether to swap input senone score.
Definition acmod.h:190
acmod_s::rawfh
FILE * rawfh
File for writing raw audio data.
Definition acmod.h:175
acmod_s::output_frame
frame_idx_t output_frame
Index of next frame of dynamic features.
Definition acmod.h:194
acmod_s::utt_start_frame
frame_idx_t utt_start_frame
Index of the utterance start in the stream, all timings are relative to that.
Definition acmod.h:192
acmod_s::n_mfc_alloc
frame_idx_t n_mfc_alloc
Number of frames allocated in mfc_buf.
Definition acmod.h:195
acmod_s::feat_buf
mfcc_t *** feat_buf
Temporary buffer of dynamic features.
Definition acmod.h:174
acmod_s::mfc_outidx
frame_idx_t mfc_outidx
Start of active frames in mfc_buf.
Definition acmod.h:197
bin_mdef_s
Definition bin_mdef.h:117
hmm_t
An individual HMM among the HMM search space.
ps_mgau_s
Definition acmod.h:113
ps_mgau_s::frame_idx
int frame_idx
frame counter.
Definition acmod.h:115
ps_mgau_s::vt
ps_mgaufuncs_t * vt
vtable of mgau functions.
Definition acmod.h:114
ps_mgaufuncs_s
Definition acmod.h:98
ps_mllr_s
Feature space linear transform structure.
Definition acmod.h:82
ps_mllr_s::veclen
int * veclen
Length of input vectors for each stream.
Definition acmod.h:86
ps_mllr_s::n_class
int n_class
Number of MLLR classes.
Definition acmod.h:84
ps_mllr_s::A
float32 **** A
Rotation part of mean transformations.
Definition acmod.h:87
ps_mllr_s::b
float32 *** b
Bias part of mean transformations.
Definition acmod.h:88
ps_mllr_s::cb2mllr
int32 * cb2mllr
Mapping from codebooks to transformations.
Definition acmod.h:90
ps_mllr_s::refcnt
int refcnt
Reference count.
Definition acmod.h:83
ps_mllr_s::n_feat
int n_feat
Number of feature streams.
Definition acmod.h:85
ps_mllr_s::h
float32 *** h
Diagonal transformation of variances.
Definition acmod.h:89
tmat_t
Transition matrix data structure.
Definition tmat.h:55
tmat.h
Transition matrix data structure.