Mercurial > hg > vamp-tempogram
comparison Spectrogram.cpp @ 11:09fb76606b2b
* Removed many unnecessary heap allocations with objects
author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
---|---|
date | Wed, 13 Aug 2014 10:45:46 +0100 |
parents | be59b4a73f49 |
children | d58409ecd720 |
comparison
equal
deleted
inserted
replaced
9:be59b4a73f49 | 11:09fb76606b2b |
---|---|
8 | 8 |
9 #include "Spectrogram.h" | 9 #include "Spectrogram.h" |
10 using namespace std; | 10 using namespace std; |
11 using Vamp::FFT; | 11 using Vamp::FFT; |
12 | 12 |
13 Spectrogram::Spectrogram(unsigned int inputLength, unsigned int windowLength, unsigned int fftLength, unsigned int hopSize) : | 13 SpectrogramProcessor::SpectrogramProcessor(unsigned int inputLength, unsigned int windowLength, unsigned int fftLength, unsigned int hopSize) : |
14 m_inputLength(inputLength), | 14 m_inputLength(inputLength), |
15 m_windowLength(windowLength), | 15 m_windowLength(windowLength), |
16 m_fftLength(fftLength), | 16 m_fftLength(fftLength), |
17 m_hopSize(hopSize), | 17 m_hopSize(hopSize), |
18 m_numberOfOutputBins(ceil(fftLength/2) + 1), | 18 m_numberOfOutputBins(ceil(fftLength/2) + 1), |
21 fftOutputImag(NULL) | 21 fftOutputImag(NULL) |
22 { | 22 { |
23 initialise(); | 23 initialise(); |
24 } | 24 } |
25 | 25 |
26 Spectrogram::~Spectrogram(){ | 26 SpectrogramProcessor::~SpectrogramProcessor(){ |
27 cleanup(); | 27 cleanup(); |
28 } | 28 } |
29 | 29 |
30 void Spectrogram::initialise(){ | 30 void SpectrogramProcessor::initialise(){ |
31 fftInput = new double [m_fftLength]; | 31 fftInput = new double [m_fftLength]; |
32 fftOutputReal = new double [m_fftLength]; | 32 fftOutputReal = new double [m_fftLength]; |
33 fftOutputImag = new double [m_fftLength]; | 33 fftOutputImag = new double [m_fftLength]; |
34 | 34 |
35 int numberOfBlocks = ceil(m_inputLength/m_hopSize) + 2*(ceil(m_windowLength/m_hopSize)-1); //The last term corresponds to overlaps at the beginning and end with padded zeros. I.e., if m_hopSize = m_windowLength/2, there'll be 1 overlap at each end. If m_hopSize = m_windowLength/4, there'll be 3 overlaps at each end, etc... | 35 int numberOfBlocks = ceil(m_inputLength/m_hopSize) + 2*(ceil(m_windowLength/m_hopSize)-1); //The last term corresponds to overlaps at the beginning and end with padded zeros. I.e., if m_hopSize = m_windowLength/2, there'll be 1 overlap at each end. If m_hopSize = m_windowLength/4, there'll be 3 overlaps at each end, etc... |
36 spectrogramOutput = vector< vector<float> >(m_numberOfOutputBins, vector<float>(numberOfBlocks)); | 36 spectrogramOutput = vector< vector<float> >(m_numberOfOutputBins, vector<float>(numberOfBlocks)); |
37 } | 37 } |
38 | 38 |
39 void Spectrogram::cleanup(){ | 39 void SpectrogramProcessor::cleanup(){ |
40 delete []fftInput; | 40 delete []fftInput; |
41 delete []fftOutputReal; | 41 delete []fftOutputReal; |
42 delete []fftOutputImag; | 42 delete []fftOutputImag; |
43 | 43 |
44 fftInput = fftOutputReal = fftOutputImag = NULL; | 44 fftInput = fftOutputReal = fftOutputImag = NULL; |
45 } | 45 } |
46 | 46 |
47 //process method | 47 //process method |
48 vector< vector<float> > Spectrogram::audioToMagnitudeSpectrogram(const float * const input, const float * window){ | 48 vector< vector<float> > SpectrogramProcessor::process(const float * const input, const float * window){ |
49 | 49 |
50 int readPointerBeginIndex = m_hopSize-m_windowLength; | 50 int readPointerBeginIndex = m_hopSize-m_windowLength; |
51 int writeBlockPointer = 0; | 51 int writeBlockPointer = 0; |
52 | 52 |
53 while(readPointerBeginIndex < m_inputLength){ | 53 while(readPointerBeginIndex < m_inputLength){ |