Mercurial > hg > qm-vamp-plugins
changeset 106:35f2138c6891
* Update to new FFT api
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 13 May 2009 09:19:30 +0000 |
parents | abbc482aaad2 |
children | 07f92bbe68d1 |
files | plugins/AdaptiveSpectrogram.cpp plugins/AdaptiveSpectrogram.h |
diffstat | 2 files changed, 33 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/AdaptiveSpectrogram.cpp Tue May 12 21:05:44 2009 +0000 +++ b/plugins/AdaptiveSpectrogram.cpp Wed May 13 09:19:30 2009 +0000 @@ -42,8 +42,8 @@ } m_cutThreads.clear(); - for (int i = 0; i < m_fftThreads.size(); ++i) { - delete m_fftThreads[i]; + for (FFTMap::iterator i = m_fftThreads.begin(); i != m_fftThreads.end(); ++i) { + delete i->second; } m_fftThreads.clear(); } @@ -102,10 +102,6 @@ if (channels < getMinChannelCount() || channels > getMaxChannelCount()) return false; - while (m_fftThreads.size() < (m_n + 1)) { - m_fftThreads.push_back(new FFTThread()); - } - return true; } @@ -229,18 +225,18 @@ int index = 0; while (w <= maxwid) { - m_fftThreads[index]->calculate(inputBuffers[0], s, index, w, maxwid); + if (m_fftThreads.find(w) == m_fftThreads.end()) { + m_fftThreads[w] = new FFTThread(w); + } + m_fftThreads[w]->calculate(inputBuffers[0], s, index, maxwid); w *= 2; ++index; } w = minwid; - index = 0; - while (w <= maxwid) { - m_fftThreads[index]->await(); + m_fftThreads[w]->await(); w *= 2; - ++index; } m_first = true;//!!!
--- a/plugins/AdaptiveSpectrogram.h Tue May 12 21:05:44 2009 +0000 +++ b/plugins/AdaptiveSpectrogram.h Wed May 13 09:19:30 2009 +0000 @@ -115,15 +115,27 @@ class FFTThread : public AsynchronousTask { public: - FFTThread() { } - ~FFTThread() { } + FFTThread(int w) { + m_w = w; + m_fft = new FFTReal(m_w); + m_rin = new double[m_w]; + m_rout = new double[m_w]; + m_iout = new double[m_w]; + } + ~FFTThread() { + delete[] m_rin; + delete[] m_rout; + delete[] m_iout; + delete m_fft; + } + + int getW() const { return m_w; } void calculate(const float *timeDomain, Spectrograms &s, - int res, int width, int maxwidth) { + int res, int maxwidth) { m_in = timeDomain; m_s = &s; m_res = res; - m_w = width; m_maxwid = maxwidth; startTask(); } @@ -135,42 +147,39 @@ protected: void performTask() { - double *tmpin = new double[m_w]; - double *tmprout = new double[m_w]; - double *tmpiout = new double[m_w]; - //!!! use window object for (int i = 0; i < m_maxwid / m_w; ++i) { int origin = m_maxwid/4 - m_w/4; // for 50% overlap for (int j = 0; j < m_w; ++j) { double mul = 0.50 - 0.50 * cos((2 * M_PI * j) / m_w); - tmpin[j] = m_in[origin + i * m_w/2 + j] * mul; + m_rin[j] = m_in[origin + i * m_w/2 + j] * mul; } - FFT::process(m_w, false, tmpin, 0, tmprout, tmpiout); + m_fft->process(false, m_rin, m_rout, m_iout); for (int j = 0; j < m_w/2; ++j) { int k = j+1; // include Nyquist but not DC - double mag = sqrt(tmprout[k] * tmprout[k] + - tmpiout[k] * tmpiout[k]); + double mag = sqrt(m_rout[k] * m_rout[k] + + m_iout[k] * m_iout[k]); double scaled = mag / (m_w/2); m_s->spectrograms[m_res]->data[i][j] = scaled; } } - - delete[] tmpin; - delete[] tmprout; - delete[] tmpiout; } private: + FFTReal *m_fft; const float *m_in; + double *m_rin; + double *m_rout; + double *m_iout; Spectrograms *m_s; int m_res; int m_w; int m_maxwid; }; - std::vector<FFTThread *> m_fftThreads; + typedef std::map<int, FFTThread *> FFTMap; + FFTMap m_fftThreads; class CutThread : public AsynchronousTask {