Mercurial > hg > svcore
comparison data/fft/FFTMemoryCache.h @ 264:260032c26c4f
* don't store fft values scaled by fftsize/2; that's a special requirement
for the spectrogram, and other applications will not expect it -- make the
spectrogram do that scaling itself
* add a higher-resolution memory cache (still polar, though) as an alternative
to the 16-bit compact cache
* don't use the memory cache if we want rectangular coords (unless the disc
cache is totally infeasible) as conversion slows it down anyway
* avoid redundant rectangular -> polar -> rectangular conversion when storing
values in a rectangular-mode disc cache
author | Chris Cannam |
---|---|
date | Fri, 01 Jun 2007 13:56:35 +0000 |
parents | b36895bda652 |
children | aa8dbac62024 |
comparison
equal
deleted
inserted
replaced
263:71dfc6ab3b54 | 264:260032c26c4f |
---|---|
40 */ | 40 */ |
41 | 41 |
42 class FFTMemoryCache : public FFTCache | 42 class FFTMemoryCache : public FFTCache |
43 { | 43 { |
44 public: | 44 public: |
45 FFTMemoryCache(); // of size zero, call resize() before using | 45 enum StorageType { |
46 Compact, // 16 bits normalized polar | |
47 Polar, // floating point mag+phase | |
48 }; | |
49 | |
50 FFTMemoryCache(StorageType storageType); // of size zero, call resize() before using | |
46 virtual ~FFTMemoryCache(); | 51 virtual ~FFTMemoryCache(); |
47 | 52 |
48 virtual size_t getWidth() const { return m_width; } | 53 virtual size_t getWidth() const { return m_width; } |
49 virtual size_t getHeight() const { return m_height; } | 54 virtual size_t getHeight() const { return m_height; } |
50 | 55 |
54 virtual float getMagnitudeAt(size_t x, size_t y) const { | 59 virtual float getMagnitudeAt(size_t x, size_t y) const { |
55 return getNormalizedMagnitudeAt(x, y) * m_factor[x]; | 60 return getNormalizedMagnitudeAt(x, y) * m_factor[x]; |
56 } | 61 } |
57 | 62 |
58 virtual float getNormalizedMagnitudeAt(size_t x, size_t y) const { | 63 virtual float getNormalizedMagnitudeAt(size_t x, size_t y) const { |
59 return float(m_magnitude[x][y]) / 65535.0; | 64 if (m_storageType == Polar) return m_fmagnitude[x][y]; |
65 else return float(m_magnitude[x][y]) / 65535.0; | |
60 } | 66 } |
61 | 67 |
62 virtual float getMaximumMagnitudeAt(size_t x) const { | 68 virtual float getMaximumMagnitudeAt(size_t x) const { |
63 return m_factor[x]; | 69 return m_factor[x]; |
64 } | 70 } |
65 | 71 |
66 virtual float getPhaseAt(size_t x, size_t y) const { | 72 virtual float getPhaseAt(size_t x, size_t y) const { |
73 if (m_storageType == Polar) return m_fphase[x][y]; | |
67 int16_t i = (int16_t)m_phase[x][y]; | 74 int16_t i = (int16_t)m_phase[x][y]; |
68 return (float(i) / 32767.0) * M_PI; | 75 return (float(i) / 32767.0) * M_PI; |
69 } | 76 } |
70 | 77 |
71 virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const { | 78 virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const { |
84 setNormalizedMagnitudeAt(x, y, mag / m_factor[x]); | 91 setNormalizedMagnitudeAt(x, y, mag / m_factor[x]); |
85 } | 92 } |
86 | 93 |
87 virtual void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) { | 94 virtual void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) { |
88 if (x < m_width && y < m_height) { | 95 if (x < m_width && y < m_height) { |
89 m_magnitude[x][y] = uint16_t(norm * 65535.0); | 96 if (m_storageType == Polar) m_fmagnitude[x][y] = norm; |
97 else m_magnitude[x][y] = uint16_t(norm * 65535.0); | |
90 } | 98 } |
91 } | 99 } |
92 | 100 |
93 virtual void setPhaseAt(size_t x, size_t y, float phase) { | 101 virtual void setPhaseAt(size_t x, size_t y, float phase) { |
94 // phase in range -pi -> pi | 102 // phase in range -pi -> pi |
95 if (x < m_width && y < m_height) { | 103 if (x < m_width && y < m_height) { |
96 m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI)); | 104 if (m_storageType == Polar) m_fphase[x][y] = phase; |
105 else m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI)); | |
97 } | 106 } |
98 } | 107 } |
99 | 108 |
100 virtual bool haveSetColumnAt(size_t x) const { | 109 virtual bool haveSetColumnAt(size_t x) const { |
101 return m_colset.get(x); | 110 return m_colset.get(x); |
110 m_colset.set(x); | 119 m_colset.set(x); |
111 } | 120 } |
112 | 121 |
113 virtual void setColumnAt(size_t x, float *reals, float *imags); | 122 virtual void setColumnAt(size_t x, float *reals, float *imags); |
114 | 123 |
115 static size_t getCacheSize(size_t width, size_t height); | 124 static size_t getCacheSize(size_t width, size_t height, StorageType type); |
116 | 125 |
117 private: | 126 private: |
118 size_t m_width; | 127 size_t m_width; |
119 size_t m_height; | 128 size_t m_height; |
120 uint16_t **m_magnitude; | 129 uint16_t **m_magnitude; |
121 uint16_t **m_phase; | 130 uint16_t **m_phase; |
131 float **m_fmagnitude; | |
132 float **m_fphase; | |
122 float *m_factor; | 133 float *m_factor; |
134 StorageType m_storageType; | |
123 ResizeableBitset m_colset; | 135 ResizeableBitset m_colset; |
124 | 136 |
125 void resize(uint16_t **&, size_t, size_t); | 137 void resize(uint16_t **&, size_t, size_t); |
138 void resize(float **&, size_t, size_t); | |
126 }; | 139 }; |
127 | 140 |
128 | 141 |
129 #endif | 142 #endif |
130 | 143 |