diff data/fileio/CodedAudioFileReader.cpp @ 1379:96a6ea30933e

Fix occasional off-by-one error in resampled audio file reader
author Chris Cannam
date Tue, 21 Feb 2017 17:42:40 +0000
parents 49b43306778b
children cc62d7862203
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Tue Feb 21 16:04:11 2017 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Tue Feb 21 17:42:40 2017 +0000
@@ -525,8 +525,12 @@
              ratio,
              true);
 
-        if (m_frameCount + out > sv_frame_t(double(m_fileFrameCount) * ratio)) {
-            out = sv_frame_t(double(m_fileFrameCount) * ratio) - m_frameCount;
+        SVDEBUG << "CodedAudioFileReader::pushBufferResampling: resampled padFrames to " << out << " frames" << endl;
+
+        sv_frame_t expected = sv_frame_t(round(double(m_fileFrameCount) * ratio));
+        if (m_frameCount + out > expected) {
+            out = expected - m_frameCount;
+            SVDEBUG << "CodedAudioFileReader::pushBufferResampling: clipping that to " << out << " to avoid producing more samples than desired" << endl;
         }
 
         pushBufferNonResampling(m_resampleBuffer, out);