feat.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 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.
*
* ====================================================================
*
*/
/*
* feat.h -- Cepstral features computation.
*/
#ifndef _S3_FEAT_H_
#define _S3_FEAT_H_
#include <stdio.h>
/* Win32/WinCE DLL gunk */
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>
#include <sphinxbase/fe.h>
#include <sphinxbase/cmn.h>
#include <sphinxbase/agc.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
#define LIVEBUFBLOCKSIZE 256
#define S3_MAX_FRAMES 15000 /* RAH, I believe this is still too large, but better than before */
#define cepstral_to_feature_command_line_macro() \
{ "-feat", \
ARG_STRING, \
"1s_c_d_dd", \
"Feature stream type, depends on the acoustic model" }, \
{ "-ceplen", \
ARG_INT32, \
"13", \
"Number of components in the input feature vector" }, \
{ "-cmn", \
ARG_STRING, \
"live", \
"Cepstral mean normalization scheme ('live', 'batch', or 'none')" }, \
{ "-cmninit", \
ARG_STRING, \
"40,3,-1", \
"Initial values (comma-separated) for cepstral mean when 'live' is used" }, \
{ "-varnorm", \
ARG_BOOLEAN, \
"no", \
"Variance normalize each utterance (only if CMN == current)" }, \
{ "-agc", \
ARG_STRING, \
"none", \
"Automatic gain control for c0 ('max', 'emax', 'noise', or 'none')" }, \
{ "-agcthresh", \
ARG_FLOAT32, \
"2.0", \
"Initial threshold for automatic gain control" }, \
{ "-lda", \
ARG_STRING, \
NULL, \
"File containing transformation matrix to be applied to features (single-stream features only)" }, \
{ "-ldadim", \
ARG_INT32, \
"0", \
"Dimensionality of output of feature transformation (0 to use entire matrix)" }, \
{"-svspec", \
ARG_STRING, \
NULL, \
"Subvector specification (e.g., 24,0-11/25,12-23/26-38 or 0-12/13-25/26-38)"}
*/
typedef struct feat_s {
int refcount;
char *name;
int32 cepsize;
int32 n_stream;
uint32 *stream_len;
int32 window_size;
int32 n_sv;
uint32 *sv_len;
int32 **subvecs;
mfcc_t *sv_buf;
int32 sv_dim;
cmn_type_t cmn;
int32 varnorm;
agc_type_t agc;
void (*compute_feat)(struct feat_s *fcb, mfcc_t **input, mfcc_t **feat);
cmn_t *cmn_struct;
agc_t *agc_struct;
mfcc_t **cepbuf;
mfcc_t **tmpcepbuf;
int32 bufpos;
int32 curpos;
mfcc_t ***lda;
uint32 n_lda;
uint32 out_dim;
} feat_t;
#define feat_name(f) ((f)->name)
#define feat_cepsize(f) ((f)->cepsize)
#define feat_window_size(f) ((f)->window_size)
#define feat_n_stream(f) ((f)->n_stream)
#define feat_stream_len(f,i) ((f)->stream_len[i])
#define feat_dimension1(f) ((f)->n_sv ? (f)->n_sv : f->n_stream)
#define feat_dimension2(f,i) ((f)->lda ? (f)->out_dim : ((f)->sv_len ? (f)->sv_len[i] : f->stream_len[i]))
#define feat_dimension(f) ((f)->out_dim)
#define feat_stream_lengths(f) ((f)->lda ? (&(f)->out_dim) : (f)->sv_len ? (f)->sv_len : f->stream_len)
SPHINXBASE_EXPORT
int32 **parse_subvecs(char const *str);
SPHINXBASE_EXPORT
void subvecs_free(int32 **subvecs);
SPHINXBASE_EXPORT
mfcc_t ***feat_array_alloc(feat_t *fcb,
int32 nfr
);
SPHINXBASE_EXPORT
mfcc_t ***feat_array_realloc(feat_t *fcb,
mfcc_t ***old_feat,
int32 ofr,
int32 nfr
);
SPHINXBASE_EXPORT
void feat_array_free(mfcc_t ***feat);
SPHINXBASE_EXPORT
feat_t *feat_init(char const *type,
cmn_type_t cmn,
int32 varnorm,
agc_type_t agc,
int32 breport,
int32 cepsize
);
SPHINXBASE_EXPORT
int32 feat_read_lda(feat_t *feat,
const char *ldafile,
int32 dim
);
SPHINXBASE_EXPORT
void feat_lda_transform(feat_t *fcb,
mfcc_t ***inout_feat,
uint32 nfr
);
SPHINXBASE_EXPORT
int feat_set_subvecs(feat_t *fcb, int32 **subvecs);
SPHINXBASE_EXPORT
void feat_print(feat_t *fcb,
mfcc_t ***feat,
int32 nfr,
FILE *fp
);
SPHINXBASE_EXPORT
int32 feat_s2mfc2feat(feat_t *fcb,
const char *file,
const char *dir,
const char *cepext,
int32 sf, int32 ef, /* Start/End frames
within file to be read. Use
0,-1 to process entire
file */
mfcc_t ***feat,
int32 maxfr
);
SPHINXBASE_EXPORT
int32 feat_s2mfc2feat_live(feat_t *fcb,
mfcc_t **uttcep,
int32 *inout_ncep,
int32 beginutt,
int32 endutt,
mfcc_t ***ofeat
);
SPHINXBASE_EXPORT
void feat_update_stats(feat_t *fcb);
SPHINXBASE_EXPORT
feat_t *feat_retain(feat_t *f);
SPHINXBASE_EXPORT
int feat_free(feat_t *f
);
SPHINXBASE_EXPORT
void feat_report(feat_t *f
);
#ifdef __cplusplus
}
#endif
#endif
agc.h
routine that implements automatic gain control
agc_type_t
enum agc_type_e agc_type_t
Types of acoustic gain control to apply to the features.
agc_t
struct agc_s agc_t
Structure holding data for doing AGC.
cmn.h
Apply Cepstral Mean Normalization (CMN) to the set of input mfc frames.
cmn_type_t
enum cmn_type_e cmn_type_t
Types of cepstral mean normalization to apply to the features.
cmn
SPHINXBASE_EXPORT void cmn(cmn_t *cmn, mfcc_t **mfc, int32 varnorm, int32 n_frame)
CMN for the whole sentence.
Definition cmn.c:100
feat_array_alloc
SPHINXBASE_EXPORT mfcc_t *** feat_array_alloc(feat_t *fcb, int32 nfr)
Allocate an array to hold several frames worth of feature vectors.
Definition feat.c:356
feat_init
SPHINXBASE_EXPORT feat_t * feat_init(char const *type, cmn_type_t cmn, int32 varnorm, agc_type_t agc, int32 breport, int32 cepsize)
Initialize feature module to use the selected type of feature stream.
Definition feat.c:705
feat_update_stats
SPHINXBASE_EXPORT void feat_update_stats(feat_t *fcb)
Update the normalization stats, possibly in the end of utterance.
Definition feat.c:1424
parse_subvecs
SPHINXBASE_EXPORT int32 ** parse_subvecs(char const *str)
Parse subvector specification string.
Definition feat.c:169
feat_s2mfc2feat_live
SPHINXBASE_EXPORT int32 feat_s2mfc2feat_live(feat_t *fcb, mfcc_t **uttcep, int32 *inout_ncep, int32 beginutt, int32 endutt, mfcc_t ***ofeat)
Feature computation routine for live mode decoder.
Definition feat.c:1308
feat_lda_transform
SPHINXBASE_EXPORT void feat_lda_transform(feat_t *fcb, mfcc_t ***inout_feat, uint32 nfr)
Transform a block of features using the feature module's LDA transform.
Definition lda.c:139
feat_read_lda
SPHINXBASE_EXPORT int32 feat_read_lda(feat_t *feat, const char *ldafile, int32 dim)
Add an LDA transformation to the feature module from a file.
Definition lda.c:61
feat_array_realloc
SPHINXBASE_EXPORT mfcc_t *** feat_array_realloc(feat_t *fcb, mfcc_t ***old_feat, int32 ofr, int32 nfr)
Realloate the array of features.
Definition feat.c:389
feat_s2mfc2feat
SPHINXBASE_EXPORT int32 feat_s2mfc2feat(feat_t *fcb, const char *file, const char *dir, const char *cepext, int32 sf, int32 ef, mfcc_t ***feat, int32 maxfr)
Read a specified MFC file (or given segment within it), perform CMN/AGC as indicated by fcb,...
Definition feat.c:1170
feat_free
SPHINXBASE_EXPORT int feat_free(feat_t *f)
Release resource associated with feat_t.
Definition feat.c:1442
feat_set_subvecs
SPHINXBASE_EXPORT int feat_set_subvecs(feat_t *fcb, int32 **subvecs)
Add a subvector specification to the feature module.
Definition feat.c:277
subvecs_free
SPHINXBASE_EXPORT void subvecs_free(int32 **subvecs)
Free array of subvector specs.
Definition feat.c:267
feat_array_free
SPHINXBASE_EXPORT void feat_array_free(mfcc_t ***feat)
Free a buffer allocated with feat_array_alloc().
Definition feat.c:418
feat_report
SPHINXBASE_EXPORT void feat_report(feat_t *f)
Report the feat_t data structure.
Definition feat.c:1473
feat_retain
SPHINXBASE_EXPORT feat_t * feat_retain(feat_t *f)
Retain ownership of feat_t.
Definition feat.c:1435
feat_print
SPHINXBASE_EXPORT void feat_print(feat_t *fcb, mfcc_t ***feat, int32 nfr, FILE *fp)
Print the given block of feature vectors to the given FILE.
Definition feat.c:896
prim_type.h
Basic type definitions used in Sphinx.
cmn_t
wrapper of operation of the cepstral mean normalization.
Definition cmn.h:128
feat_s
Definition feat.h:116
feat_s::window_size
int32 window_size
Number of extra frames around given input frame needed to compute corresponding output feature (so to...
Definition feat.h:122
feat_s::subvecs
int32 ** subvecs
Subvector specification (or NULL for none).
Definition feat.h:126
feat_s::tmpcepbuf
mfcc_t ** tmpcepbuf
Array of pointers into cepbuf to handle border cases.
Definition feat.h:154
feat_s::n_lda
uint32 n_lda
Number of linear transformations in lda.
Definition feat.h:159
feat_s::lda
mfcc_t *** lda
Array of linear transformations (for LDA, MLLT, or whatever).
Definition feat.h:158
feat_s::agc_struct
agc_t * agc_struct
Structure that stores the temporary variables for acoustic gain control.
Definition feat.h:150
feat_s::sv_dim
int32 sv_dim
Total dimensionality of subvector (length of sv_buf).
Definition feat.h:128
feat_s::cmn
cmn_type_t cmn
Type of CMN to be performed on each utterance.
Definition feat.h:130
feat_s::agc
agc_type_t agc
Type of AGC to be performed on each utterance.
Definition feat.h:133
feat_s::n_stream
int32 n_stream
Number of feature streams; e.g., 4 in Sphinx-II.
Definition feat.h:120
feat_s::refcount
int refcount
Reference count.
Definition feat.h:117
feat_s::stream_len
uint32 * stream_len
Vector length of each feature stream.
Definition feat.h:121
feat_s::varnorm
int32 varnorm
Whether variance normalization is to be performed on each utt; Irrelevant if no CMN is performed.
Definition feat.h:131
feat_s::cepbuf
mfcc_t ** cepbuf
Circular buffer of MFCC frames for live feature computation.
Definition feat.h:153
feat_s::bufpos
int32 bufpos
Write index in cepbuf.
Definition feat.h:155
feat_s::compute_feat
void(* compute_feat)(struct feat_s *fcb, mfcc_t **input, mfcc_t **feat)
Feature computation function.
Definition feat.h:147
feat_s::name
char * name
Printable name for this feature type.
Definition feat.h:118
feat_s::out_dim
uint32 out_dim
Output dimensionality.
Definition feat.h:160
feat_s::sv_len
uint32 * sv_len
Vector length of each subvector.
Definition feat.h:125
feat_s::curpos
int32 curpos
Read index in cepbuf.
Definition feat.h:156
feat_s::cepsize
int32 cepsize
Size of input speech vector (typically, a cepstrum vector).
Definition feat.h:119
feat_s::cmn_struct
cmn_t * cmn_struct
Structure that stores the temporary variables for cepstral means normalization.
Definition feat.h:148
feat_s::sv_buf
mfcc_t * sv_buf
Temporary copy buffer for subvector projection.
Definition feat.h:127
feat_s::n_sv
int32 n_sv
Number of subvectors.
Definition feat.h:124
feat_t
Structure for describing a speech feature type Structure for describing a speech feature type (no.