comparison data/fileio/CodedAudioFileReader.cpp @ 757:b98f5daab19e

More on tests, and not the right way to do it with end of resampled file
author Chris Cannam
date Fri, 08 Mar 2013 18:19:05 +0000
parents 02390a4c2abe
children babed5be1ae7
comparison
equal deleted inserted replaced
756:02390a4c2abe 757:b98f5daab19e
37 m_cacheFileReader(0), 37 m_cacheFileReader(0),
38 m_cacheWriteBuffer(0), 38 m_cacheWriteBuffer(0),
39 m_cacheWriteBufferIndex(0), 39 m_cacheWriteBufferIndex(0),
40 m_cacheWriteBufferSize(16384), 40 m_cacheWriteBufferSize(16384),
41 m_resampler(0), 41 m_resampler(0),
42 m_resampleBuffer(0) 42 m_resampleBuffer(0),
43 m_fileFrameCount(0)
43 { 44 {
44 SVDEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << endl; 45 SVDEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << endl;
45 46
46 m_frameCount = 0; 47 m_frameCount = 0;
47 m_sampleRate = targetRate; 48 m_sampleRate = targetRate;
102 if (m_sampleRate == 0) { 103 if (m_sampleRate == 0) {
103 m_sampleRate = m_fileRate; 104 m_sampleRate = m_fileRate;
104 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: rate (from file) = " << m_fileRate << endl; 105 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: rate (from file) = " << m_fileRate << endl;
105 } 106 }
106 if (m_fileRate != m_sampleRate) { 107 if (m_fileRate != m_sampleRate) {
107 std::cerr << "CodedAudioFileReader: resampling " << m_fileRate << " -> " << m_sampleRate << std::endl; 108 SVDEBUG << "CodedAudioFileReader: resampling " << m_fileRate << " -> " << m_sampleRate << endl;
108 m_resampler = new Resampler(Resampler::FastestTolerable, 109 m_resampler = new Resampler(Resampler::FastestTolerable,
109 m_channelCount, 110 m_channelCount,
110 m_cacheWriteBufferSize); 111 m_cacheWriteBufferSize);
111 float ratio = float(m_sampleRate) / float(m_fileRate); 112 float ratio = float(m_sampleRate) / float(m_fileRate);
112 m_resampleBuffer = new float 113 m_resampleBuffer = new float
295 CodedAudioFileReader::pushBuffer(float *buffer, size_t sz, bool final) 296 CodedAudioFileReader::pushBuffer(float *buffer, size_t sz, bool final)
296 { 297 {
297 float max = 1.0; 298 float max = 1.0;
298 size_t count = sz * m_channelCount; 299 size_t count = sz * m_channelCount;
299 300
301 m_fileFrameCount += sz;
302
303 float ratio = 1.f;
304
300 if (m_resampler && m_fileRate != 0) { 305 if (m_resampler && m_fileRate != 0) {
301 306
302 float ratio = float(m_sampleRate) / float(m_fileRate); 307 ratio = float(m_sampleRate) / float(m_fileRate);
303 308
304 if (ratio != 1.f) { 309 if (ratio != 1.f) {
305 310
306 size_t out = m_resampler->resampleInterleaved 311 size_t out = m_resampler->resampleInterleaved
307 (buffer, 312 (buffer,
308 m_resampleBuffer, 313 m_resampleBuffer,
342 } 347 }
343 MUNLOCK_SAMPLEBLOCK(m_data); 348 MUNLOCK_SAMPLEBLOCK(m_data);
344 m_dataLock.unlock(); 349 m_dataLock.unlock();
345 break; 350 break;
346 } 351 }
352
353 if (final && m_resampler && ratio != 1.f) {
354 size_t equivFileFrames = m_frameCount / ratio;
355 if (equivFileFrames < m_fileFrameCount) {
356 size_t padFrames = m_fileFrameCount - equivFileFrames + 32;
357 size_t padSamples = padFrames * m_channelCount;
358 std::cerr << "frameCount = " << m_frameCount << ", equivFileFrames = " << equivFileFrames << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << std::endl;
359 float *padding = new float[padSamples];
360 for (int i = 0; i < padSamples; ++i) padding[i] = 0.f;
361
362 //!!! these are not file frames (ugh this is horrible)
363 m_fileFrameCount -= padFrames;
364
365 pushBuffer(padding, padFrames, true);
366 delete[] padding;
367 }
368 }
347 } 369 }
348 370
349 void 371 void
350 CodedAudioFileReader::getInterleavedFrames(size_t start, size_t count, 372 CodedAudioFileReader::getInterleavedFrames(size_t start, size_t count,
351 SampleBlock &frames) const 373 SampleBlock &frames) const