Mercurial > hg > batch-feature-extraction-tool
view Source/FFTW.h @ 1:e86e9c111b29
Updates stuff that potentially fixes the memory leak and also makes it work on Windows and Linux (Need to test). Still have to fix fftw include for linux in Jucer.
author | David Ronan <d.m.ronan@qmul.ac.uk> |
---|---|
date | Thu, 09 Jul 2015 15:01:32 +0100 |
parents | 25bf17994ef1 |
children | 005e311b5e62 |
line wrap: on
line source
//---------------------------------------------------------------------------------------------------------------------- /** \author André Bergner \date Feb/2013 \class FFTW Encapsulates the FFT of lib-fftw (c) Copyright NATIVE INSTRUMENTS, Berlin, Germany ALL RIGHTS RESERVED */ //---------------------------------------------------------------------------------------------------------------------- #pragma once #include "fftw3.h" #include <vector> #include <stdio.h> //#include <windows.h> #include <string.h> //#include <itl/dsp/SimdTools.h> class FFTW { public: fftwf_plan m_plan; unsigned m_iFFTSize; FFTW(); FFTW( unsigned fftLength ) { m_iFFTSize = fftLength; float* tempInput = new float[fftLength]; memset(tempInput,0, fftLength * sizeof(float)); float* tempReal = new float[fftLength]; memset(tempReal,0, fftLength * sizeof(float)); float* tempImag = new float[fftLength]; memset(tempImag,0, fftLength * sizeof(float)); fftwf_iodim dim; dim.n = fftLength; dim.is = 1; dim.os = 1; m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, NULL, tempInput, tempReal, tempImag, FFTW_ESTIMATE ); delete[] tempInput; tempInput = nullptr; delete[] tempReal; tempReal = nullptr; delete[] tempImag; tempImag = nullptr; } ~FFTW() { if(m_plan != NULL) { fftwf_destroy_plan( m_plan ); } } void process( const float* input , float* realPart , float* imagPart ) { float* nonConstInput = const_cast<float*>(input); // fftw does not take const input even though the data not be manipulated! fftwf_execute_split_dft_r2c( m_plan, nonConstInput, realPart, imagPart); //Multiply results by 2 to match the iOS output for(size_t i = 0; i < m_iFFTSize; i++) { realPart[i] *= 2.f; imagPart[i] *= 2.f; } } };