diff --git a/src/fcwt/fcwt.cpp b/src/fcwt/fcwt.cpp index 5194cf5..2459205 100644 --- a/src/fcwt/fcwt.cpp +++ b/src/fcwt/fcwt.cpp @@ -86,8 +86,8 @@ void Morlet::generate(float* real, float* imag, int size, float scale) { void Morlet::getWavelet(float scale, complex* pwav, int pn) { int w = getSupport(scale); - float *real = (float*)malloc(sizeof(float)*max(w*2+1,pn)); - float *imag = (float*)malloc(sizeof(float)*max(w*2+1,pn)); + float *real = (float*)fftwf_malloc(sizeof(float)*max(w*2+1,pn)); + float *imag = (float*)fftwf_malloc(sizeof(float)*max(w*2+1,pn)); for(int t=0; t < max(w*2+1,pn); t++) { real[t] = 0; imag[t] = 0; @@ -99,9 +99,9 @@ void Morlet::getWavelet(float scale, complex* pwav, int pn) { pwav[t].real(real[t]); pwav[t].imag(imag[t]); } - - delete real; - delete imag; + + fftwf_free(real); + fftwf_free(imag); }; //==============================================================// @@ -121,7 +121,9 @@ Scales::Scales(Wavelet *wav, SCALETYPE st, int afs, float af0, float af1, int af calculate_linscale_array(wav->four_wavelen, afs, af0, af1, afn); else calculate_linfreq_array(wav->four_wavelen, afs, af0, af1, afn); - +} +Scales::~Scales(){ + free(scales); } void Scales::getScales(float *pfreqs, int pnf) { @@ -321,7 +323,7 @@ void FCWT::create_FFT_optimization_plan(int maxsize, int flags) { for(int i=11; i<=nt; i++) { int n = 1 << i; - float *dat = (float*)malloc(sizeof(float)*n); + float *dat = (float*)fftwf_malloc(sizeof(float)*n); fftwf_complex *O1 = fftwf_alloc_complex(n); fftwf_complex *out = fftwf_alloc_complex(n); @@ -347,9 +349,11 @@ void FCWT::create_FFT_optimization_plan(int maxsize, int flags) { fftwf_export_wisdom_to_filename(file_for); - free(dat); + fftwf_free(dat); fftwf_free(O1); fftwf_free(out); + fftwf_destroy_plan(p_for); + fftwf_destroy_plan(p_back); std::cout << "Optimization schemes for N: " << n << " have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length." << std::endl; } @@ -406,6 +410,7 @@ void FCWT::convolve(fftwf_plan p, fftwf_complex *Ihat, fftwf_complex *O1, comple fftbased(p, Ihat, O1, (float*)lastscalemem, wav->mother, newsize, scale, wav->imag_frequency, wav->doublesided); if(use_normalization) fft_normalize((complex*)lastscalemem, newsize); memcpy(out, (complex*)lastscalemem, sizeof(complex)*size); + free(lastscalemem); } else { if(!out) { std::cout << "OUT NOT A POINTER" << std::endl; diff --git a/src/fcwt/fcwt.h b/src/fcwt/fcwt.h index 6a792fa..f8671f6 100644 --- a/src/fcwt/fcwt.h +++ b/src/fcwt/fcwt.h @@ -106,7 +106,7 @@ class Morlet : public Wavelet { class Scales { public: FCWT_LIBRARY_API Scales(Wavelet *pwav, SCALETYPE st, int fs, float f0, float f1, int fn); - + ~Scales(); void FCWT_LIBRARY_API getScales(float *pfreqs, int pnf); void FCWT_LIBRARY_API getFrequencies(float *pfreqs, int pnf); @@ -174,4 +174,4 @@ inline int find2power(int n) return(m); } -#endif \ No newline at end of file +#endif