85ade17eb881 — Chris Cannam 7 months ago
Some work on warnings and tests
2 files changed, 43 insertions(+), 14 deletions(-)

M src/finer/R3LiveShifter.cpp
M src/test/TestLiveShifter.cpp
M src/finer/R3LiveShifter.cpp +5 -3
@@ 331,7 331,7 @@ R3LiveShifter::shift(const float *const 
 
     int incount = int(getBlockSize());
     
-    m_log.log(2, "R3LiveShifter::shift: start of process with incount", incount);
+    m_log.log(2, "R3LiveShifter::shift: start of shift with incount", incount);
     m_log.log(2, "R3LiveShifter::shift: initially in inbuf", m_channelData[0]->inbuf->getReadSpace());
     m_log.log(2, "R3LiveShifter::shift: initially in outbuf", m_channelData[0]->outbuf->getReadSpace());
 

          
@@ 492,7 492,7 @@ R3LiveShifter::generate(int requiredInOu
 
     int atInput = cd0->inbuf->getReadSpace();
     if (atInput <= ws) {
-        m_log.log(0, "R3LiveShifter::generate: insufficient samples at input: have and require more than", atInput, ws);
+        m_log.log(2, "R3LiveShifter::generate: insufficient samples at input: have and require more than", atInput, ws);
         return;
     }
 

          
@@ 658,7 658,9 @@ R3LiveShifter::readOut(float *const *out
     
         for (int c = 0; c < m_parameters.channels; ++c) {
             auto &cd = m_channelData.at(c);
-            int gotHere = cd->outbuf->read(cd->resampled.data(), got);
+            int available = cd->outbuf->getReadSpace();
+            int gotHere = cd->outbuf->read
+                (cd->resampled.data(), std::min(got, available));
             if (gotHere < got) {
                 if (c > 0) {
                     m_log.log(0, "R3LiveShifter::readOut: WARNING: channel imbalance detected");

          
M src/test/TestLiveShifter.cpp +38 -11
@@ 76,16 76,43 @@ static void check_sinusoid_unchanged(int
     
     // We now have n samples of a simple sinusoid with stretch factor
     // 1.0; obviously we expect the output to be essentially the same
-    // thing. It will have lower precision for a while at the start
-    // and end because of windowing factors, so we check those with a
-    // threshold of 0.1; in the middle we expect better
-    // precision. Note that these are relative tolerances, not
-    // absolute, i.e. 0.001 means 0.001x the smaller value - so they
-    // are tighter than they appear.
+    // thing. It will have lower precision for a while at the start,
+    // so we check that with a threshold of 0.1; after that we expect
+    // better precision.
+
+    int slackpart = 2048;
+    float slackeps = 1.0e-1f;
+    float eps = 1.0e-3f;
 
-    BOOST_TEST(vector<float>(out.begin() + delay, out.begin() + n) ==
-               vector<float>(in.begin(), in.begin() + n - delay),
-               tt::tolerance(0.001f) << tt::per_element());
+#ifdef USE_BQRESAMPLER
+    eps = 1.0e-2f;
+#endif
+    
+    for (int i = 0; i < slackpart; ++i) {
+        float fin = in[i];
+        float fout = out[delay + i];
+        float err = fabsf(fin - fout);
+        if (err > slackeps) {
+            std::cerr << "Error at index " << i << " exceeds slack eps "
+                      << slackeps << ": output " << fout << " - input "
+                      << fin << " = " << fout - fin << std::endl;
+            BOOST_TEST(err < eps);
+            break;
+        }
+    }
+    
+    for (int i = slackpart; i < n - delay; ++i) {
+        float fin = in[i];
+        float fout = out[delay + i];
+        float err = fabsf(fin - fout);
+        if (err > eps) {
+            std::cerr << "Error at index " << i << " exceeds tight eps "
+                      << eps << ": output " << fout << " - input "
+                      << fin << " = " << fout - fin << std::endl;
+            BOOST_TEST(err < eps);
+            break;
+        }
+    }
 
     if (printDebug) {
         RubberBandLiveShifter::setDefaultDebugLevel(0);

          
@@ 107,7 134,7 @@ static void check_sinusoid_unchanged(int
             std::cout << "SHIFTED," << i << "," << out[i + delay] << std::endl;
         }
 
-        std::cout << "DIFF,V" << std::endl;
+        std::cout << "DIFF,sample,V" << std::endl;
         for (int i = 0; i + delay < int(in.size()); ++i) {
             std::cout << "DIFF," << i << "," << out[i + delay] - in[i] << std::endl;
         }

          
@@ 130,7 157,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_
         RubberBandLiveShifter::OptionPitchMethodAlternate;
     int n = 100000;
 
-    check_sinusoid_unchanged(n, 44100, 440.f, options, false);
+    check_sinusoid_unchanged(n, 44100, 440.f, options, true);
     check_sinusoid_unchanged(n, 48000, 260.f, options, false);
 }