comparison data/fileio/CodedAudioFileReader.cpp @ 1320:983667969a82 3.0-integration

Update to reflect bqresample API change
author Chris Cannam
date Fri, 09 Dec 2016 10:24:40 +0000
parents f830a10bfbd6
children 4dbb7a7c9c28
comparison
equal deleted inserted replaced
1319:12a1da4719c7 1320:983667969a82
40 m_fileRate(0), 40 m_fileRate(0),
41 m_cacheFileWritePtr(0), 41 m_cacheFileWritePtr(0),
42 m_cacheFileReader(0), 42 m_cacheFileReader(0),
43 m_cacheWriteBuffer(0), 43 m_cacheWriteBuffer(0),
44 m_cacheWriteBufferIndex(0), 44 m_cacheWriteBufferIndex(0),
45 m_cacheWriteBufferSize(65536), 45 m_cacheWriteBufferFrames(65536),
46 m_resampler(0), 46 m_resampler(0),
47 m_resampleBuffer(0), 47 m_resampleBuffer(0),
48 m_resampleBufferFrames(0),
48 m_fileFrameCount(0), 49 m_fileFrameCount(0),
49 m_normalised(normalised), 50 m_normalised(normalised),
50 m_max(0.f), 51 m_max(0.f),
51 m_gain(1.f), 52 m_gain(1.f),
52 m_trimFromStart(0), 53 m_trimFromStart(0),
144 if (m_fileRate != m_sampleRate) { 145 if (m_fileRate != m_sampleRate) {
145 SVDEBUG << "CodedAudioFileReader: resampling " << m_fileRate << " -> " << m_sampleRate << endl; 146 SVDEBUG << "CodedAudioFileReader: resampling " << m_fileRate << " -> " << m_sampleRate << endl;
146 m_resampler = new breakfastquay::Resampler 147 m_resampler = new breakfastquay::Resampler
147 (breakfastquay::Resampler::FastestTolerable, 148 (breakfastquay::Resampler::FastestTolerable,
148 m_channelCount, 149 m_channelCount,
149 m_cacheWriteBufferSize); 150 int(m_cacheWriteBufferFrames));
150 double ratio = m_sampleRate / m_fileRate; 151 double ratio = m_sampleRate / m_fileRate;
151 m_resampleBuffer = new float 152 m_resampleBufferFrames = int(ceil(double(m_cacheWriteBufferFrames) *
152 [lrint(ceil(double(m_cacheWriteBufferSize) * m_channelCount * ratio + 1))]; 153 ratio + 1));
153 } 154 m_resampleBuffer = new float[m_resampleBufferFrames * m_channelCount];
154 155 }
155 m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount]; 156
157 m_cacheWriteBuffer = new float[m_cacheWriteBufferFrames * m_channelCount];
156 m_cacheWriteBufferIndex = 0; 158 m_cacheWriteBufferIndex = 0;
157 159
158 if (m_cacheMode == CacheInTemporaryFile) { 160 if (m_cacheMode == CacheInTemporaryFile) {
159 161
160 try { 162 try {
226 228
227 if (m_cacheMode == CacheInMemory) { 229 if (m_cacheMode == CacheInMemory) {
228 m_data.clear(); 230 m_data.clear();
229 } 231 }
230 232
231 if (m_trimFromEnd >= (m_cacheWriteBufferSize * m_channelCount)) { 233 if (m_trimFromEnd >= (m_cacheWriteBufferFrames * m_channelCount)) {
232 SVCERR << "WARNING: CodedAudioFileReader::setSamplesToTrim: Can't handle trimming more frames from end (" << m_trimFromEnd << ") than can be stored in cache-write buffer (" << (m_cacheWriteBufferSize * m_channelCount) << "), won't trim anything from the end after all"; 234 SVCERR << "WARNING: CodedAudioFileReader::setSamplesToTrim: Can't handle trimming more frames from end (" << m_trimFromEnd << ") than can be stored in cache-write buffer (" << (m_cacheWriteBufferFrames * m_channelCount) << "), won't trim anything from the end after all";
233 m_trimFromEnd = 0; 235 m_trimFromEnd = 0;
234 } 236 }
235 237
236 m_initialised = true; 238 m_initialised = true;
237 } 239 }
360 void 362 void
361 CodedAudioFileReader::pushCacheWriteBufferMaybe(bool final) 363 CodedAudioFileReader::pushCacheWriteBufferMaybe(bool final)
362 { 364 {
363 if (final || 365 if (final ||
364 (m_cacheWriteBufferIndex == 366 (m_cacheWriteBufferIndex ==
365 m_cacheWriteBufferSize * m_channelCount)) { 367 m_cacheWriteBufferFrames * m_channelCount)) {
366 368
367 if (m_trimFromEnd > 0) { 369 if (m_trimFromEnd > 0) {
368 370
369 sv_frame_t framesToPush = 371 sv_frame_t framesToPush =
370 (m_cacheWriteBufferIndex / m_channelCount) - m_trimFromEnd; 372 (m_cacheWriteBufferIndex / m_channelCount) - m_trimFromEnd;
481 // SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl; 483 // SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl;
482 484
483 if (sz > 0) { 485 if (sz > 0) {
484 486
485 sv_frame_t out = m_resampler->resampleInterleaved 487 sv_frame_t out = m_resampler->resampleInterleaved
486 (buffer, 488 (m_resampleBuffer,
487 m_resampleBuffer, 489 m_resampleBufferFrames,
490 buffer,
488 sz, 491 sz,
489 ratio, 492 ratio,
490 false); 493 false);
491 494
492 pushBufferNonResampling(m_resampleBuffer, out); 495 pushBufferNonResampling(m_resampleBuffer, out);
505 508
506 float *padding = new float[padSamples]; 509 float *padding = new float[padSamples];
507 for (sv_frame_t i = 0; i < padSamples; ++i) padding[i] = 0.f; 510 for (sv_frame_t i = 0; i < padSamples; ++i) padding[i] = 0.f;
508 511
509 sv_frame_t out = m_resampler->resampleInterleaved 512 sv_frame_t out = m_resampler->resampleInterleaved
510 (padding, 513 (m_resampleBuffer,
511 m_resampleBuffer, 514 m_resampleBufferFrames,
515 padding,
512 padFrames, 516 padFrames,
513 ratio, 517 ratio,
514 true); 518 true);
515 519
516 if (m_frameCount + out > sv_frame_t(double(m_fileFrameCount) * ratio)) { 520 if (m_frameCount + out > sv_frame_t(double(m_fileFrameCount) * ratio)) {