Ejemplo n.º 1
0
int
ld_utt_proc_raw_impl(live_decoder_t *decoder,
		     int16 *samples,
		     int32 num_samples,
		     int32 begin_utt,
		     int32 end_utt)
{
  float32 dummy_frame[MAX_CEP_LEN];
  float32 **frames = 0;
  int32 num_frames = 0;
  int32 num_features = 0;
	
  num_frames = fe_process_utt(decoder->fe, samples, num_samples, &frames);
	
  if (end_utt) {
    fe_end_utt(decoder->fe, dummy_frame);
  }
	
  if (num_frames > 0) {
    num_features = feat_s2mfc2feat_block(kbcore_fcb(decoder->kbcore),
					 frames,
					 num_frames,
					 begin_utt,
					 end_utt,
					 decoder->features);
  }
	
  if (num_features > 0) {
    utt_decode_block(decoder->features, 
		     num_features, 
		     &decoder->frame_num, 
		     &decoder->kb, 
		     decoder->max_wpf, 
		     decoder->max_histpf, 
		     decoder->max_hmmpf, 
		     decoder->phones_skip, 
		     decoder->hmm_log);
  }
	
  if (frames) {
    ckd_free_2d((void **)frames);
  }
	
  return 0;
}
Ejemplo n.º 2
0
void
ld_process_ceps(live_decoder_t * _decoder,
                float32 ** _cep_frames, int32 _num_frames)
{
    int32 num_features = 0;
    int32 begin_utt = _decoder->num_frames_entered == 0;

    assert(_decoder != NULL);

    if (_num_frames > 0) {
        num_features = feat_s2mfc2feat_block(kbcore_fcb(_decoder->kbcore),
                                             _cep_frames,
                                             _num_frames,
                                             begin_utt,
                                             FALSE, _decoder->features);
        _decoder->num_frames_entered += _num_frames;
    }

    if (num_features > 0) {
        utt_decode_block(_decoder->features,
                         num_features,
                         &_decoder->num_frames_decoded, &_decoder->kb);
    }
}
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);
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
void
ld_process_raw_impl(live_decoder_t * _decoder,
                    int16 * samples, int32 num_samples, int32 end_utt)
{
    float32 dummy_frame[MAX_CEP_LEN];
    float32 **frames = 0;
    int32 num_frames = 0;
    int32 num_features = 0;
    int32 begin_utt = _decoder->num_frames_entered == 0;
    int32 return_value;
    int i;

    assert(_decoder != NULL);

    if (begin_utt) {
        fe_start_utt(_decoder->fe);
    }

    if (_decoder->swap) {
        for (i = 0; i < num_samples; i++) {
            SWAP_INT16(samples + i);
        }
    }

    return_value =
        fe_process_utt(_decoder->fe, samples, num_samples, &frames,
                       &num_frames);

    if (end_utt) {
        return_value = fe_end_utt(_decoder->fe, dummy_frame, &num_frames);
        if (num_frames != 0) {
            /* ARCHAN: If num_frames !=0, assign this last ending frame to
               frames again.  The computation will then be correct.  Should
               clean up the finite state logic in fe_interface layer. 
             */
            frames =
                (float32 **) ckd_calloc_2d(1, _decoder->fe->NUM_CEPSTRA,
                                           sizeof(float32));
            memcpy(frames[0], dummy_frame,
                   _decoder->fe->NUM_CEPSTRA * sizeof(float32));
        }
    }

    if (FE_ZERO_ENERGY_ERROR == return_value) {
        E_WARN("Zero energy frame(s). Consider using dither\n");
    }

    if (num_frames > 0) {
        num_features = feat_s2mfc2feat_block(kbcore_fcb(_decoder->kbcore),
                                             frames,
                                             num_frames,
                                             begin_utt,
                                             end_utt, _decoder->features);
        _decoder->num_frames_entered += num_frames;
    }

    if (num_features > 0) {
        utt_decode_block(_decoder->features,
                         num_features,
                         &_decoder->num_frames_decoded, &_decoder->kb);
    }

    if (frames != NULL) {
        ckd_free_2d((void **) frames);
    }
}