comparison data/fileio/CodedAudioFileReader.cpp @ 1041:843f67be0ed9 cxx11

Replace the get*Frames calls in AudioFileReader with less stupid API
author Chris Cannam
date Wed, 04 Mar 2015 12:30:41 +0000
parents a1cd5abcb38b
children e603b44510c3
comparison
equal deleted inserted replaced
1040:a1cd5abcb38b 1041:843f67be0ed9
353 case CacheInMemory: 353 case CacheInMemory:
354 m_dataLock.lockForWrite(); 354 m_dataLock.lockForWrite();
355 for (sv_frame_t s = 0; s < count; ++s) { 355 for (sv_frame_t s = 0; s < count; ++s) {
356 m_data.push_back(buffer[s]); 356 m_data.push_back(buffer[s]);
357 } 357 }
358 MUNLOCK_SAMPLEBLOCK(m_data);
359 m_dataLock.unlock(); 358 m_dataLock.unlock();
360 break; 359 break;
361 } 360 }
362 } 361 }
363 362
407 pushBufferNonResampling(m_resampleBuffer, out); 406 pushBufferNonResampling(m_resampleBuffer, out);
408 delete[] padding; 407 delete[] padding;
409 } 408 }
410 } 409 }
411 410
412 void 411 SampleBlock
413 CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count, 412 CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const
414 SampleBlock &frames) const
415 { 413 {
416 // Lock is only required in CacheInMemory mode (the cache file 414 // Lock is only required in CacheInMemory mode (the cache file
417 // reader is expected to be thread safe and manage its own 415 // reader is expected to be thread safe and manage its own
418 // locking) 416 // locking)
419 417
420 if (!m_initialised) { 418 if (!m_initialised) {
421 SVDEBUG << "CodedAudioFileReader::getInterleavedFrames: not initialised" << endl; 419 SVDEBUG << "CodedAudioFileReader::getInterleavedFrames: not initialised" << endl;
422 return; 420 return SampleBlock();
423 } 421 }
424 422
423 SampleBlock frames;
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) {
429 m_cacheFileReader->getInterleavedFrames(start, count, frames); 429 frames = m_cacheFileReader->getInterleavedFrames(start, count);
430 } 430 }
431 break; 431 break;
432 432
433 case CacheInMemory: 433 case CacheInMemory:
434 { 434 {
435 frames.clear(); 435 if (!isOK()) return SampleBlock();
436 if (!isOK()) return; 436 if (count == 0) return SampleBlock();
437 if (count == 0) return;
438 frames.reserve(count * m_channelCount);
439 437
440 sv_frame_t idx = start * m_channelCount; 438 sv_frame_t idx = start * m_channelCount;
441 sv_frame_t i = 0; 439 sv_frame_t i = 0;
440 sv_frame_t n = count * m_channelCount;
442 441
443 m_dataLock.lockForRead(); 442 m_dataLock.lockForRead();
444 while (i < count * m_channelCount && idx < (sv_frame_t)m_data.size()) { 443 while (i < n && in_range_for(m_data, idx)) {
445 frames.push_back(m_data[idx]); 444 frames.push_back(m_data[idx++]);
446 ++idx; 445 ++i;
447 } 446 }
448 m_dataLock.unlock(); 447 m_dataLock.unlock();
449 } 448 }
450 } 449 }
451 450
452 if (m_normalised) { 451 if (m_normalised) {
453 for (sv_frame_t i = 0; i < (sv_frame_t)(count * m_channelCount); ++i) { 452 for (sv_frame_t i = 0; i < (sv_frame_t)(count * m_channelCount); ++i) {
454 frames[i] *= m_gain; 453 frames[i] *= m_gain;
455 } 454 }
456 } 455 }
457 } 456
458 457 return frames;
458 }
459