comparison data/model/FFTModel.cpp @ 1326:54af1e21705c 3.0-integration

Update to use bqvec allocator for float vectors
author Chris Cannam
date Tue, 13 Dec 2016 15:23:21 +0000
parents 12a1da4719c7
children fad8f533ca13
comparison
equal deleted inserted replaced
1325:3aea4f7617bb 1326:54af1e21705c
186 imags[i] = col[minbin + i].imag(); 186 imags[i] = col[minbin + i].imag();
187 } 187 }
188 return true; 188 return true;
189 } 189 }
190 190
191 vector<float> 191 FFTModel::fvec
192 FFTModel::getSourceSamples(int column) const 192 FFTModel::getSourceSamples(int column) const
193 { 193 {
194 // m_fftSize may be greater than m_windowSize, but not the reverse 194 // m_fftSize may be greater than m_windowSize, but not the reverse
195 195
196 // cerr << "getSourceSamples(" << column << ")" << endl; 196 // cerr << "getSourceSamples(" << column << ")" << endl;
202 202
203 if (off == 0) { 203 if (off == 0) {
204 return data; 204 return data;
205 } else { 205 } else {
206 vector<float> pad(off, 0.f); 206 vector<float> pad(off, 0.f);
207 vector<float> padded; 207 fvec padded;
208 padded.reserve(m_fftSize); 208 padded.reserve(m_fftSize);
209 padded.insert(padded.end(), pad.begin(), pad.end()); 209 padded.insert(padded.end(), pad.begin(), pad.end());
210 padded.insert(padded.end(), data.begin(), data.end()); 210 padded.insert(padded.end(), data.begin(), data.end());
211 padded.insert(padded.end(), pad.begin(), pad.end()); 211 padded.insert(padded.end(), pad.begin(), pad.end());
212 return padded; 212 return padded;
213 } 213 }
214 } 214 }
215 215
216 vector<float> 216 FFTModel::fvec
217 FFTModel::getSourceData(pair<sv_frame_t, sv_frame_t> range) const 217 FFTModel::getSourceData(pair<sv_frame_t, sv_frame_t> range) const
218 { 218 {
219 // cerr << "getSourceData(" << range.first << "," << range.second 219 // cerr << "getSourceData(" << range.first << "," << range.second
220 // << "): saved range is (" << m_savedData.range.first 220 // << "): saved range is (" << m_savedData.range.first
221 // << "," << m_savedData.range.second << ")" << endl; 221 // << "," << m_savedData.range.second << ")" << endl;
233 233
234 inSourceCache.partial(); 234 inSourceCache.partial();
235 235
236 sv_frame_t discard = range.first - m_savedData.range.first; 236 sv_frame_t discard = range.first - m_savedData.range.first;
237 237
238 vector<float> acc(m_savedData.data.begin() + discard, 238 fvec acc(m_savedData.data.begin() + discard, m_savedData.data.end());
239 m_savedData.data.end()); 239
240 240 fvec rest = getSourceDataUncached({ m_savedData.range.second, range.second });
241 vector<float> rest =
242 getSourceDataUncached({ m_savedData.range.second, range.second });
243 241
244 acc.insert(acc.end(), rest.begin(), rest.end()); 242 acc.insert(acc.end(), rest.begin(), rest.end());
245 243
246 m_savedData = { range, acc }; 244 m_savedData = { range, acc };
247 return acc; 245 return acc;
254 m_savedData = { range, data }; 252 m_savedData = { range, data };
255 return data; 253 return data;
256 } 254 }
257 } 255 }
258 256
259 vector<float> 257 FFTModel::fvec
260 FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const 258 FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const
261 { 259 {
262 decltype(range.first) pfx = 0; 260 decltype(range.first) pfx = 0;
263 if (range.first < 0) { 261 if (range.first < 0) {
264 pfx = -range.first; 262 pfx = -range.first;
296 } 294 }
297 295
298 return data; 296 return data;
299 } 297 }
300 298
301 vector<complex<float>> 299 FFTModel::cvec
302 FFTModel::getFFTColumn(int n) const 300 FFTModel::getFFTColumn(int n) const
303 { 301 {
304 // The small cache (i.e. the m_cached deque) is for cases where 302 // The small cache (i.e. the m_cached deque) is for cases where
305 // values are looked up individually, and for e.g. peak-frequency 303 // values are looked up individually, and for e.g. peak-frequency
306 // spectrograms where values from two consecutive columns are 304 // spectrograms where values from two consecutive columns are
319 317
320 auto samples = getSourceSamples(n); 318 auto samples = getSourceSamples(n);
321 m_windower.cut(samples.data()); 319 m_windower.cut(samples.data());
322 breakfastquay::v_fftshift(samples.data(), m_fftSize); 320 breakfastquay::v_fftshift(samples.data(), m_fftSize);
323 321
324 vector<complex<float>> col(m_fftSize/2 + 1); 322 cvec col(m_fftSize/2 + 1);
325 323
326 m_fft.forwardInterleaved(samples.data(), 324 m_fft.forwardInterleaved(samples.data(),
327 reinterpret_cast<float *>(col.data())); 325 reinterpret_cast<float *>(col.data()));
328 326
329 SavedColumn sc { n, col }; 327 SavedColumn sc { n, col };