changeset 1538:fa67fbbff8fc zoom

Oversampler fixes and further tests
author Chris Cannam
date Wed, 26 Sep 2018 15:11:26 +0100
parents c5092ca1c6e5
children 0b08bc8741c6
files data/model/WaveformOversampler.cpp data/model/test/TestWaveformOversampler.h
diffstat 2 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/WaveformOversampler.cpp	Wed Sep 26 14:44:38 2018 +0100
+++ b/data/model/WaveformOversampler.cpp	Wed Sep 26 15:11:26 2018 +0100
@@ -38,11 +38,11 @@
         double pos = (double(i) / oversampleBy) * m_filterRatio;
         double diff = pos - floor(pos);
         int ix = int(floor(pos));
-        float interpolated = (1.0 - diff) * fixedRatio[ix];
+        double interpolated = (1.0 - diff) * fixedRatio[ix];
         if (in_range_for(fixedRatio, ix + 1)) {
             interpolated += diff * fixedRatio[ix + 1];
         }
-        result[i] = interpolated;
+        result[i] = float(interpolated);
     }
 
     return result;
@@ -65,7 +65,7 @@
     
     sv_frame_t filterLength = m_filter.size(); // NB this is known to be odd
     sv_frame_t filterTailOut = (filterLength - 1) / 2;
-    sv_frame_t filterTailIn = filterTailIn / m_filterRatio;
+    sv_frame_t filterTailIn = filterTailOut / m_filterRatio;
 
     floatvec_t oversampled(targetFrameCount, 0.f);
 
@@ -77,7 +77,7 @@
     if (i1 > sourceLength) {
         i1 = sourceLength;
     }
-
+    
     floatvec_t sourceData = source->getData(channel, i0, i1 - i0);
     
     for (sv_frame_t i = i0; i < i1; ++i) {
--- a/data/model/test/TestWaveformOversampler.h	Wed Sep 26 14:44:38 2018 +0100
+++ b/data/model/test/TestWaveformOversampler.h	Wed Sep 26 15:11:26 2018 +0100
@@ -35,7 +35,7 @@
         m_source[2501] = -0.5f;
         m_source[4999] = -1.f;
         for (int i = 4000; i < 4900; ++i) {
-            m_source[i] = sin(double(i - 1000) * M_PI / 50.0);
+            m_source[i] = float(sin(double(i - 1000) * M_PI / 50.0));
         }
         m_sourceModel = new WritableWaveFileModel(8000, 1);
         const float *d = m_source.data();
@@ -70,7 +70,7 @@
 
     floatvec_t get(sv_frame_t sourceStartFrame,
                    sv_frame_t sourceFrameCount,
-                   sv_frame_t oversampleBy) {
+                   int oversampleBy) {
         return WaveformOversampler::getOversampledData
             (m_sourceModel, 0,
              sourceStartFrame, sourceFrameCount, oversampleBy);
@@ -194,6 +194,14 @@
         testStrided(0, 500, 4, sourceSubset(0, 500));
         testStrided(4500, 500, 4, sourceSubset(4500, 500));
         testStrided(2000, 1000, 4, sourceSubset(2000, 1000));
+
+        // check for windowed sinc values between the original
+        // samples, even when the original sample that was the source
+        // of this sinc kernel is not within the requested range
+        floatvec_t output = get(1, 10, 4);
+        QVERIFY(output[1] + 0.1787 < 0.0001);
+        QVERIFY(output[2] + 0.2099 < 0.0001);
+        QVERIFY(output[3] + 0.1267 < 0.0001);
     }
     
     void testOverlaps4x() {