comparison data/model/FFTModel.cpp @ 1096:4d9816ba0ebe simple-fft-model

Rework audio file reader API to prefer using std containers
author Chris Cannam
date Mon, 15 Jun 2015 12:19:47 +0100
parents b66734b5f806
children 5cbf71022679
comparison
equal deleted inserted replaced
1095:b66734b5f806 1096:4d9816ba0ebe
254 } 254 }
255 255
256 vector<float> 256 vector<float>
257 FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const 257 FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const
258 { 258 {
259 vector<float> data(range.second - range.first, 0.f);
260 decltype(range.first) pfx = 0; 259 decltype(range.first) pfx = 0;
261 if (range.first < 0) { 260 if (range.first < 0) {
262 pfx = -range.first; 261 pfx = -range.first;
263 range = { 0, range.second }; 262 range = { 0, range.second };
264 } 263 }
265 // cerr << "requesting " << range.second - range.first << " from file" << endl; 264
266 (void) m_model->getData(m_channel, 265 auto data = m_model->getData(m_channel,
267 range.first, 266 range.first,
268 range.second - range.first, 267 range.second - range.first);
269 &data[pfx]); 268
269 // don't return a partial frame
270 data.resize(range.second - range.first, 0.f);
271
272 if (pfx > 0) {
273 vector<float> pad(pfx, 0.f);
274 data.insert(data.begin(), pad.begin(), pad.end());
275 }
276
270 if (m_channel == -1) { 277 if (m_channel == -1) {
271 int channels = m_model->getChannelCount(); 278 int channels = m_model->getChannelCount();
272 if (channels > 1) { 279 if (channels > 1) {
273 for (int i = 0; in_range_for(data, i); ++i) { 280 int n = int(data.size());
274 data[i] /= float(channels); 281 float factor = 1.f / float(channels);
282 for (int i = 0; i < n; ++i) {
283 data[i] *= factor;
275 } 284 }
276 } 285 }
277 } 286 }
278 287
279 return data; 288 return data;