fe_t *fe_init(param_t *P) { fe_t *FE = (fe_t *) calloc(1,sizeof(fe_t)); if (FE==NULL){ fprintf(stderr,"memory alloc failed in fe_init()\n...exiting\n"); return(NULL); } /* transfer params to front end */ fe_parse_general_params(P,FE); /* compute remaining FE parameters */ FE->FRAME_SHIFT = (int32)(FE->SAMPLING_RATE/FE->FRAME_RATE + 0.5);/* why 0.5? */ FE->FRAME_SIZE = (int32)(FE->WINDOW_LENGTH*FE->SAMPLING_RATE + 0.5); /* why 0.5? */ FE->PRIOR = 0; /* establish buffers for overflow samps and hamming window */ FE->OVERFLOW_SAMPS = (int16 *)calloc(FE->FRAME_SIZE,sizeof(int16)); FE->HAMMING_WINDOW = (double *) calloc(FE->FRAME_SIZE,sizeof(double)); if (FE->OVERFLOW_SAMPS==NULL || FE->HAMMING_WINDOW==NULL){ fprintf(stderr,"memory alloc failed in fe_init()\n...exiting\n"); return(NULL); } /* create hamming window */ fe_create_hamming(FE->HAMMING_WINDOW, FE->FRAME_SIZE); /* init and fill appropriate filter structure */ if (FE->FB_TYPE==MEL_SCALE) { if ((FE->MEL_FB = (melfb_t *) calloc(1,sizeof(melfb_t)))==NULL){ fprintf(stderr,"memory alloc failed in fe_init()\n...exiting\n"); return(NULL); } /* transfer params to mel fb */ fe_parse_melfb_params(P, FE->MEL_FB); fe_build_melfilters(FE->MEL_FB); fe_compute_melcosine(FE->MEL_FB); } else { fprintf(stderr,"MEL SCALE IS CURRENTLY THE ONLY IMPLEMENTATION!\n"); return(NULL); } return(FE); }
fe_t * fe_init_auto_r(cmd_ln_t *config) { fe_t *fe; fe = ckd_calloc(1, sizeof(*fe)); fe->refcount = 1; /* transfer params to front end */ if (fe_parse_general_params(cmd_ln_retain(config), fe) < 0) { fe_free(fe); return NULL; } /* compute remaining fe parameters */ /* We add 0.5 so approximate the float with the closest * integer. E.g., 2.3 is truncate to 2, whereas 3.7 becomes 4 */ fe->frame_shift = (int32) (fe->sampling_rate / fe->frame_rate + 0.5); fe->frame_size = (int32) (fe->window_length * fe->sampling_rate + 0.5); fe->prior = 0; fe->frame_counter = 0; assert (fe->frame_shift > 1); if (fe->frame_size > (fe->fft_size)) { E_WARN ("Number of FFT points has to be a power of 2 higher than %d\n", (fe->frame_size)); fe_free(fe); return (NULL); } if (fe->dither) fe_init_dither(fe->seed); /* establish buffers for overflow samps and hamming window */ fe->overflow_samps = ckd_calloc(fe->frame_size, sizeof(int16)); fe->hamming_window = ckd_calloc(fe->frame_size/2, sizeof(window_t)); /* create hamming window */ fe_create_hamming(fe->hamming_window, fe->frame_size); /* init and fill appropriate filter structure */ fe->mel_fb = ckd_calloc(1, sizeof(*fe->mel_fb)); /* transfer params to mel fb */ fe_parse_melfb_params(config, fe, fe->mel_fb); fe_build_melfilters(fe->mel_fb); fe_compute_melcosine(fe->mel_fb); /* Create temporary FFT, spectrum and mel-spectrum buffers. */ /* FIXME: Gosh there are a lot of these. */ fe->spch = ckd_calloc(fe->frame_size, sizeof(*fe->spch)); fe->frame = ckd_calloc(fe->fft_size, sizeof(*fe->frame)); fe->spec = ckd_calloc(fe->fft_size, sizeof(*fe->spec)); fe->mfspec = ckd_calloc(fe->mel_fb->num_filters, sizeof(*fe->mfspec)); /* create twiddle factors */ fe->ccc = ckd_calloc(fe->fft_size / 4, sizeof(*fe->ccc)); fe->sss = ckd_calloc(fe->fft_size / 4, sizeof(*fe->sss)); fe_create_twiddle(fe); if (cmd_ln_boolean_r(config, "-verbose")) { fe_print_current(fe); } /*** Z.A.B. ***/ /*** Initialize the overflow buffers ***/ fe_start_utt(fe); return fe; }
fe_t * fe_init_auto_r(cmd_ln_t *config) { fe_t *fe; int prespch_frame_len; fe = (fe_t*)ckd_calloc(1, sizeof(*fe)); fe->refcount = 1; /* transfer params to front end */ if (fe_parse_general_params(cmd_ln_retain(config), fe) < 0) { fe_free(fe); return NULL; } /* compute remaining fe parameters */ /* We add 0.5 so approximate the float with the closest * integer. E.g., 2.3 is truncate to 2, whereas 3.7 becomes 4 */ fe->frame_shift = (int32) (fe->sampling_rate / fe->frame_rate + 0.5); fe->frame_size = (int32) (fe->window_length * fe->sampling_rate + 0.5); fe->prior = 0; fe_start_stream(fe); assert (fe->frame_shift > 1); if (fe->frame_size < fe->frame_shift) { E_ERROR ("Frame size %d (-wlen) must be greater than frame shift %d (-frate)\n", fe->frame_size, fe->frame_shift); fe_free(fe); return NULL; } if (fe->frame_size > (fe->fft_size)) { E_ERROR ("Number of FFT points has to be a power of 2 higher than %d, it is %d\n", fe->frame_size, fe->fft_size); fe_free(fe); return NULL; } if (fe->dither) fe_init_dither(fe->seed); /* establish buffers for overflow samps and hamming window */ fe->overflow_samps = ckd_calloc(fe->frame_size, sizeof(int16)); fe->hamming_window = ckd_calloc(fe->frame_size/2, sizeof(window_t)); /* create hamming window */ fe_create_hamming(fe->hamming_window, fe->frame_size); /* init and fill appropriate filter structure */ fe->mel_fb = ckd_calloc(1, sizeof(*fe->mel_fb)); /* transfer params to mel fb */ fe_parse_melfb_params(config, fe, fe->mel_fb); if (fe->mel_fb->upper_filt_freq > fe->sampling_rate / 2 + 1.0) { E_ERROR("Upper frequency %.1f is higher than samprate/2 (%.1f)\n", fe->mel_fb->upper_filt_freq, fe->sampling_rate / 2); fe_free(fe); return NULL; } fe_build_melfilters(fe->mel_fb); fe_compute_melcosine(fe->mel_fb); if (fe->remove_noise || fe->remove_silence) fe->noise_stats = fe_init_noisestats(fe->mel_fb->num_filters); fe->vad_data = (vad_data_t*)ckd_calloc(1, sizeof(*fe->vad_data)); prespch_frame_len = fe->log_spec != RAW_LOG_SPEC ? fe->num_cepstra : fe->mel_fb->num_filters; fe->vad_data->prespch_buf = fe_prespch_init(fe->pre_speech + 1, prespch_frame_len, fe->frame_shift); /* Create temporary FFT, spectrum and mel-spectrum buffers. */ /* FIXME: Gosh there are a lot of these. */ fe->spch = ckd_calloc(fe->frame_size, sizeof(*fe->spch)); fe->frame = ckd_calloc(fe->fft_size, sizeof(*fe->frame)); fe->spec = ckd_calloc(fe->fft_size, sizeof(*fe->spec)); fe->mfspec = ckd_calloc(fe->mel_fb->num_filters, sizeof(*fe->mfspec)); /* create twiddle factors */ fe->ccc = ckd_calloc(fe->fft_size / 4, sizeof(*fe->ccc)); fe->sss = ckd_calloc(fe->fft_size / 4, sizeof(*fe->sss)); fe_create_twiddle(fe); if (cmd_ln_boolean_r(config, "-verbose")) { fe_print_current(fe); } /*** Initialize the overflow buffers ***/ fe_start_utt(fe); return fe; }
fe_t * fe_init(param_t const *P) { fe_t *FE = (fe_t *) calloc(1, sizeof(fe_t)); if (FE == NULL) { E_WARN("memory alloc failed in fe_init()\n"); return (NULL); } /* transfer params to front end */ fe_parse_general_params(P, FE); /* compute remaining FE parameters */ /* We add 0.5 so approximate the float with the closest * integer. E.g., 2.3 is truncate to 2, whereas 3.7 becomes 4 */ FE->FRAME_SHIFT = (int32) (FE->SAMPLING_RATE / FE->FRAME_RATE + 0.5); /* why 0.5? */ FE->FRAME_SIZE = (int32) (FE->WINDOW_LENGTH * FE->SAMPLING_RATE + 0.5); /* why 0.5? */ FE->PRIOR = 0; FE->FRAME_COUNTER = 0; if (FE->FRAME_SIZE > (FE->FFT_SIZE)) { E_WARN ("Number of FFT points has to be a power of 2 higher than %d\n", (FE->FRAME_SIZE)); return (NULL); } if (FE->dither) { fe_init_dither(FE->seed); } /* establish buffers for overflow samps and hamming window */ FE->OVERFLOW_SAMPS = (int16 *) calloc(FE->FRAME_SIZE, sizeof(int16)); FE->HAMMING_WINDOW = (window_t *) calloc(FE->FRAME_SIZE, sizeof(window_t)); if (FE->OVERFLOW_SAMPS == NULL || FE->HAMMING_WINDOW == NULL) { E_WARN("memory alloc failed in fe_init()\n"); return (NULL); } /* create hamming window */ fe_create_hamming(FE->HAMMING_WINDOW, FE->FRAME_SIZE); /* init and fill appropriate filter structure */ if (FE->FB_TYPE == MEL_SCALE) { if ((FE->MEL_FB = (melfb_t *) calloc(1, sizeof(melfb_t))) == NULL) { E_WARN("memory alloc failed in fe_init()\n"); return (NULL); } /* transfer params to mel fb */ fe_parse_melfb_params(P, FE->MEL_FB); fe_build_melfilters(FE->MEL_FB); fe_compute_melcosine(FE->MEL_FB); } else { E_WARN("MEL SCALE IS CURRENTLY THE ONLY IMPLEMENTATION!\n"); return (NULL); } if (P->verbose) { fe_print_current(FE); } /*** Z.A.B. ***/ /*** Initialize the overflow buffers ***/ fe_start_utt(FE); return (FE); }