Mercurial > hg > svgui
comparison layer/SpectrogramLayer.h @ 110:f262aa8973e3
* Update SpectrogramLayer to use new FFTDataServer
author | Chris Cannam |
---|---|
date | Tue, 27 Jun 2006 19:18:42 +0000 |
parents | 12340cb6e6cb |
children | 7a23edd831cb |
comparison
equal
deleted
inserted
replaced
109:12340cb6e6cb | 110:f262aa8973e3 |
---|---|
26 #include <QMutex> | 26 #include <QMutex> |
27 #include <QWaitCondition> | 27 #include <QWaitCondition> |
28 #include <QImage> | 28 #include <QImage> |
29 #include <QPixmap> | 29 #include <QPixmap> |
30 | 30 |
31 #include <fftw3.h> | |
32 | |
33 class View; | 31 class View; |
34 class QPainter; | 32 class QPainter; |
35 class QImage; | 33 class QImage; |
36 class QPixmap; | 34 class QPixmap; |
37 class QTimer; | 35 class QTimer; |
38 class FFTCacheBase; | 36 class FFTDataServer; |
39 | 37 |
40 /** | 38 /** |
41 * SpectrogramLayer represents waveform data (obtained from a | 39 * SpectrogramLayer represents waveform data (obtained from a |
42 * DenseTimeValueModel) in spectrogram form. | 40 * DenseTimeValueModel) in spectrogram form. |
43 */ | 41 */ |
101 | 99 |
102 void setZeroPadLevel(size_t level); | 100 void setZeroPadLevel(size_t level); |
103 size_t getZeroPadLevel() const; | 101 size_t getZeroPadLevel() const; |
104 | 102 |
105 /** | 103 /** |
106 * Set the gain multiplier for sample values in this view prior to | 104 * Set the gain multiplier for sample values in this view. |
107 * FFT calculation. | |
108 * | |
109 * The default is 1.0. | 105 * The default is 1.0. |
110 */ | 106 */ |
111 void setGain(float gain); | 107 void setGain(float gain); |
112 float getGain() const; | 108 float getGain() const; |
113 | 109 |
114 /** | 110 /** |
115 * Set the threshold for sample values to be shown in the FFT, | 111 * Set the threshold for sample values to qualify for being shown |
116 * in voltage units. | 112 * in the FFT, in voltage units. |
117 * | 113 * |
118 * The default is 0.0. | 114 * The default is 0.0. |
119 */ | 115 */ |
120 void setThreshold(float threshold); | 116 void setThreshold(float threshold); |
121 float getThreshold() const; | 117 float getThreshold() const; |
208 void cacheInvalid(size_t startFrame, size_t endFrame); | 204 void cacheInvalid(size_t startFrame, size_t endFrame); |
209 | 205 |
210 void fillTimerTimedOut(); | 206 void fillTimerTimedOut(); |
211 | 207 |
212 protected: | 208 protected: |
213 typedef float fftsample; | |
214 | |
215 const DenseTimeValueModel *m_model; // I do not own this | 209 const DenseTimeValueModel *m_model; // I do not own this |
216 | 210 |
217 int m_channel; | 211 int m_channel; |
218 size_t m_windowSize; | 212 size_t m_windowSize; |
219 WindowType m_windowType; | 213 WindowType m_windowType; |
248 private: | 242 private: |
249 QColor m_colours[256]; | 243 QColor m_colours[256]; |
250 }; | 244 }; |
251 | 245 |
252 ColourMap m_colourMap; | 246 ColourMap m_colourMap; |
253 FFTCacheBase *m_cache; | 247 |
254 FFTCacheBase *m_writeCache; | 248 FFTDataServer *m_fftServer; |
255 bool m_cacheInvalid; | 249 void getFFTServer(); |
256 | |
257 class CacheFillThread : public Thread | |
258 { | |
259 public: | |
260 CacheFillThread(SpectrogramLayer &layer) : | |
261 m_layer(layer), m_fillExtent(0) { } | |
262 | |
263 size_t getFillExtent() const { return m_fillExtent; } | |
264 size_t getFillCompletion() const { return m_fillCompletion; } | |
265 virtual void run(); | |
266 | |
267 protected: | |
268 SpectrogramLayer &m_layer; | |
269 size_t m_fillExtent; | |
270 size_t m_fillCompletion; | |
271 }; | |
272 | |
273 void fillCache(); | |
274 | 250 |
275 struct PixmapCache | 251 struct PixmapCache |
276 { | 252 { |
277 QPixmap pixmap; | 253 QPixmap pixmap; |
278 QRect validArea; | 254 QRect validArea; |
282 typedef std::map<const View *, PixmapCache> ViewPixmapCache; | 258 typedef std::map<const View *, PixmapCache> ViewPixmapCache; |
283 void invalidatePixmapCaches(); | 259 void invalidatePixmapCaches(); |
284 void invalidatePixmapCaches(size_t startFrame, size_t endFrame); | 260 void invalidatePixmapCaches(size_t startFrame, size_t endFrame); |
285 mutable ViewPixmapCache m_pixmapCaches; | 261 mutable ViewPixmapCache m_pixmapCaches; |
286 mutable QImage m_drawBuffer; | 262 mutable QImage m_drawBuffer; |
287 | 263 |
288 QWaitCondition m_condition; | |
289 mutable QMutex m_mutex; | |
290 | |
291 CacheFillThread *m_fillThread; | |
292 QTimer *m_updateTimer; | 264 QTimer *m_updateTimer; |
265 | |
293 mutable size_t m_candidateFillStartFrame; | 266 mutable size_t m_candidateFillStartFrame; |
294 size_t m_lastFillExtent; | 267 size_t m_lastFillExtent; |
295 bool m_exiting; | 268 bool m_exiting; |
296 | 269 |
297 void setColourmap(); | 270 void setColourmap(); |
298 void rotateColourmap(int distance); | 271 void rotateColourmap(int distance); |
299 | |
300 void fillCacheColumn(int column, | |
301 fftsample *inputBuffer, | |
302 fftwf_complex *outputBuffer, | |
303 fftwf_plan plan, | |
304 size_t windowSize, | |
305 size_t fftSize, | |
306 size_t windowIncrement, | |
307 float *workbuffer, | |
308 const Window<fftsample> &windower) | |
309 const; | |
310 | 272 |
311 static float calculateFrequency(size_t bin, | 273 static float calculateFrequency(size_t bin, |
312 size_t windowSize, | 274 size_t windowSize, |
313 size_t windowIncrement, | 275 size_t windowIncrement, |
314 size_t sampleRate, | 276 size_t sampleRate, |