/* * ---------------------WARN!! VERY IMPORTANT----------------------------------------- this fast autocorr algorithm is faster than the ordinary correlation function WHEN the n is large(maybe > 128) and the order p is close to the length n!! the speed is obviously raise up when this conditions is satisfied. THUS, when you use small length correlation and low order p , I strongly suggested that you use the ordinary method fa_autocorr function to calculate the relation matrix R */ void fa_autocorr_fast(uintptr_t handle, float *x, int n, int p, float *r) { fa_autocorr_fast_t *f = (fa_autocorr_fast_t *)handle; int i; memset(f->fft_buf1, 0, sizeof(float)*f->fft_len*2); for (i = 0; i < n; i++) { f->fft_buf1[2*i] = x[i]; f->fft_buf1[2*i+1] = 0.0; } fa_fft(f->h_fft, f->fft_buf1); memset(f->fft_buf2, 0, sizeof(float)*f->fft_len*2); for (i = 0; i < n; i++) { f->fft_buf2[2*i] = f->fft_buf1[2*i] * f->fft_buf1[2*i] + f->fft_buf1[2*i+1] * f->fft_buf1[2*i+1]; f->fft_buf2[2*i+1] = 0.0; } fa_ifft(f->h_fft, f->fft_buf2); for (i = 0; i <= p; i++) { r[i] = f->fft_buf2[2*i] * 2; /*printf("r_fast[%d]=%f\n", i, r[i]);*/ } }
int hffcoef(double* frameA, int frameSize, float *hffc_cep, int ceporder, int fft_size,int sampleRate, double *filtMig, uintptr_t ffthandle) { int i,j; double temp_cep; //uintptr_t ffthandle; double *sample = (double *) malloc(fft_size*sizeof(double)+100); double *fSample = (float *) malloc(2*fft_size*sizeof(double)+100); memcpy(sample,frameA,frameSize*sizeof(double)); // FFT_DATA_TYPE* a=(FFT_DATA_TYPE*)malloc(fft_size*sizeof(FFT_DATA_TYPE)); // FFT_DATA_TYPE* b=(FFT_DATA_TYPE*)malloc(fft_size*sizeof(FFT_DATA_TYPE)); // int uiLogFFTSize = (int)(log((double)fft_size)/log((double)2)+0.5); Do_hamm_window(&sample[0],frameSize); for(i=0;i<frameSize;i++) { fSample[2*i] = sample[i]; fSample[2*i +1] = 0.0; } for(i=frameSize;i<fft_size;i++) { fSample[2*i] = 0.0; fSample[2*i +1] = 0.0; } //ffthandle = fa_fft_init(fft_size); fa_fft(ffthandle,fSample); //fa_fft_uninit(ffthandle); for(i=0;i<fft_size;i++) { sample[i] = (double)(fSample[2*i] * fSample[2*i]*1.0 + fSample[2*i+1] * fSample[2*i+1]*1.0); } // for(i=0;i<frameSize;i++) // { // a[i] = frameA[i]; // b[i]=0; // } // for(i=frameSize;i<fft_size;i++) // a[i] = b[i] = 0; // FFT_c(&a[0], &b[0], uiLogFFTSize, fft_size, 1); // for(i=0;i<fft_size/2;i++) // { // sample[i] = a[i]*a[i] + b[i]*b[i]; // } for (i=0; i<ceporder; i++) { temp_cep = 0; for(j=0; j<fft_size/2; j++) { temp_cep += (*(filtMig +(int)(i*0.5*fft_size +j)))*(sample[j]); } *(hffc_cep+i) = (float)temp_cep; } // free(a); // free(b); free(sample); free(fSample); return 1; }