comparison data/fft/FFTFileCache.cpp @ 408:115f60df1e4d

* Speed up spectrogram painting by releasing mutex in FFTDataServer while calculating data prior to writing it, and by adding whole-column value query methods to FFT objects * Add paint cache to Thumbwheel -- repaints of this widget were slowing down the whole spectrogram repaint * More uses of MutexLocker (named and with debug) and more profile points * Make startup much quicker some of the time, with OSC server in place
author Chris Cannam
date Thu, 08 May 2008 14:46:22 +0000
parents 7cc6b7b0d819
children 3e0f1f7bec85
comparison
equal deleted inserted replaced
407:88ad01799040 408:115f60df1e4d
16 #include "FFTFileCache.h" 16 #include "FFTFileCache.h"
17 17
18 #include "fileio/MatrixFile.h" 18 #include "fileio/MatrixFile.h"
19 19
20 #include "base/Profiler.h" 20 #include "base/Profiler.h"
21 #include "base/Thread.h"
21 22
22 #include <iostream> 23 #include <iostream>
23
24 #include <QMutexLocker>
25 24
26 25
27 // The underlying matrix has height (m_height * 2 + 1). In each 26 // The underlying matrix has height (m_height * 2 + 1). In each
28 // column we store magnitude at [0], [2] etc and phase at [1], [3] 27 // column we store magnitude at [0], [2] etc and phase at [1], [3]
29 // etc, and then store the normalization factor (maximum magnitude) at 28 // etc, and then store the normalization factor (maximum magnitude) at
67 } 66 }
68 67
69 void 68 void
70 FFTFileCache::resize(size_t width, size_t height) 69 FFTFileCache::resize(size_t width, size_t height)
71 { 70 {
72 QMutexLocker locker(&m_writeMutex); 71 MutexLocker locker(&m_writeMutex, "FFTFileCache::resize::m_writeMutex");
73 72
74 m_mfc->resize(width, height * 2 + m_factorSize); 73 m_mfc->resize(width, height * 2 + m_factorSize);
75 if (m_readbuf) { 74 if (m_readbuf) {
76 delete[] m_readbuf; 75 delete[] m_readbuf;
77 m_readbuf = 0; 76 m_readbuf = 0;
161 160
162 case Rectangular: 161 case Rectangular:
163 { 162 {
164 float real, imag; 163 float real, imag;
165 getValuesAt(x, y, real, imag); 164 getValuesAt(x, y, real, imag);
166 value = princargf(atan2f(imag, real)); 165 value = atan2f(imag, real);
167 break; 166 break;
168 } 167 }
169 168
170 case Polar: 169 case Polar:
171 value = getFromReadBufStandard(x, y * 2 + 1); 170 value = getFromReadBufStandard(x, y * 2 + 1);
201 } 200 }
202 201
203 void 202 void
204 FFTFileCache::setColumnAt(size_t x, float *mags, float *phases, float factor) 203 FFTFileCache::setColumnAt(size_t x, float *mags, float *phases, float factor)
205 { 204 {
206 QMutexLocker locker(&m_writeMutex); 205 MutexLocker locker(&m_writeMutex, "FFTFileCache::setColumnAt::m_writeMutex");
207 206
208 size_t h = getHeight(); 207 size_t h = getHeight();
209 208
210 switch (m_storageType) { 209 switch (m_storageType) {
211 210
241 } 240 }
242 241
243 void 242 void
244 FFTFileCache::setColumnAt(size_t x, float *real, float *imag) 243 FFTFileCache::setColumnAt(size_t x, float *real, float *imag)
245 { 244 {
246 QMutexLocker locker(&m_writeMutex); 245 MutexLocker locker(&m_writeMutex, "FFTFileCache::setColumnAt::m_writeMutex");
247 246
248 size_t h = getHeight(); 247 size_t h = getHeight();
249 248
250 float factor = 0.0f; 249 float factor = 0.0f;
251 250
256 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 255 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
257 if (mag > factor) factor = mag; 256 if (mag > factor) factor = mag;
258 } 257 }
259 for (size_t y = 0; y < h; ++y) { 258 for (size_t y = 0; y < h; ++y) {
260 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 259 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
261 float phase = princargf(atan2f(imag[y], real[y])); 260 float phase = atan2f(imag[y], real[y]);
262 ((uint16_t *)m_writebuf)[y * 2] = uint16_t((mag / factor) * 65535.0); 261 ((uint16_t *)m_writebuf)[y * 2] = uint16_t((mag / factor) * 65535.0);
263 ((uint16_t *)m_writebuf)[y * 2 + 1] = uint16_t(int16_t((phase * 32767) / M_PI)); 262 ((uint16_t *)m_writebuf)[y * 2 + 1] = uint16_t(int16_t((phase * 32767) / M_PI));
264 } 263 }
265 break; 264 break;
266 265
276 case Polar: 275 case Polar:
277 for (size_t y = 0; y < h; ++y) { 276 for (size_t y = 0; y < h; ++y) {
278 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 277 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
279 if (mag > factor) factor = mag; 278 if (mag > factor) factor = mag;
280 ((float *)m_writebuf)[y * 2] = mag; 279 ((float *)m_writebuf)[y * 2] = mag;
281 float phase = princargf(atan2f(imag[y], real[y])); 280 float phase = atan2f(imag[y], real[y]);
282 ((float *)m_writebuf)[y * 2 + 1] = phase; 281 ((float *)m_writebuf)[y * 2 + 1] = phase;
283 } 282 }
284 break; 283 break;
285 } 284 }
286 285