Mercurial > hg > vamp-tempogram
comparison FIRFilter.cpp @ 9:be59b4a73f49
* Added Spectrogram zero padding functionality
* Made output bins correspond to BPM
* User can now specify a range of output bins to view
* Comments added
author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
---|---|
date | Tue, 12 Aug 2014 14:40:37 +0100 |
parents | 4e429b9f2b4d |
children | 17a260410116 |
comparison
equal
deleted
inserted
replaced
8:4e429b9f2b4d | 9:be59b4a73f49 |
---|---|
31 FIRFilter::~FIRFilter() | 31 FIRFilter::~FIRFilter() |
32 { | 32 { |
33 cleanup(); | 33 cleanup(); |
34 } | 34 } |
35 | 35 |
36 //allocate memory | |
36 void | 37 void |
37 FIRFilter::initialise() | 38 FIRFilter::initialise() |
38 { | 39 { |
40 //next power of 2 | |
39 m_lengthFIRFFT = pow(2,(ceil(log2(m_lengthInput+m_numberOfCoefficients-1)))); | 41 m_lengthFIRFFT = pow(2,(ceil(log2(m_lengthInput+m_numberOfCoefficients-1)))); |
40 | 42 |
41 fftInput = new double[m_lengthFIRFFT]; | 43 fftInput = new double[m_lengthFIRFFT]; |
42 fftCoefficients = new double[m_lengthFIRFFT]; | 44 fftCoefficients = new double[m_lengthFIRFFT]; |
43 fftReal1 = new double[m_lengthFIRFFT]; | 45 fftReal1 = new double[m_lengthFIRFFT]; |
55 } | 57 } |
56 | 58 |
57 void | 59 void |
58 FIRFilter::process(const float* input, const float* coefficients, float* output) | 60 FIRFilter::process(const float* input, const float* coefficients, float* output) |
59 { | 61 { |
62 //Copy to same length FFT buffers | |
60 for(int i = 0; i < m_lengthFIRFFT; i++){ | 63 for(int i = 0; i < m_lengthFIRFFT; i++){ |
61 fftInput[i] = i < m_lengthInput ? input[i] : 0.0; | 64 fftInput[i] = i < m_lengthInput ? input[i] : 0.0; |
62 fftCoefficients[i] = i < m_numberOfCoefficients ? coefficients[i] : 0.0; | 65 fftCoefficients[i] = i < m_numberOfCoefficients ? coefficients[i] : 0.0; |
63 } | 66 } |
64 | 67 |
65 FFT::forward(m_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); | 68 FFT::forward(m_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); |
66 FFT::forward(m_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); | 69 FFT::forward(m_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); |
67 | 70 |
71 //Multiply FFT coefficients. Multiplication in freq domain is convolution in time domain. | |
68 for (int i = 0; i < m_lengthFIRFFT; i++){ | 72 for (int i = 0; i < m_lengthFIRFFT; i++){ |
69 fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); | 73 fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); |
70 fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); | 74 fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); |
71 } | 75 } |
72 FFT::inverse(m_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); | 76 FFT::inverse(m_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); |
73 | 77 |
78 //copy to output | |
74 for (int i = 0; i < m_lengthInput; i++){ | 79 for (int i = 0; i < m_lengthInput; i++){ |
75 output[i] = fftOutputReal[i]; | 80 output[i] = fftOutputReal[i]; |
76 } | 81 } |
77 } | 82 } |
78 | 83 |
84 //remove memory allocations | |
79 void | 85 void |
80 FIRFilter::cleanup() | 86 FIRFilter::cleanup() |
81 { | 87 { |
82 delete []fftInput; | 88 delete []fftInput; |
83 delete []fftCoefficients; | 89 delete []fftCoefficients; |