Mercurial > hg > qm-vamp-plugins
comparison plugins/AdaptiveSpectrogram.h @ 109:0dd97d053053
* tidy, make threading a parameter, fix offset error in fft input
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 13 May 2009 17:41:41 +0000 |
parents | 42e4f785a636 |
children | be419e04899a |
comparison
equal
deleted
inserted
replaced
108:42e4f785a636 | 109:0dd97d053053 |
---|---|
52 FeatureSet getRemainingFeatures(); | 52 FeatureSet getRemainingFeatures(); |
53 | 53 |
54 protected: | 54 protected: |
55 int m_w; | 55 int m_w; |
56 int m_n; | 56 int m_n; |
57 bool m_threaded; | |
57 | 58 |
58 struct Spectrogram | 59 struct Spectrogram |
59 { | 60 { |
60 int resolution; | 61 int resolution; |
61 int width; | 62 int width; |
131 delete m_fft; | 132 delete m_fft; |
132 } | 133 } |
133 | 134 |
134 int getW() const { return m_w; } | 135 int getW() const { return m_w; } |
135 | 136 |
136 void calculate(const float *timeDomain, Spectrograms &s, | 137 void startCalculation(const float *timeDomain, Spectrograms &s, |
137 int res, int maxwidth) { | 138 int res, int maxwidth) { |
139 setParameters(timeDomain, s, res, maxwidth); | |
140 startTask(); | |
141 } | |
142 | |
143 void await() { | |
144 awaitTask(); | |
145 } | |
146 | |
147 void setParameters(const float *timeDomain, Spectrograms &s, | |
148 int res, int maxwidth) { | |
138 m_in = timeDomain; | 149 m_in = timeDomain; |
139 m_s = &s; | 150 m_s = &s; |
140 m_res = res; | 151 m_res = res; |
141 m_maxwid = maxwidth; | 152 m_maxwid = maxwidth; |
142 startTask(); | 153 } |
143 } | 154 |
144 | |
145 void await() { | |
146 awaitTask(); | |
147 } | |
148 | |
149 protected: | |
150 void performTask() { | 155 void performTask() { |
151 for (int i = 0; i < m_maxwid / m_w; ++i) { | 156 for (int i = 0; i < m_maxwid / m_w; ++i) { |
152 int origin = m_maxwid/4 - m_w/4; // for 50% overlap | 157 int origin = m_maxwid/4 - m_w/4; // for 50% overlap |
153 for (int j = 0; j < m_w; ++j) { | 158 for (int j = 0; j < m_w; ++j) { |
154 m_rin[j] = m_in[j]; | 159 m_rin[j] = m_in[origin + i * m_w/2 + j]; |
155 } | 160 } |
156 m_window.cut(m_rin); | 161 m_window.cut(m_rin); |
157 m_fft->process(false, m_rin, m_rout, m_iout); | 162 m_fft->process(false, m_rin, m_rout, m_iout); |
158 for (int j = 0; j < m_w/2; ++j) { | 163 for (int j = 0; j < m_w/2; ++j) { |
159 int k = j+1; // include Nyquist but not DC | 164 int k = j+1; // include Nyquist but not DC |
214 int m_y; | 219 int m_y; |
215 int m_h; | 220 int m_h; |
216 Cutting *m_result; | 221 Cutting *m_result; |
217 }; | 222 }; |
218 | 223 |
219 mutable std::vector<CutThread *> m_cutThreads;//!!! mutable blargh | 224 mutable std::vector<CutThread *> m_cutThreads; |
220 | 225 mutable bool m_threadsInUse; |
221 ///!!! Mutex m_threadMutex; | |
222 mutable bool m_first; //!!! gross | |
223 | 226 |
224 double xlogx(double x) const { | 227 double xlogx(double x) const { |
225 if (x == 0.0) return 0.0; | 228 if (x == 0.0) return 0.0; |
226 else return x * log(x); | 229 else return x * log(x); |
227 } | 230 } |