static kiss_fft_cfg find_cached_fft(int nfft,int inverse) { size_t len; kfc_cfg cur=cache_root; kfc_cfg prev=NULL; while ( cur ) { if ( cur->nfft == nfft && inverse == cur->inverse ) break;/*found the right node*/ prev = cur; cur = prev->next; } if (cur== NULL) { /* no cached node found, need to create a new one*/ kiss_fft_alloc(nfft,inverse,0,&len); cur = (kfc_cfg)malloc(sizeof(struct cached_fft) + len ); if (cur == NULL) return NULL; cur->cfg = (kiss_fft_cfg)(cur+1); kiss_fft_alloc(nfft,inverse,cur->cfg,&len); cur->nfft=nfft; cur->inverse=inverse; cur->next = NULL; if ( prev ) prev->next = cur; else cache_root = cur; ++ncached; } return cur->cfg; }
/*------------------------------------------------------------*/ wexfft2d wexfft_init(wexcub3d cub, int n1_, int n2_) /*< initialize OMP fft >*/ { /*------------------------------------------------------------*/ wexfft2d fft; fft = (wexfft2d) sf_alloc(1,sizeof(*fft)); fft->n1 = n1_; fft->n2 = n2_; fft->ctmp1 = (kiss_fft_cpx*) sf_complexalloc(fft->n1); fft->ctmp2 = (kiss_fft_cpx*) sf_complexalloc(fft->n2); fft->forw1 = kiss_fft_alloc(fft->n1,0,NULL,NULL); fft->invs1 = kiss_fft_alloc(fft->n1,1,NULL,NULL); fft->forw2 = kiss_fft_alloc(fft->n2,0,NULL,NULL); fft->invs2 = kiss_fft_alloc(fft->n2,1,NULL,NULL); if (NULL == fft->forw2 || NULL == fft->invs2 || NULL == fft->forw1 || NULL == fft->invs1) sf_error("%s: KISS FFT allocation error",__FILE__); fft->fftscale = 1./sqrtf(fft->n1*fft->n2); return fft; }
void fft_filt_c::pre_run() { if (filter_is_set) { prepare_filter(); if (!fft_ready && filter_is_ready) { if (is_complex) { fft_fcfg_c = kiss_fft_alloc(fft_len,0,0,0); fft_icfg_c = kiss_fft_alloc(fft_len,1,0,0); input_buf_c = new kiss_fft_cpx[fft_len]; fdom_buf = new kiss_fft_cpx[fft_len]; fdom_conv_buf = new kiss_fft_cpx[fft_len]; output_buf_c = new kiss_fft_cpx[fft_len]; last_output_buf_c = new kiss_fft_cpx[fft_len-l]; memset(last_output_buf_c,0,sizeof(kiss_fft_cpx)*(fft_len-l)); } else { fft_fcfg_r = kiss_fftr_alloc(fft_len,0,0,0); fft_icfg_r = kiss_fftr_alloc(fft_len,1,0,0); input_buf_r = new kiss_fft_scalar[fft_len]; fdom_buf = new kiss_fft_cpx[fft_len/2+1]; fdom_conv_buf = new kiss_fft_cpx[fft_len/2+1]; output_buf_r = new kiss_fft_scalar[fft_len]; last_output_buf_r = new kiss_fft_scalar[fft_len-l]; memset(last_output_buf_r,0,sizeof(kiss_fft_scalar)*(fft_len-l)); } fft_ready = true; } } };
/*------------------------------------------------------------*/ ompfft3d sf_ompfft3a3_init(int n1_, int n2_, int n3_, int ompnth_) /*< initialize FFT on axis 3 >*/ { int ompith; ompfft3d fft; fft = (ompfft3d) sf_alloc(1,sizeof(*fft)); fft->n1 = n1_; fft->n2 = n2_; fft->n3 = n3_; fft->ompnth=ompnth_; fft->forw = (kiss_fft_cfg*) sf_alloc(fft->ompnth,sizeof(kiss_fft_cfg)); fft->invs = (kiss_fft_cfg*) sf_alloc(fft->ompnth,sizeof(kiss_fft_cfg)); for(ompith=0; ompith<fft->ompnth; ompith++) { fft->forw[ompith] = kiss_fft_alloc(fft->n3,0,NULL,NULL); fft->invs[ompith] = kiss_fft_alloc(fft->n3,1,NULL,NULL); if (NULL == fft->forw[ompith] || NULL == fft->invs[ompith]) sf_error("%s: KISS FFT allocation error",__FILE__); fft->trace = (kiss_fft_cpx**) sf_complexalloc2(fft->n3,fft->ompnth); } fft->scale = 1./sqrtf(fft->n3); return fft; }
/* C to C */ void Tracter::Fourier::Init( int iOrder, complex** ioIData, complex** ioOData, bool iInverse ) { assert(ioIData); assert(ioOData); assert(iOrder > 0); assert(sizeof(complex) == sizeof(kiss_fft_cpx)); FourierKiss::sInstanceCount++; assert(mFourierData == 0); mFourierData = new FourierData; FourierData& m = *mFourierData; m.Type = COMPLEX_TO_COMPLEX; Allocate<kiss_fft_cpx, complex>(iOrder, ioIData, &m.IData, &m.MyIData); Allocate<kiss_fft_cpx, complex>(iOrder, ioOData, &m.OData, &m.MyOData); m.TmpData = 0; if (iInverse) m.Config = kiss_fft_alloc(iOrder, 1, 0, 0); else m.Config = kiss_fft_alloc(iOrder, 0, 0, 0); }
struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode) { struct CODEC2 *c2; int i,l; c2 = (struct CODEC2*)malloc(sizeof(struct CODEC2)); if (c2 == NULL) return NULL; assert( (mode == CODEC2_MODE_3200) || (mode == CODEC2_MODE_2400) || (mode == CODEC2_MODE_1600) || (mode == CODEC2_MODE_1400) || (mode == CODEC2_MODE_1300) || (mode == CODEC2_MODE_1200) ); c2->mode = mode; for(i=0; i<M; i++) c2->Sn[i] = 1.0; c2->hpf_states[0] = c2->hpf_states[1] = 0.0; for(i=0; i<2*N; i++) c2->Sn_[i] = 0; c2->fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); make_analysis_window(c2->fft_fwd_cfg, c2->w,c2->W); make_synthesis_window(c2->Pn); c2->fft_inv_cfg = kiss_fft_alloc(FFT_DEC, 1, NULL, NULL); quantise_init(); c2->prev_Wo_enc = 0.0; c2->bg_est = 0.0; c2->ex_phase = 0.0; for(l=1; l<=MAX_AMP; l++) c2->prev_model_dec.A[l] = 0.0; c2->prev_model_dec.Wo = TWO_PI/P_MAX; c2->prev_model_dec.L = PI/c2->prev_model_dec.Wo; c2->prev_model_dec.voiced = 0; for(i=0; i<LPC_ORD; i++) { c2->prev_lsps_dec[i] = i*PI/(LPC_ORD+1); } c2->prev_e_dec = 1; c2->nlp = nlp_create(M); if (c2->nlp == NULL) { free (c2); return NULL; } c2->gray = 1; c2->lpc_pf = 1; c2->bass_boost = 1; c2->beta = LPCPF_BETA; c2->gamma = LPCPF_GAMMA; c2->xq_enc[0] = c2->xq_enc[1] = 0.0; c2->xq_dec[0] = c2->xq_dec[1] = 0.0; c2->smoothing = 0; return c2; }
int fft2_init(bool cmplx1 /* if complex transform */, int pad1 /* padding on the first axis */, int nx, int ny /* input data size */, int *nx2, int *ny2 /* padded data size */) /*< initialize >*/ { #ifndef SF_HAS_FFTW int i2; #endif cmplx = cmplx1; if (cmplx) { nk = n1 = kiss_fft_next_fast_size(nx*pad1); #ifndef SF_HAS_FFTW cfg1 = kiss_fft_alloc(n1,0,NULL,NULL); icfg1 = kiss_fft_alloc(n1,1,NULL,NULL); #endif } else { nk = kiss_fft_next_fast_size(pad1*(nx+1)/2)+1; n1 = 2*(nk-1); #ifndef SF_HAS_FFTW cfg = kiss_fftr_alloc(n1,0,NULL,NULL); icfg = kiss_fftr_alloc(n1,1,NULL,NULL); #endif } n2 = kiss_fft_next_fast_size(ny); if (cmplx) { cc = sf_complexalloc2(n1,n2); } else { ff = sf_floatalloc2(n1,n2); } #ifndef SF_HAS_FFTW cfg2 = kiss_fft_alloc(n2,0,NULL,NULL); icfg2 = kiss_fft_alloc(n2,1,NULL,NULL); tmp = (kiss_fft_cpx **) sf_alloc(n2,sizeof(*tmp)); tmp[0] = (kiss_fft_cpx *) sf_alloc(nk*n2,sizeof(kiss_fft_cpx)); for (i2=0; i2 < n2; i2++) { tmp[i2] = tmp[0]+i2*nk; } trace2 = sf_complexalloc(n2); ctrace2 = (kiss_fft_cpx *) trace2; #endif *nx2 = n1; *ny2 = n2; wt = 1.0/(n1*n2); return (nk*n2); }
void initialize_fft (int n) { fin = KISS_FFT_MALLOC (n * sizeof (kiss_fft_cpx)); assert(fin != NULL); fout = KISS_FFT_MALLOC (n * sizeof (kiss_fft_cpx)); assert(fout != NULL); cfg_forward = kiss_fft_alloc (n, 0, NULL, NULL); assert(cfg_forward != NULL); cfg_reverse = kiss_fft_alloc (n, 1, NULL, NULL); assert(cfg_reverse != NULL); }
int cfft2_init(int pad1 /* padding on the first axis */, int nx, int ny /* input data size */, int *nx2, int *ny2 /* padded data size */) /*< initialize >*/ { #ifdef SF_HAS_FFTW #ifdef _OPENMP fftw_init_threads(); sf_warning("Using threaded FFTW3! \n"); fftw_plan_with_nthreads(omp_get_max_threads()); #endif #endif #ifndef SF_HAS_FFTW int i2; #endif nk = n1 = kiss_fft_next_fast_size(nx*pad1); #ifndef SF_HAS_FFTW cfg1 = kiss_fft_alloc(n1,0,NULL,NULL); icfg1 = kiss_fft_alloc(n1,1,NULL,NULL); #endif n2 = kiss_fft_next_fast_size(ny); cc = sf_complexalloc2(n1,n2); dd = sf_complexalloc2(nk,n2); #ifndef SF_HAS_FFTW cfg2 = kiss_fft_alloc(n2,0,NULL,NULL); icfg2 = kiss_fft_alloc(n2,1,NULL,NULL); tmp = (kiss_fft_cpx **) sf_alloc(n2,sizeof(*tmp)); tmp[0] = (kiss_fft_cpx *) sf_alloc(nk*n2,sizeof(kiss_fft_cpx)); for (i2=0; i2 < n2; i2++) { tmp[i2] = tmp[0]+i2*nk; } trace2 = sf_complexalloc(n2); ctrace2 = (kiss_fft_cpx *) trace2; #endif *nx2 = n1; *ny2 = n2; wt = 1.0/(n1*n2); return (nk*n2); }
void rweone_fft_init(int n) /*< init FFT >*/ { if(n>0) { ffts = 1./sqrt(n); } else { sf_error("KISS FFT scale error: n==0",__FILE__); } forw = kiss_fft_alloc(n,0,NULL,NULL); invs = kiss_fft_alloc(n,1,NULL,NULL); if (NULL == forw || NULL == invs) sf_error("%s: KISS FFT allocation error",__FILE__); }
int main() { constexpr int NFFT = 2'048; constexpr int FREQ = 16'000; std::unique_ptr<kiss_fft_state, freeDelete> cfg{kiss_fft_alloc(NFFT, 0, nullptr, nullptr)}; std::vector<kiss_fft_cpx> buff_in(NFFT); std::vector<kiss_fft_cpx> buff_out(NFFT); std::ifstream file{"/tmp/samples"}; std::cerr << "1" << std::endl; { int i = 0; int witam = 0; std::cerr << "2" << std::endl; while(file >> witam) { buff_in[i++].r = witam; std::cerr << i << std::endl; } } kiss_fft(cfg.get(), buff_in.data(), buff_out.data()); std::ofstream of{"/tmp/kissfft23"}; for (int i = 0; i < NFFT; ++i) { of << buff_out[i].r << std::endl; } std::cerr << "test"; }
void TestFft(const char* title, const kiss_fft_cpx in[N], kiss_fft_cpx out[N]) { kiss_fft_cfg cfg; printf("%s\n", title); if ((cfg = kiss_fft_alloc(N, 0/*is_inverse_fft*/, NULL, NULL)) != NULL) { size_t i; kiss_fft(cfg, in, out); free(cfg); for (i = 0; i < N; i++) printf(" in[%2zu] = %+f , %+f " "out[%2zu] = %+f , %+f\n", i, in[i].r, in[i].i, i, out[i].r, out[i].i); } else { printf("not enough memory?\n"); exit(-1); } }
void SndAnalyzer::function_fft_top_only(GenSoundFunction fct, PlaySoundFunction pfct, double t1, double t2, double freq, unsigned int points) { double t, dt; unsigned int i; result_amp = result_freq = 0; kiss_fft_cpx* cin = new kiss_fft_cpx[points]; kiss_fft_cpx* cout = new kiss_fft_cpx[points]; kiss_fft_cfg kiss_fft_state; kiss_fft_scalar zero; memset(&zero,0,sizeof(zero) ); dt = (t2-t1)/points; for(i = 0; i<points; i++) { t = t1 + dt*i; cin[i].i = zero; cin[i].r = fct(t, freq*2*M_PI, freq, pfct); if (abs(cin[i].r)>result_amp) result_amp = abs(cin[i].r); } kiss_fft_state = kiss_fft_alloc(points,0,0,0); kiss_fft(kiss_fft_state,cin,cout); function_fft_calc_top(cout, points, abs(t2-t1)); free(kiss_fft_state); delete [] cin; delete [] cout; }
void ConstQ::genSparseKernel() { // get frequencies of min and max Note minFreq = noteNum2Freq((float)minNote); maxFreq = noteNum2Freq((float)maxNote); // get Q value and the number of total constant Q bins Q = 1./(pow(2.,(1./bpo)) - 1); constQBins = ceil(bpo * log2(maxFreq/minFreq)); // memory alloc for sparkernel bins sparkernel = new sparKernel[constQBins]; fftLength = nextPowerOf2((unsigned int) ceil(Q * fs/minFreq)); // fft setup fft = kiss_fft_alloc(fftLength, 0, NULL, NULL); fftr = kiss_fftr_alloc(fftLength, 0, NULL, NULL); for (int k=constQBins; k > 0; k--){ double centerFreq = (minFreq * pow(2,(float(k-1)/bpo))); int upperBound = ceil(centerFreq * pow(2, 1./12) * fftLength/fs); int lowerBound = floor(centerFreq * pow(2, -1./12) * fftLength/fs); sparkernel[k-1].s = lowerBound; sparkernel[k-1].e = upperBound; sparkernel[k-1].cpx = new kiss_fft_cpx[upperBound - lowerBound]; } pthread_create(&thread, NULL, ConstQ::sparseKernelThread, this); }
int xkolmog_init(int n1) /*< initialize with data length >*/ { nfft = n1; nk = kiss_fft_next_fast_size(nfft); fft1 = sf_complexalloc(nk); fft2 = sf_complexalloc(nk); forw = kiss_fft_alloc(nk,1,NULL,NULL); invs = kiss_fft_alloc(nk,0,NULL,NULL); if (NULL == forw || NULL == invs) sf_error("%s: KISS FFT allocation error"); return nk; }
void *nlp_create( int m /* analysis window size */ ) { NLP *nlp; int i; assert(m <= PMAX_M); nlp = (NLP*)malloc(sizeof(NLP)); if (nlp == NULL) return NULL; nlp->m = m; for(i=0; i<m/DEC; i++) { nlp->w[i] = 0.5 - 0.5*cosf(2*PI*i/(m/DEC-1)); } for(i=0; i<PMAX_M; i++) nlp->sq[i] = 0.0; nlp->mem_x = 0.0; nlp->mem_y = 0.0; for(i=0; i<NLP_NTAP; i++) nlp->mem_fir[i] = 0.0; nlp->fft_cfg = kiss_fft_alloc (PE_FFT_SIZE, 0, NULL, NULL); assert(nlp->fft_cfg != NULL); return (void*)nlp; }
void SignalProc_init() { for (int i = 0; i < FFT_BUFFER_SIZE; i++) sigData.in[i].r = sigData.in[i].i = 0; sigData.cfg = kiss_fft_alloc(FFT_BUFFER_SIZE, 0/*is_inverse_fft*/, NULL, NULL); }
void test1d(int nfft,int isinverse) { char mensaje [128]; clock_t start; clock_t end; size_t buflen = sizeof(kiss_fft_cpx)*nfft; kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen); kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen); kiss_fft_cfg cfg = kiss_fft_alloc(nfft,0,0); int k; for (k=0;k<nfft;++k) { in[k].r = (rand() % 32767) - 16384; in[k].i = (rand() % 32767) - 16384; } #ifdef DOUBLE_PRECISION for (k=0;k<nfft;++k) { in[k].r *= 32768; in[k].i *= 32768; } #endif if (isinverse) { for (k=0;k<nfft;++k) { in[k].r /= nfft; in[k].i /= nfft; } } /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/ //start=TPM3CNT; //tic tic(); if (isinverse) kiss_ifft(cfg,in,out); else kiss_fft(cfg,in,out); toc(); //end =TPM3CNT; //toc /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/ check(in,out,nfft,isinverse); free(in); free(out); free(cfg); }
void fft_filt_c::prepare_filter() { fft_len = is_complex ? kiss_fft_next_fast_size(l + filter_inlen) : kiss_fftr_next_fast_size_real(l+filter_inlen); if (filter_is_ready) { make_unready(); } kiss_fft_cpx *filt_buf_in = new kiss_fft_cpx[fft_len]; filt_buf = new kiss_fft_cpx[fft_len]; float absmax =0; if (filter_is_complex) { for (uint32_t i=0;i<filter_inlen;i++) { filt_buf_in[i].i = fft_len * filter_inptr[2*i]; filt_buf_in[i].r = fft_len * filter_inptr[2*i+1]; } } else { for (uint32_t i=0;i<filter_inlen;i++) { filt_buf_in[i].r = fft_len * filter_inptr[i]; filt_buf_in[i].i = 0; } } for (uint32_t i=filter_inlen;i<fft_len;i++) { filt_buf_in[i].r = 0; filt_buf_in[i].i = 0; } kiss_fft_cfg filter_cfg = kiss_fft_alloc(fft_len,0,0,0); kiss_fft(filter_cfg,filt_buf_in,filt_buf); absmax = 0; for (uint32_t i=0;i<fft_len;i++) { if (filt_buf[i].i > absmax) { absmax = filt_buf[i].i; }; if (filt_buf[i].i < -absmax) { absmax = -filt_buf[i].i; }; if (filt_buf[i].r > absmax) { absmax = filt_buf[i].r; }; if (filt_buf[i].r < -absmax) { absmax = -filt_buf[i].r; }; } // for (uint32_t i=0;i<fft_len/2+1;i++) { d3c(i,filt_buf[i].i,filt_buf[i].r); }; float scale_factor = 32767.0 / absmax; for (uint32_t i=0;i<fft_len;i++) { filt_buf[i].r = (float)filt_buf[i].r * scale_factor; filt_buf[i].i = (float)filt_buf[i].i * scale_factor; } // for (uint32_t i=0;i<fft_len/2+1;i++) { d3c(i,filt_buf[i].i,filt_buf[i].r); }; filter_is_ready = true; delete filt_buf_in; };
void SndAnalyzer::function_fft_base(GenSoundFunction fct, PlaySoundFunction pfct, double t1, double t2, double freq, unsigned int points) { double t, dt; double timelen = abs(t2-t1); unsigned int i, j, i_start, i_finish; double base_freq = points / timelen; i_start = 0; i_finish = points - 1; if (skip_zero_frequency) { i_start++; i_finish--; } result_amp = result_freq = 0; kiss_fft_cpx* cin = new kiss_fft_cpx[points]; kiss_fft_cpx* cout = new kiss_fft_cpx[points]; kiss_fft_cfg kiss_fft_state; kiss_fft_scalar zero; memset(&zero,0,sizeof(zero) ); dt = (t2-t1)/points; for(i = 0; i<points; i++) { t = t1 + dt*i; cin[i].i = zero; cin[i].r = fct(t, freq*2*M_PI, freq, pfct); if (abs(cin[i].r)>result_amp) result_amp = abs(cin[i].r); } kiss_fft_state = kiss_fft_alloc(points,0,0,0); kiss_fft(kiss_fft_state,cin,cout); double tmp_amp, tmp_amp2, tmp_freq; HarmonicInfo tmp_info; harmonics->clear(); for(i = i_start, j = i_finish; i<=j; i++, j--) { tmp_amp = sqrt(sqr(cout[i].r)+sqr(cout[i].i)) / base_freq; tmp_amp2 = sqrt(sqr(cout[j].r)+sqr(cout[j].i)) / base_freq; if (tmp_amp<tmp_amp2) tmp_amp = tmp_amp2; tmp_freq = i/timelen; tmp_info.amp = tmp_amp; tmp_info.freq = tmp_freq; harmonics->append(tmp_info); } function_fft_calc_top(cout, points, timelen); free(kiss_fft_state); delete [] cin; delete [] cout; }
/*------------------------------------------------------------*/ void fft2_init(int n1_, int n2_) /*< initialize >*/ { n1 = n1_; n2 = n2_; forw1 = kiss_fft_alloc(n1,0,NULL,NULL); invs1 = kiss_fft_alloc(n1,1,NULL,NULL); forw2 = kiss_fft_alloc(n2,0,NULL,NULL); invs2 = kiss_fft_alloc(n2,1,NULL,NULL); trace2 = (kiss_fft_cpx*) sf_complexalloc(n2); if (NULL == forw2 || NULL == invs2 || NULL == forw1 || NULL == invs1) sf_error("%s: KISS FFT allocation error",__FILE__); fftscale = 1./sqrtf(n1*n2); }
void ffti( FFT_Tables *fft_tables, double *xr, double *xi, int logm ) { int nfft = 0; kiss_fft_cpx fin[1 << MAXLOGM]; kiss_fft_cpx fout[1 << MAXLOGM]; if ( logm > MAXLOGM ) { fprintf(stderr, "fft size too big\n"); exit(1); } nfft = logm_to_nfft[logm]; if ( fft_tables->cfg[logm][1] == NULL ) { if ( nfft ) { fft_tables->cfg[logm][1] = kiss_fft_alloc( nfft, 1, NULL, NULL ); } else { fprintf(stderr, "bad logm = %d\n", logm); exit( 1 ); } } if ( fft_tables->cfg[logm][1] ) { unsigned int i; double fac = 1.0 / (double)nfft; for ( i = 0; i < nfft; i++ ) { fin[i].r = xr[i]; fin[i].i = xi[i]; } kiss_fft( (kiss_fft_cfg)fft_tables->cfg[logm][1], fin, fout ); for ( i = 0; i < nfft; i++ ) { xr[i] = fout[i].r * fac; xi[i] = fout[i].i * fac; } } else { fprintf( stderr, "bad config for logm = %d\n", logm); exit( 1 ); } }
void freqfilt4pi_init(int n1, int n2 /* data dimensions */, int nw1 /* number of frequencies */) /*< initialize >*/ { m1 = n1; nw = nw1; m2 = n2; nfft = 2*kiss_fft_next_fast_size((n1+1)/2); tfor = kiss_fftr_alloc(nfft,0,NULL,NULL); tinv = kiss_fftr_alloc(nfft,1,NULL,NULL); xfor = kiss_fft_alloc(n2,0,NULL,NULL); xinv = kiss_fft_alloc(n2,1,NULL,NULL); if (NULL == tfor || NULL == tinv || NULL == xfor || NULL == xinv) sf_error("%s: KISS FFT allocation error",__FILE__); trace = sf_floatalloc(nfft); ctrace = (kiss_fft_cpx*) sf_complexalloc(nw); ctrace2 = (kiss_fft_cpx*) sf_complexalloc(n2); fft = (kiss_fft_cpx**) sf_complexalloc2(nw,n2); }
/*------------------------------------------------------------*/ sf_fft3d sf_fft3a1_init(int n1_, int n2_, int n3_) /*< initialize FFT on axis 1 >*/ { sf_fft3d fft; fft = (sf_fft3d) sf_alloc(1,sizeof(*fft)); fft->n1 = n1_; fft->n2 = n2_; fft->n3 = n3_; fft->forw = kiss_fft_alloc(fft->n1,0,NULL,NULL); fft->invs = kiss_fft_alloc(fft->n1,1,NULL,NULL); if (NULL == fft->forw || NULL == fft->invs) sf_error("%s: KISS FFT allocation error",__FILE__); fft->scale = 1./sqrtf(fft->n1); return fft; }
void ist (int len /* data size */, float d1 /* data sampling */, int lo /* low frequency */, int hi /* high frequency */, float *result /* output [len] */, sf_complex *data /* input [len*(hi-lo+1)] */) /*< Inverse S transform >*/ { int i, i1, l2, nw; kiss_fft_cpx *d, *pp; kiss_fft_cfg itfft; nw = 2*kiss_fft_next_fast_size((len+1)/2); itfft = kiss_fft_alloc(nw,1,NULL,NULL); pp = (kiss_fft_cpx*) sf_complexalloc(nw); d = (kiss_fft_cpx*) sf_complexalloc(nw); for (i=0; i < nw; i++) { pp[i].r = 0.; pp[i].i = 0.; } for (i1=lo; i1 <= hi; i1++) { for (i=0; i < len; i++) { pp[i1-lo].r += crealf(data[(i1-lo)*len+i]); pp[i1-lo].i += cimagf(data[(i1-lo)*len+i]); } } l2 = (nw+1)/2; for (i=1; i < l2; i++) { pp[i].r /= 2.; pp[i].i /= 2.; } l2 = nw/2+1; for (i=l2; i < nw; i++) { pp[i].r = pp[nw-i].r; pp[i].i = -pp[nw-i].i; } kiss_fft_stride(itfft,pp,d,1); for (i=0; i < len; i++) { result[i] = d[i].r/len; } free(pp); free(d); }
fft_cfg fft_new(int n, int inverse) { #ifdef KISS_FFT kiss_fft_cfg cfg = kiss_fft_alloc (n, inverse, NULL, NULL); return cfg; #elif defined(LIBAVCODEC_FFT) FFTContext *ctxt = av_fft_init(log2int(n), inverse); if (ctxt == NULL) return NULL; fft_cfg cfg = malloc(sizeof(*cfg)); cfg->context = ctxt; cfg->size = sizeof(COMP) * n; return cfg; #else #error FFT engine was not defined #endif }
/*------------------------------------------------------------*/ fft2d ompfft2_init(cub3d cub, int n1_, int n2_) /*< initialize >*/ { int ompith; /*------------------------------------------------------------*/ fft2d fft; fft = (fft2d) sf_alloc(1,sizeof(*fft)); fft->n1 = n1_; fft->n2 = n2_; fft->ctrace = (kiss_fft_cpx**) sf_complexalloc2(fft->n2,cub->ompnth); fft->forw1 = (kiss_fft_cfg*) sf_alloc(cub->ompnth,sizeof(kiss_fft_cfg)); fft->invs1 = (kiss_fft_cfg*) sf_alloc(cub->ompnth,sizeof(kiss_fft_cfg)); fft->forw2 = (kiss_fft_cfg*) sf_alloc(cub->ompnth,sizeof(kiss_fft_cfg)); fft->invs2 = (kiss_fft_cfg*) sf_alloc(cub->ompnth,sizeof(kiss_fft_cfg)); for(ompith=0; ompith<cub->ompnth; ompith++) { fft->forw1[ompith] = kiss_fft_alloc(fft->n1,0,NULL,NULL); fft->invs1[ompith] = kiss_fft_alloc(fft->n1,1,NULL,NULL); fft->forw2[ompith] = kiss_fft_alloc(fft->n2,0,NULL,NULL); fft->invs2[ompith] = kiss_fft_alloc(fft->n2,1,NULL,NULL); if (NULL == fft->forw2[ompith] || NULL == fft->invs2[ompith] || NULL == fft->forw1[ompith] || NULL == fft->invs1[ompith]) sf_error("%s: KISS FFT allocation error",__FILE__); } fft->fftscale = 1./sqrtf(fft->n1*fft->n2); return fft; }
DP_FN_PREAMBLE(cfft,prerun) { if (!b->is_complex) { fprintf(stderr,"-ce-(%s) real ffn not supported yet\n",b->name); exit(-1); } if (s->need_buffers && !s->buffs_allocd) { fprintf(stderr,"-ci- cfft (%s) allocated buffer\n",b->name); s->ibuff = malloc(sizeof(kiss_fft_cpx) * b->runlength); s->obuff = malloc(sizeof(kiss_fft_cpx) * b->runlength); s->buffs_allocd = dp_true; } if (!s->ready) { s->cfg = kiss_fft_alloc(b->runlength,0,0,0); s->ready = dp_true; } }
static void fft_file(FILE * fin, FILE * fout, int nfft, int isinverse) { kiss_fft_cfg st; kiss_fft_cpx * buf; kiss_fft_cpx * bufout; buf = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx) * nfft); bufout = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx) * nfft); st = kiss_fft_alloc(nfft , isinverse , 0, 0); while (fread(buf , sizeof(kiss_fft_cpx) * nfft , 1, fin) > 0) { kiss_fft(st , buf , bufout); fwrite(bufout , sizeof(kiss_fft_cpx) , nfft , fout); } free(st); free(buf); free(bufout); }
void *nlp_create( int m /* analysis window size */ ) { NLP *nlp; int i; assert(m <= PMAX_M); nlp = (NLP*)malloc(sizeof(NLP)); if (nlp == NULL) return NULL; nlp->m = m; scalar PI2_ = fl_to_numb(2*PI); scalar DEC_ = int_to_numb(m/DEC - 1); scalar HALF = fl_to_numb(.5); scalar ZERO = fl_to_numb(0.0); scalar a, b, c; for(i=0; i<m/DEC; i++) { a = s_div(s_mul(PI2_, int_to_numb(i) ) , DEC_); b = s_mul(HALF,s_cos(a)); nlp->w[i] = s_sub(HALF, b); //nlp->w[i] = 0.5 - 0.5*cosf(2*PI*i/(m/DEC-1)); } for(i=0; i<PMAX_M; i++) nlp->sq[i] = ZERO; nlp->mem_x = ZERO; nlp->mem_y = ZERO; for(i=0; i<NLP_NTAP; i++) nlp->mem_fir[i] = ZERO; nlp->fft_cfg = kiss_fft_alloc (PE_FFT_SIZE, 0, NULL, NULL); assert(nlp->fft_cfg != NULL); return (void*)nlp; }