diff Source/FFTW.h @ 0:25bf17994ef1

First commit. VS2013, Codeblocks and Mac OSX configuration
author Geogaddi\David <d.m.ronan@qmul.ac.uk>
date Thu, 09 Jul 2015 01:12:16 +0100
parents
children e86e9c111b29
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/FFTW.h	Thu Jul 09 01:12:16 2015 +0100
@@ -0,0 +1,81 @@
+//----------------------------------------------------------------------------------------------------------------------
+/**
+ \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 <windows.h>
+#include <string>
+//#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;
+	}
+  }
+
+};
+