Mercurial > hg > vamp-tempogram
comparison FIRFilter.cpp @ 7:21147df9cb2d
* Error when deleting Spectrogram object in Tempogram::getRemainingFeatures().
* Moved Spectrogram computation into own class.
| author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
|---|---|
| date | Thu, 07 Aug 2014 16:21:21 +0100 |
| parents | 597f033fa7a2 |
| children | 4e429b9f2b4d |
comparison
equal
deleted
inserted
replaced
| 6:14a143a2c4c9 | 7:21147df9cb2d |
|---|---|
| 5 // Created by Carl Bussey on 25/06/2014. | 5 // Created by Carl Bussey on 25/06/2014. |
| 6 // Copyright (c) 2014 Carl Bussey. All rights reserved. | 6 // Copyright (c) 2014 Carl Bussey. All rights reserved. |
| 7 // | 7 // |
| 8 | 8 |
| 9 #include "FIRFilter.h" | 9 #include "FIRFilter.h" |
| 10 #include <cmath> | 10 |
| 11 #include <vamp-sdk/FFT.h> | |
| 12 #include <assert.h> | |
| 13 #include <iostream> | |
| 14 using namespace std; | 11 using namespace std; |
| 15 | |
| 16 using Vamp::FFT; | 12 using Vamp::FFT; |
| 17 | 13 |
| 18 FIRFilter::FIRFilter(const unsigned int lengthInput, const unsigned int numberOfCoefficients) : | 14 FIRFilter::FIRFilter(const unsigned int lengthInput, const unsigned int numberOfCoefficients) : |
| 19 _lengthInput(lengthInput), | 15 _lengthInput(lengthInput), |
| 20 _numberOfCoefficients(numberOfCoefficients), | 16 _numberOfCoefficients(numberOfCoefficients), |
| 59 } | 55 } |
| 60 | 56 |
| 61 void | 57 void |
| 62 FIRFilter::process(const float* input, const float* coefficients, float* output) | 58 FIRFilter::process(const float* input, const float* coefficients, float* output) |
| 63 { | 59 { |
| 64 float max = 0; | 60 for(int i = 0; i < _lengthFIRFFT; i++){ |
| 65 for(int i = 0; i < _lengthInput; i++){ | 61 fftInput[i] = i < _lengthInput ? input[i] : 0.0; |
| 66 fftInput[i] = input[i]; | 62 fftCoefficients[i] = i < _numberOfCoefficients ? coefficients[i] : 0.0; |
| 67 max = max > fftInput[i] ? max : fftInput[i]; | |
| 68 //cout << fftInput[i] << endl; | |
| 69 } | |
| 70 //cout << max << endl; | |
| 71 for(int i = 0; i < _numberOfCoefficients; i++){ | |
| 72 fftCoefficients[i] = coefficients[i]; | |
| 73 //cout << fftCoefficients[i] << endl; | |
| 74 } | 63 } |
| 75 | 64 |
| 76 FFT::forward(_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); | 65 FFT::forward(_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); |
| 77 FFT::forward(_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); | 66 FFT::forward(_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); |
| 67 | |
| 78 for (int i = 0; i < _lengthFIRFFT; i++){ | 68 for (int i = 0; i < _lengthFIRFFT; i++){ |
| 79 fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); | 69 fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); |
| 80 fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); | 70 fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); |
| 81 } | 71 } |
| 82 FFT::inverse(_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); | 72 FFT::inverse(_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); |
| 83 | 73 |
| 84 max = 0; | 74 for (int i = 0; i < _lengthInput; i++){ |
| 85 for(int i = 0; i < _lengthInput; i++){ | |
| 86 output[i] = fftOutputReal[i]; | 75 output[i] = fftOutputReal[i]; |
| 87 max = max > output[i] ? max : output[i]; | |
| 88 } | 76 } |
| 89 } | 77 } |
| 90 | 78 |
| 91 void | 79 void |
| 92 FIRFilter::cleanup() | 80 FIRFilter::cleanup() |
| 93 { | 81 { |
| 94 delete []fftInput; | 82 delete []fftInput; |
| 95 fftInput = NULL; | |
| 96 delete []fftCoefficients; | 83 delete []fftCoefficients; |
| 97 fftCoefficients = NULL; | |
| 98 delete []fftReal1; | 84 delete []fftReal1; |
| 99 fftReal1 = NULL; | |
| 100 delete []fftImag1; | 85 delete []fftImag1; |
| 101 fftImag1 = NULL; | |
| 102 delete []fftReal2; | 86 delete []fftReal2; |
| 103 fftReal2 = NULL; | |
| 104 delete []fftImag2; | 87 delete []fftImag2; |
| 105 fftImag2 = NULL; | |
| 106 delete []fftFilteredReal; | 88 delete []fftFilteredReal; |
| 107 fftFilteredReal = NULL; | |
| 108 delete []fftFilteredImag; | 89 delete []fftFilteredImag; |
| 109 fftFilteredImag = NULL; | |
| 110 delete []fftOutputReal; | 90 delete []fftOutputReal; |
| 111 fftOutputReal = NULL; | |
| 112 delete []fftOutputImag; | 91 delete []fftOutputImag; |
| 113 fftOutputImag = NULL; | 92 fftInput = fftCoefficients = fftReal1 = fftImag1 = fftReal2 = fftImag2 = fftFilteredReal = fftFilteredImag = fftOutputReal = fftOutputImag = NULL; |
| 114 } | 93 } |
