int acmod_process_feat(acmod_t *acmod, mfcc_t **feat) { int i, inptr; if (acmod->n_feat_frame == acmod->n_feat_alloc) { if (acmod->grow_feat) acmod_grow_feat_buf(acmod, acmod->n_feat_alloc * 2); else return 0; } if (acmod->grow_feat) { /* Grow to avoid wraparound if grow_feat == TRUE. */ inptr = acmod->feat_outidx + acmod->n_feat_frame; while (inptr + 1 >= acmod->n_feat_alloc) acmod_grow_feat_buf(acmod, acmod->n_feat_alloc * 2); } else { inptr = (acmod->feat_outidx + acmod->n_feat_frame) % acmod->n_feat_alloc; } for (i = 0; i < feat_dimension1(acmod->fcb); ++i) memcpy(acmod->feat_buf[inptr][i], feat[i], feat_dimension2(acmod->fcb, i) * sizeof(**feat)); ++acmod->n_feat_frame; assert(acmod->n_feat_frame <= acmod->n_feat_alloc); return 1; }
void feat_print(feat_t * fcb, mfcc_t *** feat, int32 nfr, FILE * fp) { uint32 i, j, k; for (i = 0; i < nfr; i++) { fprintf(fp, "%8d:\n", i); for (j = 0; j < feat_dimension1(fcb); j++) { fprintf(fp, "\t%2d:", j); for (k = 0; k < feat_dimension2(fcb, j); k++) fprintf(fp, " %8.4f", MFCC2FLOAT(feat[i][j][k])); fprintf(fp, "\n"); } } fflush(fp); }
void feat_print(feat_t * fcb, mfcc_t *** feat, int32 nfr, FILE * fp) { int32 i, j, k; for (i = 0; i < nfr; i++) { #ifndef POCKETSPHINX_NET fprintf(fp, "%8d:\n", i); #else net_fprintf(fp, "{0:8}:\n", i); #endif for (j = 0; j < feat_dimension1(fcb); j++) { #ifndef POCKETSPHINX_NET fprintf(fp, "\t%2d:", j); #else net_fprintf(fp, "\t{0:2}:\n", j); #endif for (k = 0; k < (int32)feat_dimension2(fcb, j); k++) { #ifndef POCKETSPHINX_NET fprintf(fp, " %8.4f", MFCC2FLOAT(feat[i][j][k])); #else //need check net_fprintf(fp, " {0:8.4}", MFCC2FLOAT(feat[i][j][k])); #endif } #ifndef POCKETSPHINX_NET fprintf(fp, "\n"); #else net_fprintf(fp, "\n"); #endif } } fflush(fp); }
ps_mgau_t * ms_mgau_init(acmod_t *acmod, logmath_t *lmath, bin_mdef_t *mdef) { /* Codebooks */ ms_mgau_model_t *msg; ps_mgau_t *mg; gauden_t *g; senone_t *s; cmd_ln_t *config; int i; static ps_mgaufuncs_t ms_mgau_funcs = { "ms", ms_cont_mgau_frame_eval, /* frame_eval */ ms_mgau_mllr_transform, /* transform */ ms_mgau_free /* free */ }; config = acmod->config; msg = (ms_mgau_model_t *) ckd_calloc(1, sizeof(ms_mgau_model_t)); msg->config = config; msg->g = 0; msg->s = 0; g = msg->g = gauden_init(cmd_ln_str_r(config, "-mean"), cmd_ln_str_r(config, "-var"), cmd_ln_float32_r(config, "-varfloor"), lmath); /* Verify n_feat and veclen, against acmod. */ if (g->n_feat != feat_dimension1(acmod->fcb)) { E_ERROR("Number of streams does not match: %d != %d\n", g->n_feat, feat_dimension1(acmod->fcb)); goto error_out; } for (i = 0; i < g->n_feat; ++i) { if (g->featlen[i] != feat_dimension2(acmod->fcb, i)) { E_ERROR("Dimension of stream %d does not match: %d != %d\n", i, g->featlen[i], feat_dimension2(acmod->fcb, i)); goto error_out; } } s = msg->s = senone_init(msg->g, cmd_ln_str_r(config, "-mixw"), cmd_ln_str_r(config, "-senmgau"), cmd_ln_float32_r(config, "-mixwfloor"), lmath, mdef); s->aw = cmd_ln_int32_r(config, "-aw"); /* Verify senone parameters against gauden parameters */ if (s->n_feat != g->n_feat) E_FATAL("#Feature mismatch: gauden= %d, senone= %d\n", g->n_feat, s->n_feat); if (s->n_cw != g->n_density) E_FATAL("#Densities mismatch: gauden= %d, senone= %d\n", g->n_density, s->n_cw); if ((int)s->n_gauden > g->n_mgau) E_FATAL("Senones need more codebooks (%d) than present (%d)\n", s->n_gauden, g->n_mgau); if ((int)s->n_gauden < g->n_mgau) E_ERROR("Senones use fewer codebooks (%d) than present (%d)\n", s->n_gauden, g->n_mgau); msg->topn = cmd_ln_int32_r(config, "-topn"); E_INFO("The value of topn: %d\n", msg->topn); if (msg->topn == 0 || msg->topn > msg->g->n_density) { E_WARN ("-topn argument (%d) invalid or > #density codewords (%d); set to latter\n", msg->topn, msg->g->n_density); msg->topn = msg->g->n_density; } msg->dist = (gauden_dist_t ***) ckd_calloc_3d(g->n_mgau, g->n_feat, msg->topn, sizeof(gauden_dist_t)); msg->mgau_active = (uint8*)ckd_calloc(g->n_mgau, sizeof(int8)); mg = (ps_mgau_t *)msg; mg->vt = &ms_mgau_funcs; return mg; error_out: ms_mgau_free(ps_mgau_base(msg)); return 0; }
s2_semi_mgau_t * s2_semi_mgau_init(cmd_ln_t *config, logmath_t *lmath, feat_t *fcb, mdef_t *mdef) { s2_semi_mgau_t *s; char const *sendump_path; float32 **fgau; int i; s = ckd_calloc(1, sizeof(*s)); s->config = config; s->lmath = logmath_retain(lmath); /* Log-add table. */ s->lmath_8b = logmath_init(logmath_get_base(lmath), SENSCR_SHIFT, TRUE); if (s->lmath_8b == NULL) { s2_semi_mgau_free(s); return NULL; } /* Ensure that it is only 8 bits wide so that fast_logmath_add() works. */ if (logmath_get_width(s->lmath_8b) != 1) { E_ERROR("Log base %f is too small to represent add table in 8 bits\n", logmath_get_base(s->lmath_8b)); s2_semi_mgau_free(s); return NULL; } /* Inherit stream dimensions from acmod, will be checked below. */ s->n_feat = feat_dimension1(fcb); s->veclen = ckd_calloc(s->n_feat, sizeof(int32)); for (i = 0; i < s->n_feat; ++i) s->veclen[i] = feat_dimension2(fcb, i); /* Read means and variances. */ if (s3_read_mgau(s, cmd_ln_str_r(s->config, "-mean"), &fgau) < 0) { s2_semi_mgau_free(s); return NULL; } s->means = (mfcc_t **)fgau; if (s3_read_mgau(s, cmd_ln_str_r(s->config, "-var"), &fgau) < 0) { s2_semi_mgau_free(s); return NULL; } s->vars = (mfcc_t **)fgau; /* Precompute (and fixed-point-ize) means, variances, and determinants. */ s->dets = (mfcc_t **)ckd_calloc_2d(s->n_feat, s->n_density, sizeof(**s->dets)); s3_precomp(s, s->lmath, cmd_ln_float32_r(s->config, "-varfloor")); /* Read mixture weights */ if ((sendump_path = cmd_ln_str_r(s->config, "-sendump"))) read_sendump(s, mdef, sendump_path); else read_mixw(s, cmd_ln_str_r(s->config, "-mixw"), cmd_ln_float32_r(s->config, "-mixwfloor")); s->ds_ratio = cmd_ln_int32_r(s->config, "-ds"); /* Determine top-N for each feature */ s->topn_beam = ckd_calloc(s->n_feat, sizeof(*s->topn_beam)); s->max_topn = cmd_ln_int32_r(s->config, "-topn"); split_topn(cmd_ln_str_r(s->config, "-topn_beam"), s->topn_beam, s->n_feat); E_INFO("Maximum top-N: %d ", s->max_topn); E_INFOCONT("Top-N beams:"); for (i = 0; i < s->n_feat; ++i) { E_INFOCONT(" %d", s->topn_beam[i]); } E_INFOCONT("\n"); /* Top-N scores from recent frames */ s->n_topn_hist = cmd_ln_int32_r(s->config, "-pl_window") + 2; s->topn_hist = (vqFeature_t ***) ckd_calloc_3d(s->n_topn_hist, s->n_feat, s->max_topn, sizeof(***s->topn_hist)); s->topn_hist_n = ckd_calloc_2d(s->n_topn_hist, s->n_feat, sizeof(**s->topn_hist_n)); for (i = 0; i < s->n_topn_hist; ++i) { int j; for (j = 0; j < s->n_feat; ++j) { int k; for (k = 0; k < s->max_topn; ++k) { s->topn_hist[i][j][k].score = WORST_DIST; s->topn_hist[i][j][k].codeword = k; } } } return s; }