Mercurial > hg > vamp-tempogram
comparison FIRFilter.cpp @ 8:4e429b9f2b4d
* Fixed memory leak bug. Issue with calculating size of spectrogram array.
* Fixed bug in Tempogram::reset() where specData wasn't reinitialised.
author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
---|---|
date | Thu, 07 Aug 2014 17:25:24 +0100 |
parents | 21147df9cb2d |
children | be59b4a73f49 |
comparison
equal
deleted
inserted
replaced
7:21147df9cb2d | 8:4e429b9f2b4d |
---|---|
10 | 10 |
11 using namespace std; | 11 using namespace std; |
12 using Vamp::FFT; | 12 using Vamp::FFT; |
13 | 13 |
14 FIRFilter::FIRFilter(const unsigned int lengthInput, const unsigned int numberOfCoefficients) : | 14 FIRFilter::FIRFilter(const unsigned int lengthInput, const unsigned int numberOfCoefficients) : |
15 _lengthInput(lengthInput), | 15 m_lengthInput(lengthInput), |
16 _numberOfCoefficients(numberOfCoefficients), | 16 m_numberOfCoefficients(numberOfCoefficients), |
17 fftInput(NULL), | 17 fftInput(NULL), |
18 fftCoefficients(NULL), | 18 fftCoefficients(NULL), |
19 fftReal1(NULL), | 19 fftReal1(NULL), |
20 fftImag1(NULL), | 20 fftImag1(NULL), |
21 fftReal2(NULL), | 21 fftReal2(NULL), |
34 } | 34 } |
35 | 35 |
36 void | 36 void |
37 FIRFilter::initialise() | 37 FIRFilter::initialise() |
38 { | 38 { |
39 _lengthFIRFFT = pow(2,(ceil(log2(_lengthInput+_numberOfCoefficients-1)))); | 39 m_lengthFIRFFT = pow(2,(ceil(log2(m_lengthInput+m_numberOfCoefficients-1)))); |
40 | 40 |
41 fftInput = new double[_lengthFIRFFT]; | 41 fftInput = new double[m_lengthFIRFFT]; |
42 fftCoefficients = new double[_lengthFIRFFT]; | 42 fftCoefficients = new double[m_lengthFIRFFT]; |
43 fftReal1 = new double[_lengthFIRFFT]; | 43 fftReal1 = new double[m_lengthFIRFFT]; |
44 fftImag1 = new double[_lengthFIRFFT]; | 44 fftImag1 = new double[m_lengthFIRFFT]; |
45 fftReal2 = new double[_lengthFIRFFT]; | 45 fftReal2 = new double[m_lengthFIRFFT]; |
46 fftImag2 = new double[_lengthFIRFFT]; | 46 fftImag2 = new double[m_lengthFIRFFT]; |
47 fftFilteredReal = new double[_lengthFIRFFT]; | 47 fftFilteredReal = new double[m_lengthFIRFFT]; |
48 fftFilteredImag = new double[_lengthFIRFFT]; | 48 fftFilteredImag = new double[m_lengthFIRFFT]; |
49 fftOutputReal = new double[_lengthFIRFFT]; | 49 fftOutputReal = new double[m_lengthFIRFFT]; |
50 fftOutputImag = new double[_lengthFIRFFT]; | 50 fftOutputImag = new double[m_lengthFIRFFT]; |
51 | 51 |
52 for(int i = 0; i < _lengthFIRFFT; i++){ | 52 for(int i = 0; i < m_lengthFIRFFT; i++){ |
53 fftInput[i] = fftCoefficients[i] = fftReal1[i] = fftImag1[i] = fftReal2[i] = fftImag2[i] = fftFilteredReal[i] = fftFilteredImag[i] = fftOutputReal[i] = fftOutputImag[i] = 0.0; | 53 fftInput[i] = fftCoefficients[i] = fftReal1[i] = fftImag1[i] = fftReal2[i] = fftImag2[i] = fftFilteredReal[i] = fftFilteredImag[i] = fftOutputReal[i] = fftOutputImag[i] = 0.0; |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 void | 57 void |
58 FIRFilter::process(const float* input, const float* coefficients, float* output) | 58 FIRFilter::process(const float* input, const float* coefficients, float* output) |
59 { | 59 { |
60 for(int i = 0; i < _lengthFIRFFT; i++){ | 60 for(int i = 0; i < m_lengthFIRFFT; i++){ |
61 fftInput[i] = i < _lengthInput ? input[i] : 0.0; | 61 fftInput[i] = i < m_lengthInput ? input[i] : 0.0; |
62 fftCoefficients[i] = i < _numberOfCoefficients ? coefficients[i] : 0.0; | 62 fftCoefficients[i] = i < m_numberOfCoefficients ? coefficients[i] : 0.0; |
63 } | 63 } |
64 | 64 |
65 FFT::forward(_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); | 65 FFT::forward(m_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); |
66 FFT::forward(_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); | 66 FFT::forward(m_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); |
67 | 67 |
68 for (int i = 0; i < _lengthFIRFFT; i++){ | 68 for (int i = 0; i < m_lengthFIRFFT; i++){ |
69 fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); | 69 fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); |
70 fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); | 70 fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); |
71 } | 71 } |
72 FFT::inverse(_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); | 72 FFT::inverse(m_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); |
73 | 73 |
74 for (int i = 0; i < _lengthInput; i++){ | 74 for (int i = 0; i < m_lengthInput; i++){ |
75 output[i] = fftOutputReal[i]; | 75 output[i] = fftOutputReal[i]; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void | 79 void |