Mercurial > hg > svcore
comparison data/fft/FFTFileCacheReader.cpp @ 935:f960d67ce842 tonioni
Merge from branch warnfix_no_size_t
author | Chris Cannam |
---|---|
date | Wed, 18 Jun 2014 13:42:01 +0100 |
parents | 59e7fe1b1003 |
children | cc27f35aa75c |
comparison
equal
deleted
inserted
replaced
925:3efc20c59a94 | 935:f960d67ce842 |
---|---|
51 { | 51 { |
52 if (m_readbuf) delete[] m_readbuf; | 52 if (m_readbuf) delete[] m_readbuf; |
53 delete m_mfc; | 53 delete m_mfc; |
54 } | 54 } |
55 | 55 |
56 size_t | 56 int |
57 FFTFileCacheReader::getWidth() const | 57 FFTFileCacheReader::getWidth() const |
58 { | 58 { |
59 return m_mfc->getWidth(); | 59 return m_mfc->getWidth(); |
60 } | 60 } |
61 | 61 |
62 size_t | 62 int |
63 FFTFileCacheReader::getHeight() const | 63 FFTFileCacheReader::getHeight() const |
64 { | 64 { |
65 size_t mh = m_mfc->getHeight(); | 65 int mh = m_mfc->getHeight(); |
66 if (mh > m_factorSize) return (mh - m_factorSize) / 2; | 66 if (mh > m_factorSize) return (mh - m_factorSize) / 2; |
67 else return 0; | 67 else return 0; |
68 } | 68 } |
69 | 69 |
70 float | 70 float |
71 FFTFileCacheReader::getMagnitudeAt(size_t x, size_t y) const | 71 FFTFileCacheReader::getMagnitudeAt(int x, int y) const |
72 { | 72 { |
73 Profiler profiler("FFTFileCacheReader::getMagnitudeAt", false); | 73 Profiler profiler("FFTFileCacheReader::getMagnitudeAt", false); |
74 | 74 |
75 float value = 0.f; | 75 float value = 0.f; |
76 | 76 |
96 | 96 |
97 return value; | 97 return value; |
98 } | 98 } |
99 | 99 |
100 float | 100 float |
101 FFTFileCacheReader::getNormalizedMagnitudeAt(size_t x, size_t y) const | 101 FFTFileCacheReader::getNormalizedMagnitudeAt(int x, int y) const |
102 { | 102 { |
103 float value = 0.f; | 103 float value = 0.f; |
104 | 104 |
105 switch (m_storageType) { | 105 switch (m_storageType) { |
106 | 106 |
107 case FFTCache::Compact: | 107 case FFTCache::Compact: |
108 value = getFromReadBufCompactUnsigned(x, y * 2) / 65535.0; | 108 value = getFromReadBufCompactUnsigned(x, y * 2) / 65535.0; |
109 break; | 109 break; |
110 | 110 |
111 default: | 111 case FFTCache::Rectangular: |
112 case FFTCache::Polar: | |
112 { | 113 { |
113 float mag = getMagnitudeAt(x, y); | 114 float mag = getMagnitudeAt(x, y); |
114 float factor = getNormalizationFactor(x); | 115 float factor = getNormalizationFactor(x); |
115 if (factor != 0) value = mag / factor; | 116 if (factor != 0) value = mag / factor; |
116 else value = 0.f; | 117 else value = 0.f; |
120 | 121 |
121 return value; | 122 return value; |
122 } | 123 } |
123 | 124 |
124 float | 125 float |
125 FFTFileCacheReader::getMaximumMagnitudeAt(size_t x) const | 126 FFTFileCacheReader::getMaximumMagnitudeAt(int x) const |
126 { | 127 { |
127 return getNormalizationFactor(x); | 128 return getNormalizationFactor(x); |
128 } | 129 } |
129 | 130 |
130 float | 131 float |
131 FFTFileCacheReader::getPhaseAt(size_t x, size_t y) const | 132 FFTFileCacheReader::getPhaseAt(int x, int y) const |
132 { | 133 { |
133 float value = 0.f; | 134 float value = 0.f; |
134 | 135 |
135 switch (m_storageType) { | 136 switch (m_storageType) { |
136 | 137 |
153 | 154 |
154 return value; | 155 return value; |
155 } | 156 } |
156 | 157 |
157 void | 158 void |
158 FFTFileCacheReader::getValuesAt(size_t x, size_t y, float &real, float &imag) const | 159 FFTFileCacheReader::getValuesAt(int x, int y, float &real, float &imag) const |
159 { | 160 { |
160 // SVDEBUG << "FFTFileCacheReader::getValuesAt(" << x << "," << y << ")" << endl; | 161 // SVDEBUG << "FFTFileCacheReader::getValuesAt(" << x << "," << y << ")" << endl; |
161 | 162 |
162 switch (m_storageType) { | 163 switch (m_storageType) { |
163 | 164 |
164 case FFTCache::Rectangular: | 165 case FFTCache::Rectangular: |
165 real = getFromReadBufStandard(x, y * 2); | 166 real = getFromReadBufStandard(x, y * 2); |
166 imag = getFromReadBufStandard(x, y * 2 + 1); | 167 imag = getFromReadBufStandard(x, y * 2 + 1); |
167 return; | 168 return; |
168 | 169 |
169 default: | 170 case FFTCache::Compact: |
171 case FFTCache::Polar: | |
170 float mag = getMagnitudeAt(x, y); | 172 float mag = getMagnitudeAt(x, y); |
171 float phase = getPhaseAt(x, y); | 173 float phase = getPhaseAt(x, y); |
172 real = mag * cosf(phase); | 174 real = mag * cosf(phase); |
173 imag = mag * sinf(phase); | 175 imag = mag * sinf(phase); |
174 return; | 176 return; |
175 } | 177 } |
176 } | 178 } |
177 | 179 |
178 void | 180 void |
179 FFTFileCacheReader::getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const | 181 FFTFileCacheReader::getMagnitudesAt(int x, float *values, int minbin, int count, int step) const |
180 { | 182 { |
181 Profiler profiler("FFTFileCacheReader::getMagnitudesAt"); | 183 Profiler profiler("FFTFileCacheReader::getMagnitudesAt"); |
182 | 184 |
183 switch (m_storageType) { | 185 switch (m_storageType) { |
184 | 186 |
185 case FFTCache::Compact: | 187 case FFTCache::Compact: |
186 for (size_t i = 0; i < count; ++i) { | 188 for (int i = 0; i < count; ++i) { |
187 size_t y = minbin + i * step; | 189 int y = minbin + i * step; |
188 values[i] = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.0) | 190 values[i] = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.0) |
189 * getNormalizationFactor(x); | 191 * getNormalizationFactor(x); |
190 } | 192 } |
191 break; | 193 break; |
192 | 194 |
193 case FFTCache::Rectangular: | 195 case FFTCache::Rectangular: |
194 { | 196 { |
195 float real, imag; | 197 float real, imag; |
196 for (size_t i = 0; i < count; ++i) { | 198 for (int i = 0; i < count; ++i) { |
197 size_t y = minbin + i * step; | 199 int y = minbin + i * step; |
198 real = getFromReadBufStandard(x, y * 2); | 200 real = getFromReadBufStandard(x, y * 2); |
199 imag = getFromReadBufStandard(x, y * 2 + 1); | 201 imag = getFromReadBufStandard(x, y * 2 + 1); |
200 values[i] = sqrtf(real * real + imag * imag); | 202 values[i] = sqrtf(real * real + imag * imag); |
201 } | 203 } |
202 break; | 204 break; |
203 } | 205 } |
204 | 206 |
205 case FFTCache::Polar: | 207 case FFTCache::Polar: |
206 for (size_t i = 0; i < count; ++i) { | 208 for (int i = 0; i < count; ++i) { |
207 size_t y = minbin + i * step; | 209 int y = minbin + i * step; |
208 values[i] = getFromReadBufStandard(x, y * 2); | 210 values[i] = getFromReadBufStandard(x, y * 2); |
209 } | 211 } |
210 break; | 212 break; |
211 } | 213 } |
212 } | 214 } |
213 | 215 |
214 bool | 216 bool |
215 FFTFileCacheReader::haveSetColumnAt(size_t x) const | 217 FFTFileCacheReader::haveSetColumnAt(int x) const |
216 { | 218 { |
217 if (m_readbuf && m_readbufGood && | 219 if (m_readbuf && m_readbufGood && |
218 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { | 220 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { |
219 // SVDEBUG << "FFTFileCacheReader::haveSetColumnAt: short-circuiting; we know about this one" << endl; | 221 // SVDEBUG << "FFTFileCacheReader::haveSetColumnAt: short-circuiting; we know about this one" << endl; |
220 return true; | 222 return true; |
221 } | 223 } |
222 return m_mfc->haveSetColumnAt(x); | 224 return m_mfc->haveSetColumnAt(x); |
223 } | 225 } |
224 | 226 |
225 size_t | 227 int |
226 FFTFileCacheReader::getCacheSize(size_t width, size_t height, | 228 FFTFileCacheReader::getCacheSize(int width, int height, |
227 FFTCache::StorageType type) | 229 FFTCache::StorageType type) |
228 { | 230 { |
229 return (height * 2 + (type == FFTCache::Compact ? 2 : 1)) * width * | 231 return (height * 2 + (type == FFTCache::Compact ? 2 : 1)) * width * |
230 (type == FFTCache::Compact ? sizeof(uint16_t) : sizeof(float)) + | 232 (type == FFTCache::Compact ? sizeof(uint16_t) : sizeof(float)) + |
231 2 * sizeof(size_t); // matrix file header size | 233 2 * sizeof(int); // matrix file header size |
232 } | 234 } |
233 | 235 |
234 void | 236 void |
235 FFTFileCacheReader::populateReadBuf(size_t x) const | 237 FFTFileCacheReader::populateReadBuf(int x) const |
236 { | 238 { |
237 Profiler profiler("FFTFileCacheReader::populateReadBuf", false); | 239 Profiler profiler("FFTFileCacheReader::populateReadBuf", false); |
238 | 240 |
239 // SVDEBUG << "FFTFileCacheReader::populateReadBuf(" << x << ")" << endl; | 241 // SVDEBUG << "FFTFileCacheReader::populateReadBuf(" << x << ")" << endl; |
240 | 242 |