Mercurial > hg > svcore
comparison data/model/FFTModel.cpp @ 1100:5cbf71022679 simple-fft-model
Smooth signal flow through from file to fft model
author | Chris Cannam |
---|---|
date | Mon, 15 Jun 2015 16:02:58 +0100 |
parents | 4d9816ba0ebe |
children | e994747fb9dd |
comparison
equal
deleted
inserted
replaced
1099:0c351e061945 | 1100:5cbf71022679 |
---|---|
223 { | 223 { |
224 // cerr << "getSourceData(" << range.first << "," << range.second | 224 // cerr << "getSourceData(" << range.first << "," << range.second |
225 // << "): saved range is (" << m_savedData.range.first | 225 // << "): saved range is (" << m_savedData.range.first |
226 // << "," << m_savedData.range.second << ")" << endl; | 226 // << "," << m_savedData.range.second << ")" << endl; |
227 | 227 |
228 if (m_savedData.range == range) return m_savedData.data; | 228 if (m_savedData.range == range) { |
229 return m_savedData.data; | |
230 } | |
229 | 231 |
230 if (range.first < m_savedData.range.second && | 232 if (range.first < m_savedData.range.second && |
231 range.first >= m_savedData.range.first && | 233 range.first >= m_savedData.range.first && |
232 range.second > m_savedData.range.second) { | 234 range.second > m_savedData.range.second) { |
233 | 235 |
234 //!!! Need FFTModel overlap tests to exercise this | 236 sv_frame_t discard = range.first - m_savedData.range.first; |
235 | 237 |
236 sv_frame_t off = range.first - m_savedData.range.first; | 238 vector<float> acc(m_savedData.data.begin() + discard, |
237 | 239 m_savedData.data.end()); |
238 vector<float> acc(m_savedData.data.begin() + off, m_savedData.data.end()); | |
239 | 240 |
240 vector<float> rest = | 241 vector<float> rest = |
241 getSourceDataUncached({ m_savedData.range.second, range.second }); | 242 getSourceDataUncached({ m_savedData.range.second, range.second }); |
243 | |
244 acc.insert(acc.end(), rest.begin(), rest.end()); | |
242 | 245 |
243 acc.insert(acc.end(), rest.begin(), rest.end()); | |
244 | |
245 m_savedData = { range, acc }; | 246 m_savedData = { range, acc }; |
246 return acc; | 247 return acc; |
247 | 248 |
248 } else { | 249 } else { |
249 | 250 |
277 if (m_channel == -1) { | 278 if (m_channel == -1) { |
278 int channels = m_model->getChannelCount(); | 279 int channels = m_model->getChannelCount(); |
279 if (channels > 1) { | 280 if (channels > 1) { |
280 int n = int(data.size()); | 281 int n = int(data.size()); |
281 float factor = 1.f / float(channels); | 282 float factor = 1.f / float(channels); |
283 // use mean instead of sum for fft model input | |
282 for (int i = 0; i < n; ++i) { | 284 for (int i = 0; i < n; ++i) { |
283 data[i] *= factor; | 285 data[i] *= factor; |
284 } | 286 } |
285 } | 287 } |
286 } | 288 } |
296 return incache.col; | 298 return incache.col; |
297 } | 299 } |
298 } | 300 } |
299 | 301 |
300 auto samples = getSourceSamples(n); | 302 auto samples = getSourceSamples(n); |
301 m_windower.cut(&samples[0]); | 303 m_windower.cut(samples.data()); |
302 auto col = m_fft.process(samples); | 304 auto col = m_fft.process(samples); |
303 | 305 |
304 SavedColumn sc { n, col }; | 306 SavedColumn sc { n, col }; |
305 if (m_cached.size() >= m_cacheSize) { | 307 if (m_cached.size() >= m_cacheSize) { |
306 m_cached.pop_front(); | 308 m_cached.pop_front(); |