Mercurial > hg > svcore
comparison data/model/WaveFileModel.cpp @ 1086:9f4505ac9072
Tidy dense time-value model API a bit; add first simple unit test for FFT model
author | Chris Cannam |
---|---|
date | Wed, 10 Jun 2015 17:06:02 +0100 |
parents | 0fd3661bcfff |
children | 4d9816ba0ebe b9faee02afa5 |
comparison
equal
deleted
inserted
replaced
1085:bf6f64dabe73 | 1086:9f4505ac9072 |
---|---|
250 | 250 |
251 return i; | 251 return i; |
252 } | 252 } |
253 | 253 |
254 sv_frame_t | 254 sv_frame_t |
255 WaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count, | 255 WaveFileModel::getMultiChannelData(int fromchannel, int tochannel, |
256 double *buffer) const | 256 sv_frame_t start, sv_frame_t count, |
257 { | 257 float **buffer) const |
258 #ifdef DEBUG_WAVE_FILE_MODEL | |
259 cout << "WaveFileModel::getData(double)[" << this << "]: " << channel << ", " << start << ", " << count << ", " << buffer << endl; | |
260 #endif | |
261 | |
262 if (start > m_startFrame) { | |
263 start -= m_startFrame; | |
264 } else { | |
265 for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.0; | |
266 if (count <= m_startFrame - start) { | |
267 return 0; | |
268 } else { | |
269 count -= (m_startFrame - start); | |
270 start = 0; | |
271 } | |
272 } | |
273 | |
274 if (!m_reader || !m_reader->isOK() || count == 0) { | |
275 for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.0; | |
276 return 0; | |
277 } | |
278 | |
279 int channels = getChannelCount(); | |
280 | |
281 SampleBlock frames = m_reader->getInterleavedFrames(start, count); | |
282 | |
283 sv_frame_t i = 0; | |
284 | |
285 int ch0 = channel, ch1 = channel; | |
286 if (channel == -1) { | |
287 ch0 = 0; | |
288 ch1 = channels - 1; | |
289 } | |
290 | |
291 while (i < count) { | |
292 | |
293 buffer[i] = 0.0; | |
294 | |
295 for (int ch = ch0; ch <= ch1; ++ch) { | |
296 | |
297 sv_frame_t index = i * channels + ch; | |
298 if (index >= (sv_frame_t)frames.size()) break; | |
299 | |
300 float sample = frames[index]; | |
301 buffer[i] += sample; | |
302 } | |
303 | |
304 ++i; | |
305 } | |
306 | |
307 return i; | |
308 } | |
309 | |
310 sv_frame_t | |
311 WaveFileModel::getData(int fromchannel, int tochannel, | |
312 sv_frame_t start, sv_frame_t count, | |
313 float **buffer) const | |
314 { | 258 { |
315 #ifdef DEBUG_WAVE_FILE_MODEL | 259 #ifdef DEBUG_WAVE_FILE_MODEL |
316 cout << "WaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << ", " << buffer << endl; | 260 cout << "WaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << ", " << buffer << endl; |
317 #endif | 261 #endif |
318 | 262 |