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 int32 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 =
ckd_calloc(n_sv,
sizeof(*fcb->sv_len));
318 fcb->sv_buf =
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;
819 for (i = 1; i < l - 1; i++) {
820 if (mtype[i] ==
',') {
824 else if (mtype[i] ==
':') {
826 fcb->window_size = atoi(mtype + i + 1);
832 fcb->stream_len = (uint32 *)
ckd_calloc(k,
sizeof(uint32));
839 while (sscanf(strp,
"%s%n", wd, &l) == 1) {
841 if ((i >= fcb->n_stream)
842 || (sscanf(wd,
"%d", &(fcb->stream_len[i])) != 1)
843 || (fcb->stream_len[i] <= 0))
844 E_FATAL(
"Bad feature type argument\n");
846 fcb->cepsize += fcb->stream_len[i];
847 if (fcb->window_size > 0)
848 fcb->stream_len[i] *= (fcb->window_size * 2 + 1);
850 fcb->out_dim += fcb->stream_len[i];
853 if (i != fcb->n_stream)
854 E_FATAL(
"Bad feature type argument\n");
855 if (fcb->cepsize != cepsize)
856 E_FATAL(
"Bad feature type argument\n");
859 fcb->compute_feat = feat_copy;
867 fcb->varnorm = varnorm;
868 if (agc != AGC_NONE) {
876 agc_emax_set(fcb->agc_struct, (cmn != CMN_NONE) ? 5.0 : 10.0);
888 sizeof(*fcb->tmpcepbuf));
899 for (i = 0; i < nfr; i++) {
900 fprintf(fp,
"%8d:\n", i);
903 fprintf(fp,
"\t%2d:", j);
906 fprintf(fp,
" %8.4f", MFCC2FLOAT(feat[i][j][k]));
915 feat_cmn(
feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 beginutt, int32 endutt)
919 if (!(beginutt && endutt)
920 && cmn_type != CMN_NONE)
921 cmn_type = CMN_PRIOR;
925 cmn(fcb->cmn_struct, mfc, fcb->varnorm, nfr);
928 cmn_prior(fcb->cmn_struct, mfc, fcb->varnorm, nfr);
935 cep_dump_dbg(fcb, mfc, nfr,
"After CMN");
939 feat_agc(
feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 beginutt, int32 endutt)
943 if (!(beginutt && endutt)
944 && agc_type != AGC_NONE)
949 agc_max(fcb->agc_struct, mfc, nfr);
952 agc_emax(fcb->agc_struct, mfc, nfr);
962 cep_dump_dbg(fcb, mfc, nfr,
"After AGC");
966 feat_compute_utt(
feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 win, mfcc_t ***feat)
970 cep_dump_dbg(fcb, mfc, nfr,
"Incoming features (after padding)");
973 for (i = win; i < nfr - win; i++) {
974 fcb->compute_feat(fcb, mfc + i, feat[i - win]);
977 feat_print_dbg(fcb, feat, nfr - win * 2,
"After dynamic feature computation");
981 feat_print_dbg(fcb, feat, nfr - win * 2,
"After LDA");
985 feat_subvec_project(fcb, feat, nfr - win * 2);
986 feat_print_dbg(fcb, feat, nfr - win * 2,
"After subvector projection");
1004 feat_s2mfc_read_norm_pad(
feat_t *fcb,
char *file, int32 win,
1012 float32 *float_feat;
1013 struct stat statbuf;
1014 int32 i, n, byterev;
1015 int32 start_pad, end_pad;
1022 E_INFO(
"Reading mfc file: '%s'[%d..%d]\n", file, sf, ef);
1023 if (ef >= 0 && ef <= sf) {
1024 E_ERROR(
"%s: End frame (%d) <= Start frame (%d)\n", file, ef, sf);
1030 || ((fp = fopen(file,
"rb")) == NULL)) {
1031 E_ERROR(
"Failed to open file '%s' for reading: %s\n", file, strerror(errno));
1036 if (
fread_retry(&n_float32,
sizeof(int32), 1, fp) != 1) {
1037 E_ERROR(
"%s: fread(#floats) failed\n", file);
1044 if ((int32) (n_float32 *
sizeof(float32) + 4) != (int32) statbuf.st_size) {
1048 if ((int32) (n *
sizeof(float32) + 4) != (int32) (statbuf.st_size)) {
1050 (
"%s: Header size field: %d(%08x); filesize: %d(%08x)\n",
1051 file, n_float32, n_float32, statbuf.st_size,
1060 if (n_float32 <= 0) {
1061 E_ERROR(
"%s: Header size field (#floats) = %d\n", file, n_float32);
1067 n = n_float32 / cepsize;
1068 if (n * cepsize != n_float32) {
1069 E_ERROR(
"Header size field: %d; not multiple of %d\n", n_float32,
1078 E_ERROR(
"%s: Start frame (%d) beyond file size (%d)\n", file,
1087 E_WARN(
"%s: End frame (%d) beyond file size (%d), will truncate\n",
1102 end_pad = ef - n + 1;
1109 if ((ef - sf + 1) < n)
1111 if (maxfr > 0 && n + start_pad + end_pad > maxfr) {
1112 E_ERROR(
"%s: Maximum output size(%d frames) < actual #frames(%d)\n",
1113 file, maxfr, n + start_pad + end_pad);
1119 if (out_mfc != NULL) {
1121 mfc = (mfcc_t **)
ckd_calloc_2d(n + start_pad + end_pad, cepsize,
sizeof(mfcc_t));
1123 fseek(fp, sf * cepsize *
sizeof(float32), SEEK_CUR);
1124 n_float32 = n * cepsize;
1126 float_feat =
ckd_calloc(n_float32,
sizeof(float32));
1128 float_feat = mfc[start_pad];
1130 if (
fread_retry(float_feat,
sizeof(float32), n_float32, fp) != n_float32) {
1131 E_ERROR(
"%s: fread(%dx%d) (MFC data) failed\n", file, n, cepsize);
1137 for (i = 0; i < n_float32; i++) {
1138 SWAP_FLOAT32(&float_feat[i]);
1142 for (i = 0; i < n_float32; ++i) {
1143 mfc[start_pad][i] = FLOAT2MFCC(float_feat[i]);
1149 feat_cmn(fcb, mfc + start_pad, n, 1, 1);
1150 feat_agc(fcb, mfc + start_pad, n, 1, 1);
1153 for (i = 0; i < start_pad; ++i)
1154 memcpy(mfc[i], mfc[start_pad], cepsize *
sizeof(mfcc_t));
1155 for (i = 0; i < end_pad; ++i)
1156 memcpy(mfc[start_pad + n + i], mfc[start_pad + n - 1],
1157 cepsize *
sizeof(mfcc_t));
1163 return n + start_pad + end_pad;
1170 int32 sf, int32 ef, mfcc_t *** feat, int32 maxfr)
1175 int32 file_length, cepext_length, path_length = 0;
1178 if (fcb->cepsize <= 0) {
1179 E_ERROR(
"Bad cepsize: %d\n", fcb->cepsize);
1202 E_INFO(
"At directory . (current directory)\n");
1205 E_INFO(
"At directory %s\n", dir);
1209 path_length += strlen(dir) + 1;
1215 file_length = strlen(file);
1216 cepext_length = strlen(cepext);
1217 if ((file_length > cepext_length)
1218 && (strcmp(file + file_length - cepext_length, cepext) == 0)) {
1226 path_length += file_length + cepext_length + 1;
1227 path = (
char*)
ckd_calloc(path_length,
sizeof(
char));
1229 #ifdef HAVE_SNPRINTF
1233 while ((file_length = snprintf(path, path_length,
"%s%s%s%s", dir, ps, file, cepext)) > path_length) {
1234 path_length = file_length;
1235 path = (
char*)
ckd_realloc(path, path_length *
sizeof(
char));
1238 sprintf(path,
"%s%s%s%s", dir, ps, file, cepext);
1249 nfr = feat_s2mfc_read_norm_pad(fcb, path, win, sf, ef, &mfc, maxfr, fcb->cepsize);
1257 feat_compute_utt(fcb, mfc, nfr, win, feat);
1263 nfr = feat_s2mfc_read_norm_pad(fcb, path, win, sf, ef, NULL, maxfr, fcb->cepsize);
1270 return (nfr - win * 2);
1274 feat_s2mfc2feat_block_utt(
feat_t * fcb, mfcc_t ** uttcep,
1275 int32 nfr, mfcc_t *** ofeat)
1278 int32 i, win, cepsize;
1286 cepbuf =
ckd_calloc(nfr + win * 2,
sizeof(mfcc_t *));
1287 memcpy(cepbuf + win, uttcep, nfr *
sizeof(mfcc_t *));
1290 feat_cmn(fcb, cepbuf + win, nfr, 1, 1);
1291 feat_agc(fcb, cepbuf + win, nfr, 1, 1);
1294 for (i = 0; i < win; ++i) {
1295 cepbuf[i] = fcb->cepbuf[i];
1296 memcpy(cepbuf[i], uttcep[0], cepsize *
sizeof(mfcc_t));
1297 cepbuf[nfr + win + i] = fcb->cepbuf[win + i];
1298 memcpy(cepbuf[nfr + win + i], uttcep[nfr - 1], cepsize *
sizeof(mfcc_t));
1301 feat_compute_utt(fcb, cepbuf, nfr + win * 2, win, ofeat);
1308 int32 beginutt, int32 endutt, mfcc_t *** ofeat)
1310 int32 win, cepsize, nbufcep;
1311 int32 i, j, nfeatvec;
1315 if (inout_ncep == NULL) inout_ncep = &zero;
1318 if (beginutt && endutt && *inout_ncep > 0)
1319 return feat_s2mfc2feat_block_utt(fcb, uttcep, *inout_ncep, ofeat);
1326 fcb->bufpos = fcb->curpos;
1329 nbufcep = fcb->bufpos - fcb->curpos;
1331 nbufcep = fcb->bufpos + LIVEBUFBLOCKSIZE - fcb->curpos;
1333 if (beginutt && *inout_ncep > 0)
1339 if (nbufcep + *inout_ncep > LIVEBUFBLOCKSIZE) {
1342 *inout_ncep = LIVEBUFBLOCKSIZE - nbufcep - win;
1348 feat_cmn(fcb, uttcep, *inout_ncep, beginutt, endutt);
1349 feat_agc(fcb, uttcep, *inout_ncep, beginutt, endutt);
1354 if (beginutt && *inout_ncep > 0) {
1355 for (i = 0; i < win; i++) {
1356 memcpy(fcb->cepbuf[fcb->bufpos++], uttcep[0],
1357 cepsize *
sizeof(mfcc_t));
1358 fcb->bufpos %= LIVEBUFBLOCKSIZE;
1361 fcb->curpos = fcb->bufpos;
1366 for (i = 0; i < *inout_ncep; ++i) {
1367 memcpy(fcb->cepbuf[fcb->bufpos++], uttcep[i],
1368 cepsize *
sizeof(mfcc_t));
1369 fcb->bufpos %= LIVEBUFBLOCKSIZE;
1378 if (fcb->bufpos == 0)
1379 tpos = LIVEBUFBLOCKSIZE - 1;
1381 tpos = fcb->bufpos - 1;
1382 for (i = 0; i < win; ++i) {
1383 memcpy(fcb->cepbuf[fcb->bufpos++], fcb->cepbuf[tpos],
1384 cepsize *
sizeof(mfcc_t));
1385 fcb->bufpos %= LIVEBUFBLOCKSIZE;
1390 nfeatvec = nbufcep - win;
1394 for (i = 0; i < nfeatvec; ++i) {
1396 if (fcb->curpos - win < 0 || fcb->curpos + win >= LIVEBUFBLOCKSIZE) {
1398 for (j = -win; j <= win; ++j) {
1400 (fcb->curpos + j + LIVEBUFBLOCKSIZE) % LIVEBUFBLOCKSIZE;
1401 fcb->tmpcepbuf[win + j] = fcb->cepbuf[tmppos];
1403 fcb->compute_feat(fcb, fcb->tmpcepbuf + win, ofeat[i]);
1406 fcb->compute_feat(fcb, fcb->cepbuf + fcb->curpos, ofeat[i]);
1410 fcb->curpos %= LIVEBUFBLOCKSIZE;
1417 feat_subvec_project(fcb, ofeat, nfeatvec);
1434 if (--f->refcount > 0)
1452 cmn_free(f->cmn_struct);
1464 E_INFO_NOFN(
"Initialization of feat_t, report:\n");
1467 E_INFO_NOFN(
"Number of streams = %d\n", f->n_stream);
1468 for (i = 0; i < f->n_stream; i++) {
1472 E_INFO_NOFN(
"Number of subvectors = %d\n", f->n_sv);
1473 for (i = 0; i < f->n_sv; i++) {
1477 for (sv = f->subvecs[i]; sv && *sv != -1; ++sv)
1481 E_INFO_NOFN(
"Whether CMN is used = %d\n", f->cmn);
1482 E_INFO_NOFN(
"Whether AGC is used = %d\n", f->agc);
1483 E_INFO_NOFN(
"Whether variance is normalized = %d\n", f->varnorm);
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.
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.
SPHINXBASE_EXPORT mfcc_t *** feat_array_alloc(feat_t *fcb, int32 nfr)
Allocate an array to hold several frames worth of feature vectors.
#define E_INFO
Print logging information to standard error stream.
#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 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...
#define E_WARN
Print warning information to standard error stream.
SPHINXBASE_EXPORT void cmn(cmn_t *cmn, mfcc_t **mfc, int32 varnorm, int32 n_frame)
CMN for the whole sentence.
#define E_INFO_NOFN
Print logging information without filename.
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.
#define E_INFOCONT
Print logging information without header, to standard error stream.
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.
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.
#define E_FATAL
Exit with non-zero status after error message.
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_ERROR
Print error message to standard error stream.
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 agc_emax(agc_t *agc, mfcc_t **mfc, int32 n_frame)
Apply AGC to the given block of MFC vectors.
SPHINXBASE_EXPORT void cmn_prior_update(cmn_t *cmn)
Update prior mean based on observed data.
#define feat_dimension1(f)
Number of streams or subvectors in feature output.
SPHINXBASE_EXPORT void cmn_prior(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
CMN for one block of data, using prior mean.
SPHINXBASE_EXPORT int feat_free(feat_t *f)
Release resource associated with feat_t.
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.