OpenWareLaboratory
ComplexFourierTransform.h
Go to the documentation of this file.
1 #ifndef __ComplexFourierTransform_h__
2 #define __ComplexFourierTransform_h__
3 
4 #include "ComplexFloatArray.h"
5 
6 #ifdef ARM_CORTEX
7 #include "arm_const_structs.h"
8 
10 private:
11  arm_cfft_instance_f32 instance;
12 public:
14  ComplexFourierTransform(int len){
15  init(len);
16  }
17  void init(int len){
18  ASSERT(len==32 || len ==64 || len==128 || len==256 || len==512 || len==1024 || len==2048 || len==4096, "Unsupported FFT size");
19  void* args[] = {(void*)&instance, (void*)&len};
20  getProgramVector()->serviceCall(OWL_SERVICE_ARM_CFFT_INIT_F32, args, 2);
21  // Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096.
22  }
23  void fft(ComplexFloatArray inout){
24  ASSERT(inout.getSize() >= getSize(), "Input array too small");
25  arm_cfft_f32(&instance, (float*)inout.getData(), 0, 1); //forward
26  }
27  void ifft(ComplexFloatArray inout){
28  ASSERT(inout.getSize() >= getSize(), "Input array too small");
29  arm_cfft_f32(&instance, (float*)inout.getData(), 1, 1); //inverse
30  }
31  int getSize(){
32  return instance.fftLen;
33  }
34 };
35 #endif /* ARM_CORTEX */
36 
37 #ifndef ARM_CORTEX
38 #include "kiss_fft.h"
40 private:
41  kiss_fft_cfg cfgfft;
42  kiss_fft_cfg cfgifft;
43  ComplexFloatArray temp;
44 public:
47  init(len);
48  }
51  }
52  void init(int len){
53  ASSERT(len==32 || len ==64 || len==128 || len==256 || len==512 || len==1024 || len==2048 || len==4096, "Unsupported FFT size");
54  cfgfft = kiss_fft_alloc(len, 0 , 0, 0);
55  cfgifft = kiss_fft_alloc(len, 1,0, 0);
56  temp = ComplexFloatArray::create(len);
57  }
58  void fft(ComplexFloatArray inout){
59  ASSERT(inout.getSize() >= getSize(), "Input array too small");
60  kiss_fft(cfgfft, (kiss_fft_cpx*)(float*)inout.getData(), (kiss_fft_cpx*)(float*)temp.getData());
61  inout.copyFrom(temp);
62  }
63  void ifft(ComplexFloatArray inout){
64  ASSERT(inout.getSize() >= getSize(), "Input array too small");
65  kiss_fft(cfgifft, (kiss_fft_cpx*)(float*)inout.getData(), (kiss_fft_cpx*)(float*)temp.getData());
66  temp.scale(1.0f/getSize());
67  inout.copyFrom(temp);
68  }
69  size_t getSize(){
70  return temp.getSize();
71  }
72 };
73 #endif /* ifndef ARM_CORTEX */
74 
75 #endif // __ComplexFourierTransform_h__
static void destroy(ComplexFloatArray)
Destroys a ComplexFloatArray created with the create() method.
void scale(float factor)
Array by scalar multiplication.
static ComplexFloatArray create(size_t size)
Creates a new ComplexFloatArray.
void copyFrom(FloatArray real, FloatArray imag)
Merge two channels of audio containing real and imaginary axis data into this array.
void ifft(ComplexFloatArray inout)
void fft(ComplexFloatArray inout)
size_t getSize() const
Definition: SimpleArray.h:31
T * getData()
Get the data stored in the Array.
Definition: SimpleArray.h:27
#define ASSERT(cond, msg)
Definition: message.h:16