int32 live_utt_decode_block (int16 *samples, int32 nsamples, int32 live_endutt, partialhyp_t **ohyp) { static int32 live_begin_new_utt = 1; static int32 frmno; float32 **live_feat; int32 live_nfr, live_nfeatvec; int32 nwds; /* int32 id; */ /* unreferenced variable */ /* glist_t hyp; */ /* unreferenced variable */ /* gnode_t *gn; */ /* unreferenced variable */ /* hyp_t *h; */ /* unreferenced variable */ /* dict_t *dict; */ /* unreferenced variable */ float32 **mfcbuf; if (live_begin_new_utt){ fe_start_utt(fe); utt_begin (kb); frmno = 0; kb->nfr = 0; kb->utt_hmm_eval = 0; kb->utt_sen_eval = 0; kb->utt_gau_eval = 0; live_begin_new_utt = 0; } sample_blk++; /* 10.jan.01 RAH, fe_process_utt now requires ***mfcbuf and it allocates the memory internally) */ mfcbuf = NULL; live_nfr = fe_process_utt(fe, samples, nsamples, &mfcbuf); /* */ if (live_endutt) /* RAH, It seems that we shouldn't throw out this data */ fe_end_utt(fe,dummyframe); /* Flush out the fe */ /* Compute feature vectors */ live_nfeatvec = feat_s2mfc2feat_block(kbcore_fcb(kbcore), mfcbuf, live_nfr, live_begin_new_utt, live_endutt, &live_feat); E_INFO ("live_nfeatvec: %ld\n",live_nfeatvec); /* decode the block */ if (sample_blk<=START_BLOCK) single_utt_decode_block (live_feat, live_nfeatvec, &frmno, kb, maxwpf, maxhistpf, maxhmmpf, ptranskip, hmmdumpfp); else utt_decode_block (live_feat, live_nfeatvec, &frmno, kb, maxwpf, maxhistpf, maxhmmpf, ptranskip, hmmdumpfp); /* Pull out partial hypothesis */ nwds = live_get_partialhyp(live_endutt); *ohyp = parthyp; /* Clean up */ if (live_endutt) { live_begin_new_utt = 1; kb->tot_fr += kb->nfr; utt_end(kb); } else { live_begin_new_utt = 0; } /* I'm starting to think that fe_process_utt should not be allocating its memory, that or it should allocate some max and just keep on going, this idea of constantly allocating freeing memory seems dangerous to me.*/ ckd_free_2d((void **) mfcbuf); /* RAH, this must be freed since fe_process_utt allocates it */ return(nwds); }
int32 live_utt_decode_block (int16 *samples, int32 nsamples, int32 live_endutt, partialhyp_t **ohyp) { static int32 live_begin_new_utt = 1; static int32 frmno; static float32 ***live_feat = NULL; int32 live_nfr, live_nfeatvec; int32 nwds =0; float32 **mfcbuf; /* int i,j;*/ /* 2004/08/27 L Galescu <*****@*****.**> -- added raw audio file saving */ static char uttfn[1024]; static FILE *rawfp = NULL; int16 block_peak_amplitude; if(live_feat==NULL) live_feat = feat_array_alloc (kbcore_fcb(kbcore), LIVEBUFBLOCKSIZE); if (live_begin_new_utt){ fe_start_utt(fe); utt_begin (kb); frmno = 0; kb->nfr = 0; kb->utt_hmm_eval = 0; kb->utt_sen_eval = 0; kb->utt_gau_eval = 0; live_begin_new_utt = 0; sprintf(uttfn, "%s/%s.raw", cmd_ln_str("-outrawdir"), kb->uttid); rawfp = fopen(uttfn, "wb"); } /* 10.jan.01 RAH, fe_process_utt now requires ***mfcbuf and it allocates the memory internally) */ mfcbuf = NULL; /* LG 20080613 */ block_peak_amplitude = get_peak_amplitude(samples, nsamples); if (block_peak_amplitude > peak_amplitude) peak_amplitude = block_peak_amplitude; E_INFO("segment peak %d\n",peak_amplitude); live_nfr = fe_process_utt(fe, samples, nsamples, &mfcbuf); /**/ if (rawfp != NULL) { fwrite(samples, sizeof(int16), nsamples, rawfp); if (live_endutt) fclose(rawfp); } if (live_endutt) { /* RAH, It seems that we shouldn't throw out this data */ fe_end_utt(fe,dummyframe); /* Flush out the fe */ } #if 0 E_INFO("Number frame after fe_process_utt %d\n",live_nfr); for(i=0;i<live_nfr;i++){ printf("%d ",i); for(j=0;j<13;j++){ printf("%f ",mfcbuf[i][j]); fflush(stdout); } printf("\n"); fflush(stdout); } #endif /* lgalescu 2004/08/22 -- i am under the impression that * feat_s2mfc2feat_block() needs to be called at the end of utt * even if no frames need processing */ /* lgalescu 2004/10/13 -- rescinded the above */ if(live_nfr>0){ /* Compute feature vectors */ live_nfeatvec = feat_s2mfc2feat_block(kbcore_fcb(kbcore), mfcbuf, live_nfr, live_begin_new_utt, live_endutt, live_feat); #if 0 E_INFO ("live_nfeatvec: %ld\n",live_nfeatvec); #endif #if 0 E_INFO("Current frame number %d, Number of frames %d, Number frame after feat_s2mfcfeat_block %d\n",frmno,live_nfr,live_nfeatvec); for(i=0;i<live_nfeatvec;i++){ printf("%d\n",i); printf("Cep: "); fflush(stdout); for(j=0;j<13;j++){ printf("%f ",live_feat[i][0][j]); fflush(stdout); } printf("\n"); fflush(stdout); printf("Del: "); fflush(stdout); for(j=13;j<26;j++){ printf("%f ",live_feat[i][0][j]); fflush(stdout); } printf("\n"); fflush(stdout); printf("Acc: "); fflush(stdout); for(j=26;j<39;j++){ printf("%f ",live_feat[i][0][j]); fflush(stdout); } printf("\n"); fflush(stdout); } #endif /* decode the block */ utt_decode_block (live_feat, live_nfeatvec, &frmno, kb, maxwpf, maxhistpf, maxhmmpf, ptranskip, hmmdumpfp); /* lgalescu 2004/08/21 * moved the following block out of the previous if(){} because we need * the output even when no feature computation has to be done. */ /* lgalescu 2004/10/13 -- rescinded */ /* Pull out partial hypothesis */ nwds = live_get_partialhyp(live_endutt); *ohyp = parthyp; parthyplen = nwds; } /* Clean up */ if (live_endutt) { live_begin_new_utt = 1; kb->tot_fr += kb->nfr; utt_end(kb); } else { live_begin_new_utt = 0; } /* I'm starting to think that fe_process_utt should not be allocating its * memory, that or it should allocate some max and just keep on going, * this idea of constantly allocating freeing memory seems dangerous to me. */ /* 20040318 ARCHAN : It sounds extremely dangerous to me and I will * eliminate it sometime. */ /* lgalescu: i second that! the memory issue needs to be investigated: after a run on linux, i noticed some 1.6M of memory having "disappeared"! */ if(live_nfr>0){ ckd_free_2d((void **) mfcbuf); /* RAH, this must be freed since fe_process_utt allocates it */ } return(parthyplen); }