static int acmod_process_full_raw(acmod_t *acmod, int16 const **inout_raw, size_t *inout_n_samps) { int32 nfr, ntail; mfcc_t **cepptr; /* Write to logging file if any. */ if (acmod->rawfh) fwrite(*inout_raw, 2, *inout_n_samps, acmod->rawfh); /* Resize mfc_buf to fit. */ if (fe_process_frames(acmod->fe, NULL, inout_n_samps, NULL, &nfr) < 0) return -1; if (acmod->n_mfc_alloc < nfr + 1) { ckd_free_2d(acmod->mfc_buf); acmod->mfc_buf = ckd_calloc_2d(nfr + 1, fe_get_output_size(acmod->fe), sizeof(**acmod->mfc_buf)); acmod->n_mfc_alloc = nfr + 1; } acmod->n_mfc_frame = 0; acmod->mfc_outidx = 0; fe_start_utt(acmod->fe); if (fe_process_frames(acmod->fe, inout_raw, inout_n_samps, acmod->mfc_buf, &nfr) < 0) return -1; fe_end_utt(acmod->fe, acmod->mfc_buf[nfr], &ntail); nfr += ntail; cepptr = acmod->mfc_buf; nfr = acmod_process_full_cep(acmod, &cepptr, &nfr); acmod->n_mfc_frame = 0; return nfr; }
int acmod_process_cep(acmod_t *acmod, mfcc_t ***inout_cep, int *inout_n_frames, int full_utt) { int32 nfeat, ncep, inptr; int orig_n_frames; /* If this is a full utterance, process it all at once. */ if (full_utt) return acmod_process_full_cep(acmod, inout_cep, inout_n_frames); /* Write to log file. */ if (acmod->mfcfh) acmod_log_mfc(acmod, *inout_cep, *inout_n_frames); /* Maximum number of frames we're going to generate. */ orig_n_frames = ncep = nfeat = *inout_n_frames; /* FIXME: This behaviour isn't guaranteed... */ if (acmod->state == ACMOD_ENDED) nfeat += feat_window_size(acmod->fcb); else if (acmod->state == ACMOD_STARTED) nfeat -= feat_window_size(acmod->fcb); /* Clamp number of features to fit available space. */ if (nfeat > acmod->n_feat_alloc - acmod->n_feat_frame) { /* Grow it as needed - we have to grow it at the end of an * utterance because we can't return a short read there. */ if (acmod->grow_feat || acmod->state == ACMOD_ENDED) acmod_grow_feat_buf(acmod, acmod->n_feat_alloc + nfeat); else ncep -= (nfeat - (acmod->n_feat_alloc - acmod->n_feat_frame)); } /* Where to start writing in the feature buffer. */ if (acmod->grow_feat) { /* Grow to avoid wraparound if grow_feat == TRUE. */ inptr = acmod->feat_outidx + acmod->n_feat_frame; while (inptr + nfeat >= 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; } /* FIXME: we can't split the last frame drop properly to be on the bounary, * so just return */ if (inptr + nfeat > acmod->n_feat_alloc && acmod->state == ACMOD_ENDED) { *inout_n_frames -= ncep; *inout_cep += ncep; return 0; } /* Write them in two parts if there is wraparound. */ if (inptr + nfeat > acmod->n_feat_alloc) { int32 ncep1 = acmod->n_feat_alloc - inptr; /* Make sure we don't end the utterance here. */ nfeat = feat_s2mfc2feat_live(acmod->fcb, *inout_cep, &ncep1, (acmod->state == ACMOD_STARTED), FALSE, acmod->feat_buf + inptr); if (nfeat < 0) return -1; /* Move the output feature pointer forward. */ acmod->n_feat_frame += nfeat; assert(acmod->n_feat_frame <= acmod->n_feat_alloc); inptr += nfeat; inptr %= acmod->n_feat_alloc; /* Move the input feature pointers forward. */ *inout_n_frames -= ncep1; *inout_cep += ncep1; ncep -= ncep1; } nfeat = feat_s2mfc2feat_live(acmod->fcb, *inout_cep, &ncep, (acmod->state == ACMOD_STARTED), (acmod->state == ACMOD_ENDED), acmod->feat_buf + inptr); if (nfeat < 0) return -1; acmod->n_feat_frame += nfeat; assert(acmod->n_feat_frame <= acmod->n_feat_alloc); /* Move the input feature pointers forward. */ *inout_n_frames -= ncep; *inout_cep += ncep; if (acmod->state == ACMOD_STARTED) acmod->state = ACMOD_PROCESSING; return orig_n_frames - *inout_n_frames; }