⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fe_sigproc.c

📁 CMU大名鼎鼎的SPHINX-3大词汇量连续语音识别系统
💻 C
📖 第 1 页 / 共 2 页
字号:
    for (whichfilt = 0; whichfilt<FE->MEL_FB->num_filters; whichfilt++){	start = (int32)(FE->MEL_FB->left_apex[whichfilt]/dfreq) + 1;	mfspec[whichfilt] = 0;	for (i=0; i< FE->MEL_FB->width[whichfilt]; i++)	    mfspec[whichfilt] +=		FE->MEL_FB->filter_coeffs[whichfilt][i]*spec[start+i];	    }    }int32 fe_mel_cep(fe_t *FE, float64 *mfspec, float64 *mfcep){    int32 i,j;    int32 period;    float32 beta;    int32 returnValue = FE_SUCCESS;    period = FE->MEL_FB->num_filters;    for (i=0;i<FE->MEL_FB->num_filters; ++i)    {	if (mfspec[i]>0)	    mfspec[i] = log(mfspec[i]);	else {	    mfspec[i] = -1.0e+5;	    returnValue = FE_ZERO_ENERGY_ERROR;	}    }        for (i=0; i< FE->NUM_CEPSTRA; ++i){	mfcep[i] = 0;	for (j=0;j<FE->MEL_FB->num_filters; j++){	    if (j==0)		beta = 0.5;	    else		beta = 1.0;	    mfcep[i] += beta*mfspec[j]*FE->MEL_FB->mel_cosine[i][j];	}		mfcep[i] /= (float32)period;    }    return returnValue;}int32 fe_fft(complex const *in, complex *out, int32 N, int32 invert){  complex    *w, *from, *to,		/* as above				*/    wwf2,			/* temporary for ww*f2			*/    *buffer,			/* from and to flipflop btw out and buffer */    *exch,			/* temporary for exchanging from and to	*/    *wEnd;			/* to keep ww from going off end	*/  float64    div,			/* amount to divide result by: N or 1	*/    x;				/* misc.				*/  int32    s, k,			/* as above				*/    lgN;			/* log2(N)				*/  complex    *f1, *f2,			/* pointers into from array		*/    *t1, *t2,			/* pointers into to array		*/    *ww;			/* pointer into w array			*/    /* check N, compute lgN						*/  for (k = N, lgN = 0; k > 1; k /= 2, lgN++)  {    if (k%2 != 0 || N < 0)    {      fprintf(stderr, "fft: N must be a power of 2 (is %d)\n", N);      return(-1);    }  }  /* check invert, compute div						*/  if (invert == 1)    div = 1.0;  else if (invert == -1)    div = N;  else  {    fprintf(stderr, "fft: invert must be either +1 or -1 (is %d)\n", invert);    return(-1);  }  /* get the to, from buffers right, and init				*/  buffer = (complex *)calloc(N, sizeof(complex));  if (lgN%2 == 0)  {    from = out;    to = buffer;  }  else  {    to = out;    from = buffer;  }    for (s = 0; s<N; s++)  {      from[s].r = in[s].r/div;      from[s].i = in[s].i/div;  }  /* w = exp(-2*PI*i/N), w[k] = w^k					*/  w = (complex *) calloc(N/2, sizeof(complex));  for (k = 0; k < N/2; k++)  {    x = -6.28318530717958647*invert*k/N;    w[k].r = cos(x);    w[k].i = sin(x);  }  wEnd = &w[N/2];    /* go for it!								*/  for (k = N/2; k > 0; k /= 2)  {    for (s = 0; s < k; s++)    {      /* initialize pointers						*/      f1 = &from[s]; f2 = &from[s+k];      t1 = &to[s]; t2 = &to[s+N/2];      ww = &w[0];      /* compute <s,k>							*/      while (ww < wEnd)      {        /* wwf2 = ww*f2							*/        wwf2.r = f2->r*ww->r - f2->i*ww->i;        wwf2.i = f2->r*ww->i + f2->i*ww->r;        /* t1 = f1+wwf2							*/        t1->r = f1->r + wwf2.r;        t1->i = f1->i + wwf2.i;        /* t2 = f1-wwf2							*/        t2->r = f1->r - wwf2.r;        t2->i = f1->i - wwf2.i;        /* increment							*/        f1 += 2*k; f2 += 2*k;        t1 += k; t2 += k;        ww += k;      }    }    exch = from; from = to; to = exch;  }  free(buffer);  free(w);  return(0);}char **fe_create_2d(int32 d1, int32 d2, int32 elem_size){    char *store;    char **out;    int32 i, j;    store = calloc(d1 * d2, elem_size);    if (store == NULL) {	fprintf(stderr,"fe_create_2d failed\n");	return(NULL);    }        out = calloc(d1, sizeof(void *));    if (out == NULL) {	fprintf(stderr,"fe_create_2d failed\n");	free(store);	return(NULL);    }        for (i = 0, j = 0; i < d1; i++, j += d2) {	out[i] = &((char *)store)[j*elem_size];    }    return out;}void fe_free_2d(void **arr){    if (arr!=NULL){	free(arr[0]);	free(arr);    }    }void fe_parse_general_params(param_t const *P, fe_t *FE){    if (P->SAMPLING_RATE != 0)       FE->SAMPLING_RATE = P->SAMPLING_RATE;    else      FE->SAMPLING_RATE = (float32)atof(DEFAULT_SAMPLING_RATE);    if (P->FRAME_RATE != 0)       FE->FRAME_RATE = P->FRAME_RATE;    else       FE->FRAME_RATE = (int32)atof(DEFAULT_FRAME_RATE);        if (P->WINDOW_LENGTH != 0)       FE->WINDOW_LENGTH = P->WINDOW_LENGTH;    else       FE->WINDOW_LENGTH = (float32)atof(DEFAULT_WINDOW_LENGTH);        if (P->FB_TYPE != 0)       FE->FB_TYPE = P->FB_TYPE;    else       FE->FB_TYPE = DEFAULT_FB_TYPE;     if (P->PRE_EMPHASIS_ALPHA != 0)       FE->PRE_EMPHASIS_ALPHA = P->PRE_EMPHASIS_ALPHA;    else       FE->PRE_EMPHASIS_ALPHA = (float32)atof(DEFAULT_PRE_EMPHASIS_ALPHA);     if (P->NUM_CEPSTRA != 0)       FE->NUM_CEPSTRA = P->NUM_CEPSTRA;    else       FE->NUM_CEPSTRA = atoi(DEFAULT_NUM_CEPSTRA);    if (P->FFT_SIZE != 0)       FE->FFT_SIZE = P->FFT_SIZE;    else       FE->FFT_SIZE = atoi(DEFAULT_FFT_SIZE); }void fe_parse_melfb_params(param_t const *P, melfb_t *MEL){    if (P->SAMPLING_RATE != 0)       MEL->sampling_rate = P->SAMPLING_RATE;    else       MEL->sampling_rate = (float32)atof(DEFAULT_SAMPLING_RATE);    if (P->FFT_SIZE != 0)       MEL->fft_size = P->FFT_SIZE;    else {      if (MEL->sampling_rate == BB_SAMPLING_RATE)	MEL->fft_size = DEFAULT_BB_FFT_SIZE;      if (MEL->sampling_rate == NB_SAMPLING_RATE)	MEL->fft_size = DEFAULT_NB_FFT_SIZE;      else 	MEL->fft_size = atoi(DEFAULT_FFT_SIZE);    }     if (P->NUM_CEPSTRA != 0)       MEL->num_cepstra = P->NUM_CEPSTRA;    else       MEL->num_cepstra = atoi(DEFAULT_NUM_CEPSTRA);     if (P->NUM_FILTERS != 0)		MEL->num_filters = P->NUM_FILTERS;    else {      if (MEL->sampling_rate == BB_SAMPLING_RATE)	MEL->num_filters = DEFAULT_BB_NUM_FILTERS;      else if (MEL->sampling_rate == NB_SAMPLING_RATE)	MEL->num_filters = DEFAULT_NB_NUM_FILTERS;      else {	fprintf(stderr,"Please define the number of MEL filters needed\n");	fprintf(stderr,"Modify include/new_fe.h and new_fe_sp.c\n");	fflush(stderr); exit(0);      }    }    if (P->UPPER_FILT_FREQ != 0)	      MEL->upper_filt_freq = P->UPPER_FILT_FREQ;    else{      if (MEL->sampling_rate == BB_SAMPLING_RATE)	MEL->upper_filt_freq = (float32) DEFAULT_BB_UPPER_FILT_FREQ;      else if (MEL->sampling_rate == NB_SAMPLING_RATE)	MEL->upper_filt_freq = (float32) DEFAULT_NB_UPPER_FILT_FREQ;      else {	fprintf(stderr,"Please define the upper filt frequency needed\n");	fprintf(stderr,"Modify include/new_fe.h and new_fe_sp.c\n");	fflush(stderr); exit(0);      }    }     if (P->LOWER_FILT_FREQ != 0)	      MEL->lower_filt_freq = P->LOWER_FILT_FREQ;    else {      if (MEL->sampling_rate == BB_SAMPLING_RATE)	MEL->lower_filt_freq = (float32) DEFAULT_BB_LOWER_FILT_FREQ;      else if (MEL->sampling_rate == NB_SAMPLING_RATE)	MEL->lower_filt_freq = (float32) DEFAULT_NB_LOWER_FILT_FREQ;      else {	fprintf(stderr,"Please define the lower filt frequency needed\n");	fprintf(stderr,"Modify include/new_fe.h and new_fe_sp.c\n");	fflush(stderr); exit(0);      }    }     if (P->doublebw == ON)	MEL->doublewide = ON;    else	MEL->doublewide = OFF;}void fe_print_current(fe_t *FE){    fprintf(stderr,"Current FE Parameters:\n");    fprintf(stderr,"\tSampling Rate:             %f\n",FE->SAMPLING_RATE);    fprintf(stderr,"\tFrame Size:                %d\n",FE->FRAME_SIZE);    fprintf(stderr,"\tFrame Shift:               %d\n",FE->FRAME_SHIFT);    fprintf(stderr,"\tFFT Size:                  %d\n",FE->FFT_SIZE);    fprintf(stderr,"\tNumber of Overflow Samps:  %d\n",FE->NUM_OVERFLOW_SAMPS);    fprintf(stderr,"\tStart Utt Status:          %d\n",FE->START_FLAG);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -