comparison data/fileio/CodedAudioFileReader.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 e603b44510c3
children 329ddaf7415d
comparison
equal deleted inserted replaced
1095:b66734b5f806 1096:4d9816ba0ebe
24 24
25 #include <stdint.h> 25 #include <stdint.h>
26 #include <iostream> 26 #include <iostream>
27 #include <QDir> 27 #include <QDir>
28 #include <QMutexLocker> 28 #include <QMutexLocker>
29
30 using namespace std;
29 31
30 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode, 32 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode,
31 sv_samplerate_t targetRate, 33 sv_samplerate_t targetRate,
32 bool normalised) : 34 bool normalised) :
33 m_cacheMode(cacheMode), 35 m_cacheMode(cacheMode),
240 } 242 }
241 } 243 }
242 } 244 }
243 245
244 void 246 void
245 CodedAudioFileReader::addSamplesToDecodeCache(const SampleBlock &samples) 247 CodedAudioFileReader::addSamplesToDecodeCache(const vector<float> &samples)
246 { 248 {
247 QMutexLocker locker(&m_cacheMutex); 249 QMutexLocker locker(&m_cacheMutex);
248 250
249 if (!m_initialised) return; 251 if (!m_initialised) return;
250 252
350 } 352 }
351 break; 353 break;
352 354
353 case CacheInMemory: 355 case CacheInMemory:
354 m_dataLock.lockForWrite(); 356 m_dataLock.lockForWrite();
355 for (sv_frame_t s = 0; s < count; ++s) { 357 m_data.insert(m_data.end(), buffer, buffer + count);
356 m_data.push_back(buffer[s]);
357 }
358 m_dataLock.unlock(); 358 m_dataLock.unlock();
359 break; 359 break;
360 } 360 }
361 } 361 }
362 362
406 pushBufferNonResampling(m_resampleBuffer, out); 406 pushBufferNonResampling(m_resampleBuffer, out);
407 delete[] padding; 407 delete[] padding;
408 } 408 }
409 } 409 }
410 410
411 SampleBlock 411 vector<float>
412 CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const 412 CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const
413 { 413 {
414 // Lock is only required in CacheInMemory mode (the cache file 414 // Lock is only required in CacheInMemory mode (the cache file
415 // reader is expected to be thread safe and manage its own 415 // reader is expected to be thread safe and manage its own
416 // locking) 416 // locking)
417 417
418 if (!m_initialised) { 418 if (!m_initialised) {
419 SVDEBUG << "CodedAudioFileReader::getInterleavedFrames: not initialised" << endl; 419 SVDEBUG << "CodedAudioFileReader::getInterleavedFrames: not initialised" << endl;
420 return SampleBlock(); 420 return {};
421 } 421 }
422 422
423 SampleBlock frames; 423 vector<float> frames;
424 424
425 switch (m_cacheMode) { 425 switch (m_cacheMode) {
426 426
427 case CacheInTemporaryFile: 427 case CacheInTemporaryFile:
428 if (m_cacheFileReader) { 428 if (m_cacheFileReader) {
430 } 430 }
431 break; 431 break;
432 432
433 case CacheInMemory: 433 case CacheInMemory:
434 { 434 {
435 if (!isOK()) return SampleBlock(); 435 if (!isOK()) return {};
436 if (count == 0) return SampleBlock(); 436 if (count == 0) return {};
437 437
438 sv_frame_t idx = start * m_channelCount; 438 sv_frame_t idx = start * m_channelCount;
439 sv_frame_t i = 0; 439 sv_frame_t i = 0;
440 sv_frame_t n = count * m_channelCount; 440 sv_frame_t n = count * m_channelCount;
441 441