Mercurial > hg > qm-vamp-plugins
comparison plugins/AdaptiveSpectrogram.h @ 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 |
comparison
equal
deleted
inserted
replaced
105:abbc482aaad2 | 106:35f2138c6891 |
---|---|
113 }; | 113 }; |
114 | 114 |
115 class FFTThread : public AsynchronousTask | 115 class FFTThread : public AsynchronousTask |
116 { | 116 { |
117 public: | 117 public: |
118 FFTThread() { } | 118 FFTThread(int w) { |
119 ~FFTThread() { } | 119 m_w = w; |
120 m_fft = new FFTReal(m_w); | |
121 m_rin = new double[m_w]; | |
122 m_rout = new double[m_w]; | |
123 m_iout = new double[m_w]; | |
124 } | |
125 ~FFTThread() { | |
126 delete[] m_rin; | |
127 delete[] m_rout; | |
128 delete[] m_iout; | |
129 delete m_fft; | |
130 } | |
131 | |
132 int getW() const { return m_w; } | |
120 | 133 |
121 void calculate(const float *timeDomain, Spectrograms &s, | 134 void calculate(const float *timeDomain, Spectrograms &s, |
122 int res, int width, int maxwidth) { | 135 int res, int maxwidth) { |
123 m_in = timeDomain; | 136 m_in = timeDomain; |
124 m_s = &s; | 137 m_s = &s; |
125 m_res = res; | 138 m_res = res; |
126 m_w = width; | |
127 m_maxwid = maxwidth; | 139 m_maxwid = maxwidth; |
128 startTask(); | 140 startTask(); |
129 } | 141 } |
130 | 142 |
131 void await() { | 143 void await() { |
132 awaitTask(); | 144 awaitTask(); |
133 } | 145 } |
134 | 146 |
135 protected: | 147 protected: |
136 void performTask() { | 148 void performTask() { |
137 | |
138 double *tmpin = new double[m_w]; | |
139 double *tmprout = new double[m_w]; | |
140 double *tmpiout = new double[m_w]; | |
141 | 149 |
142 //!!! use window object | 150 //!!! use window object |
143 | 151 |
144 for (int i = 0; i < m_maxwid / m_w; ++i) { | 152 for (int i = 0; i < m_maxwid / m_w; ++i) { |
145 int origin = m_maxwid/4 - m_w/4; // for 50% overlap | 153 int origin = m_maxwid/4 - m_w/4; // for 50% overlap |
146 for (int j = 0; j < m_w; ++j) { | 154 for (int j = 0; j < m_w; ++j) { |
147 double mul = 0.50 - 0.50 * cos((2 * M_PI * j) / m_w); | 155 double mul = 0.50 - 0.50 * cos((2 * M_PI * j) / m_w); |
148 tmpin[j] = m_in[origin + i * m_w/2 + j] * mul; | 156 m_rin[j] = m_in[origin + i * m_w/2 + j] * mul; |
149 } | 157 } |
150 FFT::process(m_w, false, tmpin, 0, tmprout, tmpiout); | 158 m_fft->process(false, m_rin, m_rout, m_iout); |
151 for (int j = 0; j < m_w/2; ++j) { | 159 for (int j = 0; j < m_w/2; ++j) { |
152 int k = j+1; // include Nyquist but not DC | 160 int k = j+1; // include Nyquist but not DC |
153 double mag = sqrt(tmprout[k] * tmprout[k] + | 161 double mag = sqrt(m_rout[k] * m_rout[k] + |
154 tmpiout[k] * tmpiout[k]); | 162 m_iout[k] * m_iout[k]); |
155 double scaled = mag / (m_w/2); | 163 double scaled = mag / (m_w/2); |
156 m_s->spectrograms[m_res]->data[i][j] = scaled; | 164 m_s->spectrograms[m_res]->data[i][j] = scaled; |
157 } | 165 } |
158 } | 166 } |
159 | |
160 delete[] tmpin; | |
161 delete[] tmprout; | |
162 delete[] tmpiout; | |
163 } | 167 } |
164 | 168 |
165 private: | 169 private: |
170 FFTReal *m_fft; | |
166 const float *m_in; | 171 const float *m_in; |
172 double *m_rin; | |
173 double *m_rout; | |
174 double *m_iout; | |
167 Spectrograms *m_s; | 175 Spectrograms *m_s; |
168 int m_res; | 176 int m_res; |
169 int m_w; | 177 int m_w; |
170 int m_maxwid; | 178 int m_maxwid; |
171 }; | 179 }; |
172 | 180 |
173 std::vector<FFTThread *> m_fftThreads; | 181 typedef std::map<int, FFTThread *> FFTMap; |
182 FFTMap m_fftThreads; | |
174 | 183 |
175 class CutThread : public AsynchronousTask | 184 class CutThread : public AsynchronousTask |
176 { | 185 { |
177 public: | 186 public: |
178 CutThread(const AdaptiveSpectrogram *as) : m_as(as), m_result(0) { } | 187 CutThread(const AdaptiveSpectrogram *as) : m_as(as), m_result(0) { } |