changeset 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 b5728e69802b
children 0a729b57b4e4
files data/fileio/CodedAudioFileReader.cpp
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
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);