126 #pragma warning (disable: 4244 4996)
129 #include "sphinxbase/fe.h"
140 #define FEAT_VERSION "1.0"
141 #define FEAT_DCEP_WIN 2
145 cep_dump_dbg(
feat_t *fcb, mfcc_t **mfc, int32 nfr,
const char *text)
150 for (i = 0; i < nfr; i++) {
151 for (j = 0; j < fcb->cepsize; j++) {
152 fprintf(stderr,
"%f ", MFCC2FLOAT(mfc[i][j]));
154 fprintf(stderr,
"\n");
158 feat_print_dbg(
feat_t *fcb, mfcc_t ***feat, int32 nfr,
const char *text)
164 #define cep_dump_dbg(fcb,mfc,nfr,text)
165 #define feat_print_dbg(fcb,mfc,nfr,text)
185 if (sscanf(strp,
"%d%n", &n, &l) != 1)
186 E_FATAL(
"'%s': Couldn't read int32 @pos %d\n", str,
193 if (sscanf(strp,
"%d%n", &n2, &l) != 1)
194 E_FATAL(
"'%s': Couldn't read int32 @pos %d\n", str,
201 if ((n < 0) || (n > n2))
202 E_FATAL(
"'%s': Bad subrange spec ending @pos %d\n", str,
205 for (; n <= n2; n++) {
207 for (gn = dimlist; gn; gn = gnode_next(gn))
208 if (gnode_int32(gn) == n)
211 E_FATAL(
"'%s': Duplicate dimension ending @pos %d\n",
217 if ((*strp ==
'\0') || (*strp ==
'/'))
221 E_FATAL(
"'%s': Bad delimiter @pos %d\n", str, strp - str);
231 assert(*strp ==
'/');
237 subvec = (int32 **)
ckd_calloc(n + 1,
sizeof(int32 *));
240 for (--n, gn = veclist; (n >= 0) && gn; gn = gnode_next(gn), --n) {
245 E_FATAL(
"'%s': 0-length subvector\n", str);
247 subvec[n] = (int32 *)
ckd_calloc(n2 + 1,
sizeof(int32));
250 for (--n2; (n2 >= 0) && gn2; gn2 = gnode_next(gn2), --n2)
251 subvec[n][n2] = gnode_int32(gn2);
252 assert((n2 < 0) && (!gn2));
254 assert((n < 0) && (!gn));
257 for (gn = veclist; gn; gn = gnode_next(gn)) {
271 for (sv = subvecs; sv && *sv; ++sv)
280 uint32 n_sv, n_dim, i;
282 if (subvecs == NULL) {
294 if (fcb->n_stream != 1) {
295 E_ERROR(
"Subvector specifications require single-stream features!");
301 for (sv = subvecs; sv && *sv; ++sv) {
304 for (d = *sv; d && *d != -1; ++d) {
310 E_ERROR(
"Total dimensionality of subvector specification %d "
316 fcb->subvecs = subvecs;
317 fcb->sv_len = (uint32 *)
ckd_calloc(n_sv,
sizeof(*fcb->sv_len));
318 fcb->sv_buf = (mfcc_t *)
ckd_calloc(n_dim,
sizeof(*fcb->sv_buf));
320 for (i = 0; i < n_sv; ++i) {
322 for (d = subvecs[i]; d && *d != -1; ++d) {
334 feat_subvec_project(
feat_t *fcb, mfcc_t ***inout_feat, uint32 nfr)
338 if (fcb->subvecs == NULL)
340 for (i = 0; i < nfr; ++i) {
345 for (j = 0; j < fcb->n_sv; ++j) {
347 for (d = fcb->subvecs[j]; d && *d != -1; ++d) {
348 *out++ = inout_feat[i][0][*d];
351 memcpy(inout_feat[i][0], fcb->sv_buf, fcb->sv_dim *
sizeof(*fcb->sv_buf));
359 mfcc_t *data, *d, ***feat;
368 for (i = 0; i < fcb->n_stream; ++i)
369 k += fcb->stream_len[i];
371 assert(k >= fcb->sv_dim);
375 data = (mfcc_t *)
ckd_calloc(nfr * k,
sizeof(mfcc_t));
377 for (i = 0; i < nfr; i++) {
402 for (i = 0; i < fcb->n_stream; ++i)
403 k += fcb->stream_len[i];
405 assert(k >= fcb->sv_dim);
409 cf = (nfr < ofr) ? nfr : ofr;
410 memcpy(new_feat[0][0], old_feat[0][0], cf * k *
sizeof(mfcc_t));
425 feat_s2_4x_cep2feat(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
429 mfcc_t *w1, *w_1, *_w1, *_w_1;
443 memcpy(feat[0], mfc[0] + 1, (
feat_cepsize(fcb) - 1) *
sizeof(mfcc_t));
471 d2 = w_1[i] - _w_1[i];
479 f[1] = mfc[2][0] - mfc[-2][0];
481 d1 = mfc[3][0] - mfc[-1][0];
482 d2 = mfc[1][0] - mfc[-3][0];
488 feat_s3_1x39_cep2feat(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
492 mfcc_t *w1, *w_1, *_w1, *_w_1;
503 memcpy(feat[0], mfc[0] + 1, (
feat_cepsize(fcb) - 1) *
sizeof(mfcc_t));
518 f[1] = mfc[2][0] - mfc[-2][0];
520 d1 = mfc[3][0] - mfc[-1][0];
521 d2 = mfc[1][0] - mfc[-3][0];
534 d2 = w_1[i] - _w_1[i];
542 feat_s3_cep(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
549 memcpy(feat[0], mfc[0],
feat_cepsize(fcb) *
sizeof(mfcc_t));
553 feat_s3_cep_dcep(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
565 memcpy(feat[0], mfc[0],
feat_cepsize(fcb) *
sizeof(mfcc_t));
579 feat_1s_c_d_dd_cep2feat(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
583 mfcc_t *w1, *w_1, *_w1, *_w_1;
593 memcpy(feat[0], mfc[0],
feat_cepsize(fcb) *
sizeof(mfcc_t));
599 w = mfc[FEAT_DCEP_WIN];
600 _w = mfc[-FEAT_DCEP_WIN];
611 w1 = mfc[FEAT_DCEP_WIN + 1];
612 _w1 = mfc[-FEAT_DCEP_WIN + 1];
613 w_1 = mfc[FEAT_DCEP_WIN - 1];
614 _w_1 = mfc[-FEAT_DCEP_WIN - 1];
618 d2 = w_1[i] - _w_1[i];
625 feat_1s_c_d_ld_dd_cep2feat(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
629 mfcc_t *w1, *w_1, *_w1, *_w_1;
639 memcpy(feat[0], mfc[0],
feat_cepsize(fcb) *
sizeof(mfcc_t));
645 w = mfc[FEAT_DCEP_WIN];
646 _w = mfc[-FEAT_DCEP_WIN];
655 w = mfc[FEAT_DCEP_WIN * 2];
656 _w = mfc[-FEAT_DCEP_WIN * 2];
667 w1 = mfc[FEAT_DCEP_WIN + 1];
668 _w1 = mfc[-FEAT_DCEP_WIN + 1];
669 w_1 = mfc[FEAT_DCEP_WIN - 1];
670 _w_1 = mfc[-FEAT_DCEP_WIN - 1];
674 d2 = w_1[i] - _w_1[i];
681 feat_copy(
feat_t * fcb, mfcc_t ** mfc, mfcc_t ** feat)
688 for (i = -win; i <= win; ++i) {
696 memcpy(feat[j] + ((i + win) * stream_len),
698 stream_len *
sizeof(mfcc_t));
714 (
"Initializing feature stream to type: '%s', ceplen=%d, CMN='%s', VARNORM='%s', AGC='%s'\n",
720 if (strcmp(type,
"s2_4x") == 0) {
723 E_ERROR(
"s2_4x features require cepsize == 13\n");
729 fcb->stream_len = (uint32 *)
ckd_calloc(4,
sizeof(uint32));
730 fcb->stream_len[0] = 12;
731 fcb->stream_len[1] = 24;
732 fcb->stream_len[2] = 3;
733 fcb->stream_len[3] = 12;
735 fcb->window_size = 4;
736 fcb->compute_feat = feat_s2_4x_cep2feat;
738 else if ((strcmp(type,
"s3_1x39") == 0) || (strcmp(type,
"1s_12c_12d_3p_12dd") == 0)) {
741 E_ERROR(
"s2_4x features require cepsize == 13\n");
747 fcb->stream_len = (uint32 *)
ckd_calloc(1,
sizeof(uint32));
748 fcb->stream_len[0] = 39;
750 fcb->window_size = 3;
751 fcb->compute_feat = feat_s3_1x39_cep2feat;
753 else if (strncmp(type,
"1s_c_d_dd", 9) == 0) {
754 fcb->cepsize = cepsize;
756 fcb->stream_len = (uint32 *)
ckd_calloc(1,
sizeof(uint32));
757 fcb->stream_len[0] = cepsize * 3;
758 fcb->out_dim = cepsize * 3;
759 fcb->window_size = FEAT_DCEP_WIN + 1;
760 fcb->compute_feat = feat_1s_c_d_dd_cep2feat;
762 else if (strncmp(type,
"1s_c_d_ld_dd", 12) == 0) {
763 fcb->cepsize = cepsize;
765 fcb->stream_len = (uint32 *)
ckd_calloc(1,
sizeof(uint32));
766 fcb->stream_len[0] = cepsize * 4;
767 fcb->out_dim = cepsize * 4;
768 fcb->window_size = FEAT_DCEP_WIN * 2;
769 fcb->compute_feat = feat_1s_c_d_ld_dd_cep2feat;
771 else if (strncmp(type,
"cep_dcep", 8) == 0 || strncmp(type,
"1s_c_d", 6) == 0) {
773 fcb->cepsize = cepsize;
775 fcb->stream_len = (uint32 *)
ckd_calloc(1,
sizeof(uint32));
777 fcb->out_dim = fcb->stream_len[0];
778 fcb->window_size = 2;
779 fcb->compute_feat = feat_s3_cep_dcep;
781 else if (strncmp(type,
"cep", 3) == 0 || strncmp(type,
"1s_c", 4) == 0) {
783 fcb->cepsize = cepsize;
785 fcb->stream_len = (uint32 *)
ckd_calloc(1,
sizeof(uint32));
787 fcb->out_dim = fcb->stream_len[0];
788 fcb->window_size = 0;
789 fcb->compute_feat = feat_s3_cep;
791 else if (strncmp(type,
"1s_3c", 5) == 0 || strncmp(type,
"1s_4c", 5) == 0) {
793 if (strncmp(type,
"1s_3c", 5) == 0)
794 fcb->window_size = 3;
796 fcb->window_size = 4;
798 fcb->cepsize = cepsize;
800 fcb->stream_len = (uint32 *)
ckd_calloc(1,
sizeof(uint32));
801 fcb->stream_len[0] =
feat_cepsize(fcb) * (2 * fcb->window_size + 1);
802 fcb->out_dim = fcb->stream_len[0];
803 fcb->compute_feat = feat_copy;
820 for (i = 1; i < len - 1; i++) {
821 if (mtype[i] ==
',') {
825 else if (mtype[i] ==
':') {
827 fcb->window_size = atoi(mtype + i + 1);
833 fcb->stream_len = (uint32 *)
ckd_calloc(k,
sizeof(uint32));
840 while (sscanf(strp,
"%s%n", wd, &l) == 1) {
842 if ((i >= fcb->n_stream)
843 || (sscanf(wd,
"%u", &(fcb->stream_len[i])) != 1)
844 || (fcb->stream_len[i] <= 0))
845 E_FATAL(
"Bad feature type argument\n");
847 fcb->cepsize += fcb->stream_len[i];
848 if (fcb->window_size > 0)
849 fcb->stream_len[i] *= (fcb->window_size * 2 + 1);
851 fcb->out_dim += fcb->stream_len[i];
854 if (i != fcb->n_stream)
855 E_FATAL(
"Bad feature type argument\n");
856 if (fcb->cepsize != cepsize)
857 E_FATAL(
"Bad feature type argument\n");
860 fcb->compute_feat = feat_copy;
868 fcb->varnorm = varnorm;
869 if (agc != AGC_NONE) {
877 agc_emax_set(fcb->agc_struct, (cmn != CMN_NONE) ? 5.0 : 10.0);
889 sizeof(*fcb->tmpcepbuf));
900 for (i = 0; i < nfr; i++) {
901 fprintf(fp,
"%8d:\n", i);
904 fprintf(fp,
"\t%2d:", j);
907 fprintf(fp,
" %8.4f", MFCC2FLOAT(feat[i][j][k]));
916 feat_cmn(
feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 beginutt, int32 endutt)
920 if (!(beginutt && endutt)
921 && cmn_type != CMN_NONE)
922 fcb->cmn = cmn_type = CMN_LIVE;
926 cmn(fcb->cmn_struct, mfc, fcb->varnorm, nfr);
929 cmn_live(fcb->cmn_struct, mfc, fcb->varnorm, nfr);
936 cep_dump_dbg(fcb, mfc, nfr,
"After CMN");
940 feat_agc(
feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 beginutt, int32 endutt)
944 if (!(beginutt && endutt)
945 && agc_type != AGC_NONE)
950 agc_max(fcb->agc_struct, mfc, nfr);
953 agc_emax(fcb->agc_struct, mfc, nfr);
963 cep_dump_dbg(fcb, mfc, nfr,
"After AGC");
967 feat_compute_utt(
feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 win, mfcc_t ***feat)
971 cep_dump_dbg(fcb, mfc, nfr,
"Incoming features (after padding)");
974 for (i = win; i < nfr - win; i++) {
975 fcb->compute_feat(fcb, mfc + i, feat[i - win]);
978 feat_print_dbg(fcb, feat, nfr - win * 2,
"After dynamic feature computation");
982 feat_print_dbg(fcb, feat, nfr - win * 2,
"After LDA");
986 feat_subvec_project(fcb, feat, nfr - win * 2);
987 feat_print_dbg(fcb, feat, nfr - win * 2,
"After subvector projection");
1005 feat_s2mfc_read_norm_pad(
feat_t *fcb,
char *file, int32 win,
1013 float32 *float_feat;
1014 struct stat statbuf;
1015 int32 i, n, byterev;
1016 int32 start_pad, end_pad;
1023 E_INFO(
"Reading mfc file: '%s'[%d..%d]\n", file, sf, ef);
1024 if (ef >= 0 && ef <= sf) {
1025 E_ERROR(
"%s: End frame (%d) <= Start frame (%d)\n", file, ef, sf);
1031 || ((fp = fopen(file,
"rb")) == NULL)) {
1037 if (
fread_retry(&n_float32,
sizeof(int32), 1, fp) != 1) {
1038 E_ERROR(
"%s: fread(#floats) failed\n", file);
1045 if ((int32) (n_float32 *
sizeof(float32) + 4) != (int32) statbuf.st_size) {
1049 if ((int32) (n *
sizeof(float32) + 4) != (int32) (statbuf.st_size)) {
1051 (
"%s: Header size field: %d(%08x); filesize: %d(%08x)\n",
1052 file, n_float32, n_float32, statbuf.st_size,
1061 if (n_float32 <= 0) {
1062 E_ERROR(
"%s: Header size field (#floats) = %d\n", file, n_float32);
1068 n = n_float32 / cepsize;
1069 if (n * cepsize != n_float32) {
1070 E_ERROR(
"Header size field: %d; not multiple of %d\n", n_float32,
1079 E_ERROR(
"%s: Start frame (%d) beyond file size (%d)\n", file,
1088 E_WARN(
"%s: End frame (%d) beyond file size (%d), will truncate\n",
1103 end_pad = ef - n + 1;
1110 if ((ef - sf + 1) < n)
1112 if (maxfr > 0 && n + start_pad + end_pad > maxfr) {
1113 E_ERROR(
"%s: Maximum output size(%d frames) < actual #frames(%d)\n",
1114 file, maxfr, n + start_pad + end_pad);
1120 if (out_mfc != NULL) {
1122 mfc = (mfcc_t **)
ckd_calloc_2d(n + start_pad + end_pad, cepsize,
sizeof(mfcc_t));
1124 fseek(fp, sf * cepsize *
sizeof(float32), SEEK_CUR);
1125 n_float32 = n * cepsize;
1127 float_feat =
ckd_calloc(n_float32,
sizeof(float32));
1129 float_feat = mfc[start_pad];
1131 if (
fread_retry(float_feat,
sizeof(float32), n_float32, fp) != n_float32) {
1132 E_ERROR(
"%s: fread(%dx%d) (MFC data) failed\n", file, n, cepsize);
1138 for (i = 0; i < n_float32; i++) {
1139 SWAP_FLOAT32(&float_feat[i]);
1143 for (i = 0; i < n_float32; ++i) {
1144 mfc[start_pad][i] = FLOAT2MFCC(float_feat[i]);
1150 feat_cmn(fcb, mfc + start_pad, n, 1, 1);
1151 feat_agc(fcb, mfc + start_pad, n, 1, 1);
1154 for (i = 0; i < start_pad; ++i)
1155 memcpy(mfc[i], mfc[start_pad], cepsize *
sizeof(mfcc_t));
1156 for (i = 0; i < end_pad; ++i)
1157 memcpy(mfc[start_pad + n + i], mfc[start_pad + n - 1],
1158 cepsize *
sizeof(mfcc_t));
1164 return n + start_pad + end_pad;
1171 int32 sf, int32 ef, mfcc_t *** feat, int32 maxfr)
1176 size_t file_length, cepext_length, path_length = 0;
1179 if (fcb->cepsize <= 0) {
1180 E_ERROR(
"Bad cepsize: %d\n", fcb->cepsize);
1203 E_INFO(
"At directory . (current directory)\n");
1206 E_INFO(
"At directory %s\n", dir);
1210 path_length += strlen(dir) + 1;
1216 file_length = strlen(file);
1217 cepext_length = strlen(cepext);
1218 if ((file_length > cepext_length)
1219 && (strcmp(file + file_length - cepext_length, cepext) == 0)) {
1227 path_length += file_length + cepext_length + 1;
1228 path = (
char*)
ckd_calloc(path_length,
sizeof(
char));
1230 #ifdef HAVE_SNPRINTF
1234 while ((file_length = snprintf(path, path_length,
"%s%s%s%s", dir, ps, file, cepext)) > path_length) {
1235 path_length = file_length;
1236 path = (
char*)
ckd_realloc(path, path_length *
sizeof(
char));
1239 sprintf(path,
"%s%s%s%s", dir, ps, file, cepext);
1250 nfr = feat_s2mfc_read_norm_pad(fcb, path, win, sf, ef, &mfc, maxfr, fcb->cepsize);
1258 feat_compute_utt(fcb, mfc, nfr, win, feat);
1264 nfr = feat_s2mfc_read_norm_pad(fcb, path, win, sf, ef, NULL, maxfr, fcb->cepsize);
1271 return (nfr - win * 2);
1275 feat_s2mfc2feat_block_utt(
feat_t * fcb, mfcc_t ** uttcep,
1276 int32 nfr, mfcc_t *** ofeat)
1279 int32 i, win, cepsize;
1287 cepbuf = (mfcc_t **)
ckd_calloc(nfr + win * 2,
sizeof(mfcc_t *));
1288 memcpy(cepbuf + win, uttcep, nfr *
sizeof(mfcc_t *));
1291 feat_cmn(fcb, cepbuf + win, nfr, 1, 1);
1292 feat_agc(fcb, cepbuf + win, nfr, 1, 1);
1295 for (i = 0; i < win; ++i) {
1296 cepbuf[i] = fcb->cepbuf[i];
1297 memcpy(cepbuf[i], uttcep[0], cepsize *
sizeof(mfcc_t));
1298 cepbuf[nfr + win + i] = fcb->cepbuf[win + i];
1299 memcpy(cepbuf[nfr + win + i], uttcep[nfr - 1], cepsize *
sizeof(mfcc_t));
1302 feat_compute_utt(fcb, cepbuf, nfr + win * 2, win, ofeat);
1309 int32 beginutt, int32 endutt, mfcc_t *** ofeat)
1311 int32 win, cepsize, nbufcep;
1312 int32 i, j, nfeatvec;
1316 if (inout_ncep == NULL) inout_ncep = &zero;
1319 if (beginutt && endutt && *inout_ncep > 0)
1320 return feat_s2mfc2feat_block_utt(fcb, uttcep, *inout_ncep, ofeat);
1327 fcb->bufpos = fcb->curpos;
1330 nbufcep = fcb->bufpos - fcb->curpos;
1332 nbufcep = fcb->bufpos + LIVEBUFBLOCKSIZE - fcb->curpos;
1334 if (beginutt && *inout_ncep > 0)
1340 if (nbufcep + *inout_ncep > LIVEBUFBLOCKSIZE) {
1343 *inout_ncep = LIVEBUFBLOCKSIZE - nbufcep - win;
1349 feat_cmn(fcb, uttcep, *inout_ncep, beginutt, endutt);
1350 feat_agc(fcb, uttcep, *inout_ncep, beginutt, endutt);
1355 if (beginutt && *inout_ncep > 0) {
1356 for (i = 0; i < win; i++) {
1357 memcpy(fcb->cepbuf[fcb->bufpos++], uttcep[0],
1358 cepsize *
sizeof(mfcc_t));
1359 fcb->bufpos %= LIVEBUFBLOCKSIZE;
1362 fcb->curpos = fcb->bufpos;
1367 for (i = 0; i < *inout_ncep; ++i) {
1368 memcpy(fcb->cepbuf[fcb->bufpos++], uttcep[i],
1369 cepsize *
sizeof(mfcc_t));
1370 fcb->bufpos %= LIVEBUFBLOCKSIZE;
1379 if (fcb->bufpos == 0)
1380 tpos = LIVEBUFBLOCKSIZE - 1;
1382 tpos = fcb->bufpos - 1;
1383 for (i = 0; i < win; ++i) {
1384 memcpy(fcb->cepbuf[fcb->bufpos++], fcb->cepbuf[tpos],
1385 cepsize *
sizeof(mfcc_t));
1386 fcb->bufpos %= LIVEBUFBLOCKSIZE;
1391 nfeatvec = nbufcep - win;
1395 for (i = 0; i < nfeatvec; ++i) {
1397 if (fcb->curpos - win < 0 || fcb->curpos + win >= LIVEBUFBLOCKSIZE) {
1399 for (j = -win; j <= win; ++j) {
1401 (fcb->curpos + j + LIVEBUFBLOCKSIZE) % LIVEBUFBLOCKSIZE;
1402 fcb->tmpcepbuf[win + j] = fcb->cepbuf[tmppos];
1404 fcb->compute_feat(fcb, fcb->tmpcepbuf + win, ofeat[i]);
1407 fcb->compute_feat(fcb, fcb->cepbuf + fcb->curpos, ofeat[i]);
1411 fcb->curpos %= LIVEBUFBLOCKSIZE;
1418 feat_subvec_project(fcb, ofeat, nfeatvec);
1426 if (fcb->cmn == CMN_LIVE) {
1429 if (fcb->agc == AGC_EMAX || fcb->agc == AGC_MAX) {
1446 if (--f->refcount > 0)
1464 cmn_free(f->cmn_struct);
1476 E_INFO_NOFN(
"Initialization of feat_t, report:\n");
1479 E_INFO_NOFN(
"Number of streams = %d\n", f->n_stream);
1480 for (i = 0; i < f->n_stream; i++) {
1484 E_INFO_NOFN(
"Number of subvectors = %d\n", f->n_sv);
1485 for (i = 0; i < f->n_sv; i++) {
1489 for (sv = f->subvecs[i]; sv && *sv != -1; ++sv)
1493 E_INFO_NOFN(
"Whether CMN is used = %d\n", f->cmn);
1494 E_INFO_NOFN(
"Whether AGC is used = %d\n", f->agc);
1495 E_INFO_NOFN(
"Whether variance is normalized = %d\n", f->varnorm);
#define E_ERROR_SYSTEM(...)
Print error text; Call perror("");.
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.
SPHINXBASE_EXPORT void feat_report(feat_t *f)
Report the feat_t data structure.
#define E_INFO(...)
Print logging information to standard error stream.
SPHINXBASE_EXPORT void agc_noise(agc_t *agc, mfcc_t **mfc, int32 n_frame)
Apply AGC using noise threshold to the given block of MFC vectors.
SPHINXBASE_EXPORT void agc_max(agc_t *agc, mfcc_t **mfc, int32 n_frame)
Apply AGC to the given mfc vectors (normalize all C0 mfc coefficients in the given input such that th...
#define ckd_calloc_2d(d1, d2, sz)
Macro for ckd_calloc_2d
routine that implements automatic gain control
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
SPHINXBASE_EXPORT glist_t glist_add_int32(glist_t g, int32 val)
Create and prepend a new list node containing an integer.
#define E_ERROR(...)
Print error message to error log.
SPHINXBASE_EXPORT mfcc_t *** feat_array_alloc(feat_t *fcb, int32 nfr)
Allocate an array to hold several frames worth of feature vectors.
#define feat_dimension(f)
Total dimensionality of feature output.
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT const char * agc_type_str[]
String representations of agc_type_t values.
Apply Cepstral Mean Normalization (CMN) to the set of input mfc frames.
SPHINXBASE_EXPORT mfcc_t *** feat_array_realloc(feat_t *fcb, mfcc_t ***old_feat, int32 ofr, int32 nfr)
Realloate the array of features.
SPHINXBASE_EXPORT int32 stat_retry(const char *file, struct stat *statbuf)
There is no bitstream decoder, because a stream abstraction is too slow.
Cross platform binary IO to process files in sphinx3 format.
#define E_INFOCONT(...)
Continue printing the information to standard error stream.
#define feat_cepsize(f)
Input dimensionality of feature.
A node in a generic list.
#define ckd_salloc(ptr)
Macro for ckd_salloc
Basic type definitions used in Sphinx.
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.
SPHINXBASE_EXPORT glist_t glist_add_ptr(glist_t g, void *ptr)
Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generi...
SPHINXBASE_EXPORT void cmn(cmn_t *cmn, mfcc_t **mfc, int32 varnorm, int32 n_frame)
CMN for the whole sentence.
SPHINXBASE_EXPORT agc_t * agc_init(void)
Initialize AGC structure with default values.
SPHINXBASE_EXPORT void agc_free(agc_t *agc)
Free AGC structure.
SPHINXBASE_EXPORT int32 ** parse_subvecs(char const *str)
Parse subvector specification string.
enum agc_type_e agc_type_t
Types of acoustic gain control to apply to the features.
SPHINXBASE_EXPORT feat_t * feat_retain(feat_t *f)
Retain ownership of feat_t.
SPHINXBASE_EXPORT void glist_free(glist_t g)
Free the given generic list; user-defined data contained within is not automatically freed...
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...
#define gnode_ptr(g)
Head of a list of gnodes.
SPHINXBASE_EXPORT void subvecs_free(int32 **subvecs)
Free array of subvector specs.
compute the dynamic coefficients from the cepstral vector.
SPHINXBASE_EXPORT void agc_emax_set(agc_t *agc, float32 m)
Set the current AGC maximum estimate.
Implementation of logging routines.
#define feat_window_size(f)
Size of dynamic feature window.
#define feat_stream_len(f, i)
Length of feature stream i.
Generic linked-lists maintenance.
#define E_WARN(...)
Print warning message to error log.
SPHINXBASE_EXPORT void feat_array_free(mfcc_t ***feat)
Free a buffer allocated with feat_array_alloc()
#define feat_n_stream(f)
Number of feature streams.
SPHINXBASE_EXPORT void agc_emax_update(agc_t *agc)
Update AGC parameters for next utterance.
SPHINXBASE_EXPORT void ckd_free_3d(void *ptr)
Free a 3-D array (ptr) previously allocated by ckd_calloc_3d.
SPHINXBASE_EXPORT int32 fread_retry(void *pointer, int32 size, int32 num_items, FILE *stream)
NFS file reads seem to fail now and then.
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.
enum cmn_type_e cmn_type_t
Types of cepstral mean normalization to apply to the features.
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.
SPHINXBASE_EXPORT const char * cmn_type_str[]
String representations of cmn_type_t values.
SPHINXBASE_EXPORT void ckd_free_2d(void *ptr)
Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
SPHINXBASE_EXPORT void feat_update_stats(feat_t *fcb)
Update the normalization stats, possibly in the end of utterance.
SPHINXBASE_EXPORT void agc_emax(agc_t *agc, mfcc_t **mfc, int32 n_frame)
Apply AGC to the given block of MFC vectors.
SPHINXBASE_EXPORT void cmn_live(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
CMN for one block of data, using live mean.
#define feat_dimension1(f)
Number of streams or subvectors in feature output.
#define E_INFO_NOFN(...)
Print logging information without filename.
#define E_FATAL(...)
Exit with non-zero status after error message.
SPHINXBASE_EXPORT int feat_free(feat_t *f)
Release resource associated with feat_t.
SPHINXBASE_EXPORT void cmn_live_update(cmn_t *cmn)
Update live mean based on observed data.
SPHINXBASE_EXPORT int feat_set_subvecs(feat_t *fcb, int32 **subvecs)
Add a subvector specification to the feature module.
#define feat_dimension2(f, i)
Dimensionality of stream/subvector i in feature output.
#define ckd_realloc(ptr, sz)
Macro for ckd_realloc
SPHINXBASE_EXPORT int32 glist_count(glist_t g)
Count the number of element in a given link list.
file IO related operations.
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.