comparison data/fft/FFTMemoryCache.h @ 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 824ee993ca8d
children 6066bde1c126
comparison
equal deleted inserted replaced
407:88ad01799040 408:115f60df1e4d
17 #define _FFT_MEMORY_CACHE_H_ 17 #define _FFT_MEMORY_CACHE_H_
18 18
19 #include "FFTCache.h" 19 #include "FFTCache.h"
20 20
21 #include "base/ResizeableBitset.h" 21 #include "base/ResizeableBitset.h"
22 #include "base/Profiler.h"
22 23
23 /** 24 /**
24 * In-memory FFT cache. For this we want to cache magnitude with 25 * In-memory FFT cache. For this we want to cache magnitude with
25 * enough resolution to have gain applied afterwards and determine 26 * enough resolution to have gain applied afterwards and determine
26 * whether something is a peak or not, and also cache phase rather 27 * whether something is a peak or not, and also cache phase rather
40 */ 41 */
41 42
42 class FFTMemoryCache : public FFTCache 43 class FFTMemoryCache : public FFTCache
43 { 44 {
44 public: 45 public:
45 enum StorageType {
46 Compact, // 16 bits normalized polar
47 Rectangular, // floating point real+imag
48 Polar // floating point mag+phase
49 };
50
51 FFTMemoryCache(StorageType storageType); // of size zero, call resize() before using 46 FFTMemoryCache(StorageType storageType); // of size zero, call resize() before using
52 virtual ~FFTMemoryCache(); 47 virtual ~FFTMemoryCache();
53 48
54 virtual size_t getWidth() const { return m_width; } 49 virtual size_t getWidth() const { return m_width; }
55 virtual size_t getHeight() const { return m_height; } 50 virtual size_t getHeight() const { return m_height; }
57 virtual void resize(size_t width, size_t height); 52 virtual void resize(size_t width, size_t height);
58 virtual void reset(); // zero-fill or 1-fill as appropriate without changing size 53 virtual void reset(); // zero-fill or 1-fill as appropriate without changing size
59 54
60 virtual float getMagnitudeAt(size_t x, size_t y) const { 55 virtual float getMagnitudeAt(size_t x, size_t y) const {
61 if (m_storageType == Rectangular) { 56 if (m_storageType == Rectangular) {
57 Profiler profiler("FFTMemoryCache::getMagnitudeAt: cart to polar");
62 return sqrt(m_freal[x][y] * m_freal[x][y] + 58 return sqrt(m_freal[x][y] * m_freal[x][y] +
63 m_fimag[x][y] * m_fimag[x][y]); 59 m_fimag[x][y] * m_fimag[x][y]);
64 } else { 60 } else {
65 return getNormalizedMagnitudeAt(x, y) * m_factor[x]; 61 return getNormalizedMagnitudeAt(x, y) * m_factor[x];
66 } 62 }
76 return m_factor[x]; 72 return m_factor[x];
77 } 73 }
78 74
79 virtual float getPhaseAt(size_t x, size_t y) const { 75 virtual float getPhaseAt(size_t x, size_t y) const {
80 if (m_storageType == Rectangular) { 76 if (m_storageType == Rectangular) {
77 Profiler profiler("FFTMemoryCache::getValuesAt: cart to polar");
81 return atan2f(m_fimag[x][y], m_freal[x][y]); 78 return atan2f(m_fimag[x][y], m_freal[x][y]);
82 } else if (m_storageType == Polar) { 79 } else if (m_storageType == Polar) {
83 return m_fphase[x][y]; 80 return m_fphase[x][y];
84 } else { 81 } else {
85 int16_t i = (int16_t)m_phase[x][y]; 82 int16_t i = (int16_t)m_phase[x][y];
90 virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const { 87 virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const {
91 if (m_storageType == Rectangular) { 88 if (m_storageType == Rectangular) {
92 real = m_freal[x][y]; 89 real = m_freal[x][y];
93 imag = m_fimag[x][y]; 90 imag = m_fimag[x][y];
94 } else { 91 } else {
92 Profiler profiler("FFTMemoryCache::getValuesAt: polar to cart");
95 float mag = getMagnitudeAt(x, y); 93 float mag = getMagnitudeAt(x, y);
96 float phase = getPhaseAt(x, y); 94 float phase = getPhaseAt(x, y);
97 real = mag * cosf(phase); 95 real = mag * cosf(phase);
98 imag = mag * sinf(phase); 96 imag = mag * sinf(phase);
99 } 97 }
107 105
108 virtual void setColumnAt(size_t x, float *reals, float *imags); 106 virtual void setColumnAt(size_t x, float *reals, float *imags);
109 107
110 static size_t getCacheSize(size_t width, size_t height, StorageType type); 108 static size_t getCacheSize(size_t width, size_t height, StorageType type);
111 109
110 virtual StorageType getStorageType() { return m_storageType; }
112 virtual Type getType() { return MemoryCache; } 111 virtual Type getType() { return MemoryCache; }
113 112
114 private: 113 private:
115 size_t m_width; 114 size_t m_width;
116 size_t m_height; 115 size_t m_height;