comparison plugins/AdaptiveSpectrogram.h @ 107:07f92bbe68d1

* Use a Window object instead of working it out "by hand"
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 13 May 2009 11:23:00 +0000
parents 35f2138c6891
children 42e4f785a636
comparison
equal deleted inserted replaced
106:35f2138c6891 107:07f92bbe68d1
13 #include <vamp-sdk/Plugin.h> 13 #include <vamp-sdk/Plugin.h>
14 #include <cmath> 14 #include <cmath>
15 #include <vector> 15 #include <vector>
16 16
17 #include <dsp/transforms/FFT.h>//!!! 17 #include <dsp/transforms/FFT.h>//!!!
18 #include <base/Window.h>
18 19
19 #include "thread/Thread.h" 20 #include "thread/Thread.h"
20 21
21 class AdaptiveSpectrogram : public Vamp::Plugin 22 class AdaptiveSpectrogram : public Vamp::Plugin
22 { 23 {
113 }; 114 };
114 115
115 class FFTThread : public AsynchronousTask 116 class FFTThread : public AsynchronousTask
116 { 117 {
117 public: 118 public:
118 FFTThread(int w) { 119 FFTThread(int w) :
120 m_window(HanningWindow, w) {
119 m_w = w; 121 m_w = w;
120 m_fft = new FFTReal(m_w); 122 m_fft = new FFTReal(m_w);
121 m_rin = new double[m_w]; 123 m_rin = new double[m_w];
122 m_rout = new double[m_w]; 124 m_rout = new double[m_w];
123 m_iout = new double[m_w]; 125 m_iout = new double[m_w];
144 awaitTask(); 146 awaitTask();
145 } 147 }
146 148
147 protected: 149 protected:
148 void performTask() { 150 void performTask() {
149
150 //!!! use window object
151
152 for (int i = 0; i < m_maxwid / m_w; ++i) { 151 for (int i = 0; i < m_maxwid / m_w; ++i) {
153 int origin = m_maxwid/4 - m_w/4; // for 50% overlap 152 int origin = m_maxwid/4 - m_w/4; // for 50% overlap
154 for (int j = 0; j < m_w; ++j) { 153 for (int j = 0; j < m_w; ++j) {
155 double mul = 0.50 - 0.50 * cos((2 * M_PI * j) / m_w); 154 m_rin[j] = m_in[j];
156 m_rin[j] = m_in[origin + i * m_w/2 + j] * mul;
157 } 155 }
156 m_window.cut(m_rin);
158 m_fft->process(false, m_rin, m_rout, m_iout); 157 m_fft->process(false, m_rin, m_rout, m_iout);
159 for (int j = 0; j < m_w/2; ++j) { 158 for (int j = 0; j < m_w/2; ++j) {
160 int k = j+1; // include Nyquist but not DC 159 int k = j+1; // include Nyquist but not DC
161 double mag = sqrt(m_rout[k] * m_rout[k] + 160 double mag = sqrt(m_rout[k] * m_rout[k] +
162 m_iout[k] * m_iout[k]); 161 m_iout[k] * m_iout[k]);
165 } 164 }
166 } 165 }
167 } 166 }
168 167
169 private: 168 private:
169 Window<double> m_window;
170 FFTReal *m_fft; 170 FFTReal *m_fft;
171 const float *m_in; 171 const float *m_in;
172 double *m_rin; 172 double *m_rin;
173 double *m_rout; 173 double *m_rout;
174 double *m_iout; 174 double *m_iout;