changeset 1320:983667969a82 3.0-integration

Update to reflect bqresample API change
author Chris Cannam
date Fri, 09 Dec 2016 10:24:40 +0000
parents 12a1da4719c7
children ca43c4b7719c e939a365e4d2
files data/fileio/CodedAudioFileReader.cpp data/fileio/CodedAudioFileReader.h
diffstat 2 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Wed Dec 07 13:56:22 2016 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Fri Dec 09 10:24:40 2016 +0000
@@ -42,9 +42,10 @@
     m_cacheFileReader(0),
     m_cacheWriteBuffer(0),
     m_cacheWriteBufferIndex(0),
-    m_cacheWriteBufferSize(65536),
+    m_cacheWriteBufferFrames(65536),
     m_resampler(0),
     m_resampleBuffer(0),
+    m_resampleBufferFrames(0),
     m_fileFrameCount(0),
     m_normalised(normalised),
     m_max(0.f),
@@ -146,13 +147,14 @@
         m_resampler = new breakfastquay::Resampler
             (breakfastquay::Resampler::FastestTolerable,
              m_channelCount,
-             m_cacheWriteBufferSize);
+             int(m_cacheWriteBufferFrames));
         double ratio = m_sampleRate / m_fileRate;
-        m_resampleBuffer = new float
-            [lrint(ceil(double(m_cacheWriteBufferSize) * m_channelCount * ratio + 1))];
+        m_resampleBufferFrames = int(ceil(double(m_cacheWriteBufferFrames) *
+                                          ratio + 1));
+        m_resampleBuffer = new float[m_resampleBufferFrames * m_channelCount];
     }
 
-    m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount];
+    m_cacheWriteBuffer = new float[m_cacheWriteBufferFrames * m_channelCount];
     m_cacheWriteBufferIndex = 0;
 
     if (m_cacheMode == CacheInTemporaryFile) {
@@ -228,8 +230,8 @@
         m_data.clear();
     }
 
-    if (m_trimFromEnd >= (m_cacheWriteBufferSize * m_channelCount)) {
-        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";
+    if (m_trimFromEnd >= (m_cacheWriteBufferFrames * m_channelCount)) {
+        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";
         m_trimFromEnd = 0;
     }
 
@@ -362,7 +364,7 @@
 {
     if (final ||
         (m_cacheWriteBufferIndex ==
-         m_cacheWriteBufferSize * m_channelCount)) {
+         m_cacheWriteBufferFrames * m_channelCount)) {
 
         if (m_trimFromEnd > 0) {
         
@@ -483,8 +485,9 @@
     if (sz > 0) {
 
         sv_frame_t out = m_resampler->resampleInterleaved
-            (buffer,
-             m_resampleBuffer,
+            (m_resampleBuffer,
+             m_resampleBufferFrames,
+             buffer,
              sz,
              ratio,
              false);
@@ -507,8 +510,9 @@
         for (sv_frame_t i = 0; i < padSamples; ++i) padding[i] = 0.f;
 
         sv_frame_t out = m_resampler->resampleInterleaved
-            (padding,
-             m_resampleBuffer,
+            (m_resampleBuffer,
+             m_resampleBufferFrames,
+             padding,
              padFrames,
              ratio,
              true);
--- a/data/fileio/CodedAudioFileReader.h	Wed Dec 07 13:56:22 2016 +0000
+++ b/data/fileio/CodedAudioFileReader.h	Fri Dec 09 10:24:40 2016 +0000
@@ -105,11 +105,12 @@
     SNDFILE *m_cacheFileWritePtr;
     WavFileReader *m_cacheFileReader;
     float *m_cacheWriteBuffer;
-    sv_frame_t m_cacheWriteBufferIndex; // samples
-    sv_frame_t m_cacheWriteBufferSize; // frames
+    sv_frame_t m_cacheWriteBufferIndex;  // buffer write pointer in samples
+    sv_frame_t m_cacheWriteBufferFrames; // buffer size in frames
 
     breakfastquay::Resampler *m_resampler;
     float *m_resampleBuffer;
+    int m_resampleBufferFrames;
     sv_frame_t m_fileFrameCount;
 
     bool m_normalised;