scfft * scfft_create(size_t fullsize, size_t winsize, SCFFT_WindowFunction wintype, float *indata, float *outdata, SCFFT_Direction forward, SCFFT_Allocator & alloc) { char * chunk = (char*) alloc.alloc(sizeof(scfft) + scfft_trbufsize(fullsize)); if (!chunk) return NULL; scfft * f = (scfft*)chunk; float *trbuf = (float*)(chunk + sizeof(scfft)); f->nfull = fullsize; f->nwin = winsize; f->log2nfull = LOG2CEIL(fullsize); f->log2nwin = LOG2CEIL( winsize); f->wintype = wintype; f->indata = indata; f->outdata = outdata; f->trbuf = trbuf; // Buffer is larger than the range of sizes we provide for at startup; we can get ready just-in-time though if (fullsize > SC_FFT_MAXSIZE) scfft_ensurewindow(f->log2nfull, f->log2nwin, wintype); #if SC_FFT_FFTW if(forward) f->plan = fftwf_plan_dft_r2c_1d(fullsize, trbuf, (fftwf_complex*) trbuf, FFTW_ESTIMATE); else f->plan = fftwf_plan_dft_c2r_1d(fullsize, (fftwf_complex*) trbuf, outdata, FFTW_ESTIMATE); #endif // The scale factors rescale the data to unity gain. The old Green lib did this itself, meaning scalefacs would here be 1... if(forward){ #if SC_FFT_VDSP f->scalefac = 0.5f; #else // forward FFTW and Green factor f->scalefac = 1.f; #endif } else { // backward FFTW and VDSP factor #if SC_FFT_GREEN f->scalefac = 1.f; #else // fftw, vdsp f->scalefac = 1.f / fullsize; #endif } memset(trbuf, 0, scfft_trbufsize(fullsize)); return f; }
int scfft_create(scfft *f, unsigned int fullsize, unsigned int winsize, short wintype, float *indata, float *outdata, float *trbuf, bool forward){ f->nfull = fullsize; f->nwin = winsize; f->log2nfull = LOG2CEIL(fullsize); f->log2nwin = LOG2CEIL( winsize); f->wintype = wintype; f->indata = indata; f->outdata = outdata; f->trbuf = trbuf; // Buffer is larger than the range of sizes we provide for at startup; we can get ready just-in-time though if (fullsize > SC_FFT_MAXSIZE){ scfft_ensurewindow(f->log2nfull, f->log2nwin, wintype); } #if SC_FFT_FFTW if(forward) f->plan = fftwf_plan_dft_r2c_1d(fullsize, trbuf, (fftwf_complex*) trbuf, FFTW_ESTIMATE); else f->plan = fftwf_plan_dft_c2r_1d(fullsize, (fftwf_complex*) trbuf, outdata, FFTW_ESTIMATE); #endif // The scale factors rescale the data to unity gain. The old Green lib did this itself, meaning scalefacs would here be 1... if(forward){ #if SC_FFT_VDSP f->scalefac = 0.5f; #else // forward FFTW factor f->scalefac = 1.f; #endif }else{ // backward FFTW and VDSP factor f->scalefac = 1.f / fullsize; } memset(trbuf, 0, scfft_trbufsize(fullsize)); return 0; }