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.
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 1999 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*
* HISTORY
* $Log$
* Revision 1.1 2006/04/05 20:27:30 dhdfu
* A Great Reorganzation of header files and executables
*
* Revision 1.17 2006/02/23 03:59:40 arthchan2003
* Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: a, Free buffers correctly. b, Fixed dox-doc.
*
* Revision 1.16.4.1 2005/07/05 06:25:08 arthchan2003
* Fixed dox-doc.
*
* Revision 1.16 2005/06/22 03:29:35 arthchan2003
* Makefile.am s for all subdirectory of libs3decoder/
*
* Revision 1.5 2005/06/13 04:02:56 archan
* Fixed most doxygen-style documentation under libs3decoder.
*
* Revision 1.4 2005/04/21 23:50:26 archan
* Some more refactoring on the how reporting of structures inside kbcore_t is done, it is now 50% nice. Also added class-based LM test case into test-decode.sh.in. At this moment, everything in search mode 5 is already done. It is time to test the idea whether the search can really be used.
*
* Revision 1.3 2005/03/30 01:22:46 archan
* Fixed mistakes in last updates. Add
*
*
* 20.Apr.2001 RAH (rhoughton@mediasite.com, ricky.houghton@cs.cmu.edu)
* Adding feat_free() to free allocated memory
*
* 04-Jan-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Started.
*/
#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, \
"current", \
"Cepstral mean normalization scheme ('current', 'prior', or 'none')" }, \
{ "-cmninit", \
ARG_STRING, \
"8.0", \
"Initial values (comma-separated) for cepstral mean when 'prior' 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
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
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:895
feat_report
SPHINXBASE_EXPORT void feat_report(feat_t *f)
Report the feat_t data structure.
Definition: feat.c:1461
feat_s::n_stream
int32 n_stream
Number of feature streams; e.g., 4 in Sphinx-II.
Definition: feat.h:159
feat_s::name
char * name
Printable name for this feature type.
Definition: feat.h:157
agc.h
routine that implements automatic gain control
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_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_s::agc_struct
agc_t * agc_struct
Structure that stores the temporary variables for acoustic gain control.
Definition: feat.h:189
feat_s::subvecs
int32 ** subvecs
Subvector specification (or NULL for none)
Definition: feat.h:165
cmn.h
Apply Cepstral Mean Normalization (CMN) to the set of input mfc frames.
feat_s::agc
agc_type_t agc
Type of AGC to be performed on each utterance.
Definition: feat.h:172
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_s::bufpos
int32 bufpos
Write index in cepbuf.
Definition: feat.h:194
feat_s::sv_len
uint32 * sv_len
Vector length of each subvector.
Definition: feat.h:164
feat_s::refcount
int refcount
Reference count.
Definition: feat.h:156
feat_s::sv_buf
mfcc_t * sv_buf
Temporary copy buffer for subvector projection.
Definition: feat.h:166
feat_s::stream_len
uint32 * stream_len
Vector length of each feature stream.
Definition: feat.h:160
prim_type.h
Basic type definitions used in Sphinx.
feat_s::compute_feat
void(* compute_feat)(struct feat_s *fcb, mfcc_t **input, mfcc_t **feat)
Feature computation function.
Definition: feat.h:186
feat_t
Structure for describing a speech feature type Structure for describing a speech feature type (no...
cmn
SPHINXBASE_EXPORT void cmn(cmn_t *cmn, mfcc_t **mfc, int32 varnorm, int32 n_frame)
CMN for the whole sentence.
Definition: cmn.c:150
feat_s::cepsize
int32 cepsize
Size of input speech vector (typically, a cepstrum vector)
Definition: feat.h:158
feat_s::lda
mfcc_t *** lda
Array of linear transformations (for LDA, MLLT, or whatever)
Definition: feat.h:197
feat_s::n_lda
uint32 n_lda
Number of linear transformations in lda.
Definition: feat.h:198
feat_s::out_dim
uint32 out_dim
Output dimensionality.
Definition: feat.h:199
parse_subvecs
SPHINXBASE_EXPORT int32 ** parse_subvecs(char const *str)
Parse subvector specification string.
Definition: feat.c:169
agc_type_t
enum agc_type_e agc_type_t
Types of acoustic gain control to apply to the features.
feat_retain
SPHINXBASE_EXPORT feat_t * feat_retain(feat_t *f)
Retain ownership of feat_t.
Definition: feat.c:1423
feat_s::cepbuf
mfcc_t ** cepbuf
Circular buffer of MFCC frames for live feature computation.
Definition: feat.h:192
feat_s::cmn_struct
cmn_t * cmn_struct
Structure that stores the temporary variables for cepstral means normalization.
Definition: feat.h:187
feat_s::varnorm
int32 varnorm
Whether variance normalization is to be performed on each utt; Irrelevant if no CMN is performed...
Definition: feat.h:170
feat_s::tmpcepbuf
mfcc_t ** tmpcepbuf
Array of pointers into cepbuf to handle border cases.
Definition: feat.h:193
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:1169
subvecs_free
SPHINXBASE_EXPORT void subvecs_free(int32 **subvecs)
Free array of subvector specs.
Definition: feat.c:267
feat_s
Definition: feat.h:155
feat_s::sv_dim
int32 sv_dim
Total dimensionality of subvector (length of sv_buf)
Definition: feat.h:167
feat_s::curpos
int32 curpos
Read index in cepbuf.
Definition: feat.h:195
agc_s
Structure holding data for doing AGC.
Definition: agc.h:113
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_s::n_sv
int32 n_sv
Number of subvectors.
Definition: feat.h:163
feat_s::cmn
cmn_type_t cmn
Type of CMN to be performed on each utterance.
Definition: feat.h:169
cmn_t
wrapper of operation of the cepstral mean normalization.
Definition: cmn.h:128
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
cmn_type_t
enum cmn_type_e cmn_type_t
Types of cepstral mean normalization to apply to the features.
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_free
SPHINXBASE_EXPORT int feat_free(feat_t *f)
Release resource associated with feat_t.
Definition: feat.c:1430
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
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:1307
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:161