annotate 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
rev   line source
d@0 1 //----------------------------------------------------------------------------------------------------------------------
d@0 2 /**
d@0 3 \author André Bergner
d@0 4 \date Feb/2013
d@1 5
d@0 6 \class FFTW
d@1 7
d@0 8 Encapsulates the FFT of lib-fftw
d@1 9
d@0 10 (c) Copyright NATIVE INSTRUMENTS, Berlin, Germany
d@0 11 ALL RIGHTS RESERVED
d@0 12 */
d@0 13 //----------------------------------------------------------------------------------------------------------------------
d@0 14
d@0 15 #pragma once
d@0 16
d@0 17 #include "fftw3.h"
d@1 18 #include <vector>
d@1 19 #include <stdio.h>
d@1 20 //#include <windows.h>
d@1 21 #include <string.h>
d@0 22 //#include <itl/dsp/SimdTools.h>
d@0 23
d@0 24
d@0 25
d@0 26 class FFTW
d@0 27 {
d@0 28
d@0 29 public:
d@0 30 fftwf_plan m_plan;
d@0 31 unsigned m_iFFTSize;
d@0 32
d@1 33 FFTW();
d@0 34 FFTW( unsigned fftLength )
d@0 35 {
d@0 36 m_iFFTSize = fftLength;
d@0 37
d@0 38 float* tempInput = new float[fftLength];
d@0 39 memset(tempInput,0, fftLength * sizeof(float));
d@0 40 float* tempReal = new float[fftLength];
d@0 41 memset(tempReal,0, fftLength * sizeof(float));
d@0 42 float* tempImag = new float[fftLength];
d@0 43 memset(tempImag,0, fftLength * sizeof(float));
d@0 44 fftwf_iodim dim;
d@0 45 dim.n = fftLength;
d@0 46 dim.is = 1;
d@0 47 dim.os = 1;
d@0 48 m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, NULL, tempInput, tempReal, tempImag, FFTW_ESTIMATE );
d@0 49 delete[] tempInput;
d@0 50 tempInput = nullptr;
d@0 51 delete[] tempReal;
d@0 52 tempReal = nullptr;
d@0 53 delete[] tempImag;
d@0 54 tempImag = nullptr;
d@0 55 }
d@0 56
d@0 57
d@0 58 ~FFTW()
d@0 59 {
d@0 60 if(m_plan != NULL)
d@0 61 {
d@0 62 fftwf_destroy_plan( m_plan );
d@0 63 }
d@0 64 }
d@0 65
d@0 66
d@0 67 void process( const float* input , float* realPart , float* imagPart )
d@0 68 {
d@0 69 float* nonConstInput = const_cast<float*>(input); // fftw does not take const input even though the data not be manipulated!
d@0 70
d@0 71 fftwf_execute_split_dft_r2c( m_plan, nonConstInput, realPart, imagPart);
d@0 72
d@0 73 //Multiply results by 2 to match the iOS output
d@0 74 for(size_t i = 0; i < m_iFFTSize; i++)
d@1 75 {
d@0 76 realPart[i] *= 2.f;
d@0 77 imagPart[i] *= 2.f;
d@0 78 }
d@0 79 }
d@0 80
d@0 81 };
d@0 82