comparison data/fileio/CodedAudioFileReader.cpp @ 759:a43acbe3988f

More refinement in audiofile read tests and implementation
author Chris Cannam
date Fri, 08 Mar 2013 21:35:46 +0000
parents babed5be1ae7
children e802e550a1f2
comparison
equal deleted inserted replaced
758:babed5be1ae7 759:a43acbe3988f
268 if (!m_initialised) { 268 if (!m_initialised) {
269 std::cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << std::endl; 269 std::cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << std::endl;
270 return; 270 return;
271 } 271 }
272 272
273 if (m_cacheWriteBufferIndex > 0) { 273 // if (m_cacheWriteBufferIndex > 0) {
274 pushBuffer(m_cacheWriteBuffer, 274 pushBuffer(m_cacheWriteBuffer,
275 m_cacheWriteBufferIndex / m_channelCount, 275 m_cacheWriteBufferIndex / m_channelCount,
276 true); 276 true);
277 } 277 // }
278 278
279 delete[] m_cacheWriteBuffer; 279 delete[] m_cacheWriteBuffer;
280 m_cacheWriteBuffer = 0; 280 m_cacheWriteBuffer = 0;
281 281
282 delete[] m_resampleBuffer; 282 delete[] m_resampleBuffer;
347 347
348 void 348 void
349 CodedAudioFileReader::pushBufferResampling(float *buffer, size_t sz, 349 CodedAudioFileReader::pushBufferResampling(float *buffer, size_t sz,
350 float ratio, bool final) 350 float ratio, bool final)
351 { 351 {
352 size_t out = m_resampler->resampleInterleaved 352 SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl;
353 (buffer, 353
354 m_resampleBuffer, 354 if (sz > 0) {
355 sz, 355
356 ratio, 356 size_t out = m_resampler->resampleInterleaved
357 false); 357 (buffer,
358 358 m_resampleBuffer,
359 pushBufferNonResampling(m_resampleBuffer, out); 359 sz,
360 ratio,
361 false);
362
363 pushBufferNonResampling(m_resampleBuffer, out);
364 }
360 365
361 if (final) { 366 if (final) {
362 367
363 size_t padFrames = 1; 368 size_t padFrames = 1;
364 if (m_frameCount / ratio < m_fileFrameCount) { 369 if (m_frameCount / ratio < m_fileFrameCount) {
365 padFrames = m_fileFrameCount - (m_frameCount / ratio) + 1; 370 padFrames = m_fileFrameCount - (m_frameCount / ratio) + 1;
366 } 371 }
367 372
368 size_t padSamples = padFrames * m_channelCount; 373 size_t padSamples = padFrames * m_channelCount;
369 374
370 std::cerr << "frameCount = " << m_frameCount << ", equivFileFrames = " << m_frameCount / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << std::endl; 375 SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << m_frameCount / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl;
371 376
372 float *padding = new float[padSamples]; 377 float *padding = new float[padSamples];
373 for (int i = 0; i < padSamples; ++i) padding[i] = 0.f; 378 for (int i = 0; i < padSamples; ++i) padding[i] = 0.f;
374 379
375 out = m_resampler->resampleInterleaved 380 size_t out = m_resampler->resampleInterleaved
376 (padding, 381 (padding,
377 m_resampleBuffer, 382 m_resampleBuffer,
378 padFrames, 383 padFrames,
379 ratio, 384 ratio,
380 true); 385 true);
386
387 if (m_frameCount + out > int(m_fileFrameCount * ratio)) {
388 out = int(m_fileFrameCount * ratio) - m_frameCount;
389 }
381 390
382 pushBufferNonResampling(m_resampleBuffer, out); 391 pushBufferNonResampling(m_resampleBuffer, out);
383 delete[] padding; 392 delete[] padding;
384 } 393 }
385 } 394 }