50 #pragma warning (disable: 4018)
58 #define MATRIX_FILE_VERSION "0.1"
65 uint32 chksum, i, m, n;
66 char **argname, **argval;
69 if (feat->n_stream != 1) {
70 E_ERROR(
"LDA incompatible with multi-stream features (n_stream = %d)\n",
75 if ((fh = fopen(ldafile,
"rb")) == NULL) {
76 E_ERROR_SYSTEM(
"Failed to open transform file '%s' for reading", ldafile);
80 if (
bio_readhdr(fh, &argname, &argval, &byteswap) < 0) {
81 E_ERROR(
"Failed to read header from transform file '%s'\n", ldafile);
86 for (i = 0; argname[i]; i++) {
87 if (strcmp(argname[i],
"version") == 0) {
88 if (strcmp(argval[i], MATRIX_FILE_VERSION) != 0)
89 E_WARN(
"%s: Version mismatch: %s, expecting %s\n",
90 ldafile, argval[i], MATRIX_FILE_VERSION);
95 argname = argval = NULL;
107 &feat->n_lda, &m, &n,
108 fh, byteswap, &chksum) < 0) {
113 feat->lda = (
void *)outlda;
120 for (i = 0; i < feat->n_lda * m * n; ++i) {
121 feat->lda[0][0][i] = FLOAT2MFCC(((
float *)feat->lda[0][0])[i]);
126 if (n != feat->stream_len[0])
127 E_FATAL(
"LDA matrix dimension %d doesn't match feature stream size %d\n", n, feat->stream_len[0]);
130 if (dim > m || dim <= 0) {
144 tmp =
ckd_calloc(fcb->stream_len[0],
sizeof(mfcc_t));
145 for (i = 0; i < nfr; ++i) {
149 memset(tmp, 0,
sizeof(mfcc_t) * fcb->stream_len[0]);
151 for (k = 0; k < fcb->stream_len[0]; ++k) {
152 tmp[j] += MFCCMUL(inout_feat[i][0][k], fcb->lda[0][j][k]);
155 memcpy(inout_feat[i][0], tmp, fcb->stream_len[0] *
sizeof(mfcc_t));
#define E_ERROR_SYSTEM(...)
Print error text; Call perror("");.
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
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.
#define E_ERROR(...)
Print error message to error log.
#define feat_dimension(f)
Total dimensionality of feature output.
Sphinx's memory allocation/deallocation routines.
Cross platform binary IO to process files in sphinx3 format.
SPHINXBASE_EXPORT int32 bio_fread_3d(void ****arr, size_t e_sz, uint32 *d1, uint32 *d2, uint32 *d3, FILE *fp, uint32 swap, uint32 *chksum)
Read a 3-d array (set of matrices)
Structure for describing a speech feature type Structure for describing a speech feature type (no...
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
compute the dynamic coefficients from the cepstral vector.
Implementation of logging routines.
#define E_WARN(...)
Print warning message to error log.
SPHINXBASE_EXPORT void ckd_free_3d(void *ptr)
Free a 3-D array (ptr) previously allocated by ckd_calloc_3d.
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.
#define E_FATAL(...)
Exit with non-zero status after error message.
SPHINXBASE_EXPORT void bio_hdrarg_free(char **name, char **val)
Free name and value strings previously allocated and returned by bio_readhdr.
SPHINXBASE_EXPORT int32 bio_readhdr(FILE *fp, char ***name, char ***val, int32 *swap)
Read binary file format header: has the following format.