Mercurial > hg > svcore
comparison data/fft/FFTMemoryCache.cpp @ 334:aa8dbac62024
* Pass StorageAdviser::Criteria into FFTModel constructor etc
author | Chris Cannam |
---|---|
date | Sun, 11 Nov 2007 20:31:12 +0000 |
parents | 260032c26c4f |
children | 02d2ad95ea52 94fc0591ea43 |
comparison
equal
deleted
inserted
replaced
333:1afaf98dbf11 | 334:aa8dbac62024 |
---|---|
23 m_height(0), | 23 m_height(0), |
24 m_magnitude(0), | 24 m_magnitude(0), |
25 m_phase(0), | 25 m_phase(0), |
26 m_fmagnitude(0), | 26 m_fmagnitude(0), |
27 m_fphase(0), | 27 m_fphase(0), |
28 m_freal(0), | |
29 m_fimag(0), | |
28 m_factor(0), | 30 m_factor(0), |
29 m_storageType(storageType) | 31 m_storageType(storageType) |
30 { | 32 { |
31 std::cerr << "FFTMemoryCache[" << this << "]::FFTMemoryCache (type " | 33 std::cerr << "FFTMemoryCache[" << this << "]::FFTMemoryCache (type " |
32 << m_storageType << ")" << std::endl; | 34 << m_storageType << ")" << std::endl; |
39 for (size_t i = 0; i < m_width; ++i) { | 41 for (size_t i = 0; i < m_width; ++i) { |
40 if (m_magnitude && m_magnitude[i]) free(m_magnitude[i]); | 42 if (m_magnitude && m_magnitude[i]) free(m_magnitude[i]); |
41 if (m_phase && m_phase[i]) free(m_phase[i]); | 43 if (m_phase && m_phase[i]) free(m_phase[i]); |
42 if (m_fmagnitude && m_fmagnitude[i]) free(m_fmagnitude[i]); | 44 if (m_fmagnitude && m_fmagnitude[i]) free(m_fmagnitude[i]); |
43 if (m_fphase && m_fphase[i]) free(m_fphase[i]); | 45 if (m_fphase && m_fphase[i]) free(m_fphase[i]); |
46 if (m_freal && m_freal[i]) free(m_freal[i]); | |
47 if (m_fimag && m_fimag[i]) free(m_fimag[i]); | |
44 } | 48 } |
45 | 49 |
46 if (m_magnitude) free(m_magnitude); | 50 if (m_magnitude) free(m_magnitude); |
47 if (m_phase) free(m_phase); | 51 if (m_phase) free(m_phase); |
48 if (m_fmagnitude) free(m_fmagnitude); | 52 if (m_fmagnitude) free(m_fmagnitude); |
49 if (m_fphase) free(m_fphase); | 53 if (m_fphase) free(m_fphase); |
54 if (m_freal) free(m_freal); | |
55 if (m_fimag) free(m_fimag); | |
50 if (m_factor) free(m_factor); | 56 if (m_factor) free(m_factor); |
51 } | 57 } |
52 | 58 |
53 void | 59 void |
54 FFTMemoryCache::resize(size_t width, size_t height) | 60 FFTMemoryCache::resize(size_t width, size_t height) |
58 if (m_width == width && m_height == height) return; | 64 if (m_width == width && m_height == height) return; |
59 | 65 |
60 if (m_storageType == Compact) { | 66 if (m_storageType == Compact) { |
61 resize(m_magnitude, width, height); | 67 resize(m_magnitude, width, height); |
62 resize(m_phase, width, height); | 68 resize(m_phase, width, height); |
63 } else { | 69 } else if (m_storageType == Polar) { |
64 resize(m_fmagnitude, width, height); | 70 resize(m_fmagnitude, width, height); |
65 resize(m_fphase, width, height); | 71 resize(m_fphase, width, height); |
72 } else { | |
73 resize(m_freal, width, height); | |
74 resize(m_fimag, width, height); | |
66 } | 75 } |
67 | 76 |
68 m_colset.resize(width); | 77 m_colset.resize(width); |
69 | 78 |
70 m_factor = (float *)realloc(m_factor, width * sizeof(float)); | 79 m_factor = (float *)realloc(m_factor, width * sizeof(float)); |
145 m_fphase[x][y] = 0; | 154 m_fphase[x][y] = 0; |
146 } | 155 } |
147 m_factor[x] = 1.0; | 156 m_factor[x] = 1.0; |
148 } | 157 } |
149 break; | 158 break; |
159 | |
160 case Rectangular: | |
161 for (size_t x = 0; x < m_width; ++x) { | |
162 for (size_t y = 0; y < m_height; ++y) { | |
163 m_freal[x][y] = 0; | |
164 m_fimag[x][y] = 0; | |
165 } | |
166 m_factor[x] = 1.0; | |
167 } | |
168 break; | |
150 } | 169 } |
151 } | 170 } |
152 | 171 |
153 void | 172 void |
173 FFTMemoryCache::setColumnAt(size_t x, float *mags, float *phases, float factor) | |
174 { | |
175 setNormalizationFactor(x, factor); | |
176 | |
177 if (m_storageType == Rectangular) { | |
178 for (size_t y = 0; y < m_height; ++y) { | |
179 m_freal[x][y] = mags[y] * cosf(phases[y]); | |
180 m_fimag[x][y] = mags[y] * sinf(phases[y]); | |
181 } | |
182 } else { | |
183 for (size_t y = 0; y < m_height; ++y) { | |
184 setMagnitudeAt(x, y, mags[y]); | |
185 setPhaseAt(x, y, phases[y]); | |
186 } | |
187 } | |
188 | |
189 m_colset.set(x); | |
190 } | |
191 | |
192 void | |
154 FFTMemoryCache::setColumnAt(size_t x, float *reals, float *imags) | 193 FFTMemoryCache::setColumnAt(size_t x, float *reals, float *imags) |
155 { | 194 { |
156 float max = 0.0; | 195 float max = 0.0; |
157 | 196 |
158 switch (m_storageType) { | 197 switch (m_storageType) { |
198 | |
199 case Rectangular: | |
200 for (size_t y = 0; y < m_height; ++y) { | |
201 m_freal[x][y] = reals[y]; | |
202 m_fimag[x][y] = imags[y]; | |
203 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]); | |
204 if (mag > max) max = mag; | |
205 } | |
206 break; | |
159 | 207 |
160 case Compact: | 208 case Compact: |
161 case Polar: | 209 case Polar: |
162 for (size_t y = 0; y < m_height; ++y) { | 210 for (size_t y = 0; y < m_height; ++y) { |
163 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]); | 211 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]); |
168 if (mag > max) max = mag; | 216 if (mag > max) max = mag; |
169 } | 217 } |
170 break; | 218 break; |
171 }; | 219 }; |
172 | 220 |
173 setColumnAt(x, reals, imags, max); | 221 if (m_storageType == Rectangular) { |
222 m_factor[x] = max; | |
223 m_colset.set(x); | |
224 } else { | |
225 setColumnAt(x, reals, imags, max); | |
226 } | |
174 } | 227 } |
175 | 228 |
176 size_t | 229 size_t |
177 FFTMemoryCache::getCacheSize(size_t width, size_t height, StorageType type) | 230 FFTMemoryCache::getCacheSize(size_t width, size_t height, StorageType type) |
178 { | 231 { |
182 | 235 |
183 case Compact: | 236 case Compact: |
184 sz = (height * 2 + 1) * width * sizeof(uint16_t); | 237 sz = (height * 2 + 1) * width * sizeof(uint16_t); |
185 | 238 |
186 case Polar: | 239 case Polar: |
240 case Rectangular: | |
187 sz = (height * 2 + 1) * width * sizeof(float); | 241 sz = (height * 2 + 1) * width * sizeof(float); |
188 } | 242 } |
189 | 243 |
190 return sz; | 244 return sz; |
191 } | 245 } |