From 5b379121c7086a0ab8e938f3b11f3b2ab8fd0503 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Thu, 9 May 2024 17:15:42 +0100 Subject: [PATCH] Some work on warnings and tests --- src/finer/R3LiveShifter.cpp | 8 +++--- src/test/TestLiveShifter.cpp | 49 ++++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/finer/R3LiveShifter.cpp b/src/finer/R3LiveShifter.cpp index 42f849b..b615f98 100644 --- a/src/finer/R3LiveShifter.cpp +++ b/src/finer/R3LiveShifter.cpp @@ -331,7 +331,7 @@ R3LiveShifter::shift(const float *const *input, float *const *output) 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 requiredInOutbuf) 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 *output, int outcount) 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"); diff --git a/src/test/TestLiveShifter.cpp b/src/test/TestLiveShifter.cpp index 884d180..9e8d8f7 100644 --- a/src/test/TestLiveShifter.cpp +++ b/src/test/TestLiveShifter.cpp @@ -76,16 +76,43 @@ static void check_sinusoid_unchanged(int n, int rate, float freq, // 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. - BOOST_TEST(vector(out.begin() + delay, out.begin() + n) == - vector(in.begin(), in.begin() + n - delay), - tt::tolerance(0.001f) << tt::per_element()); + int slackpart = 2048; + float slackeps = 1.0e-1f; + float eps = 1.0e-3f; + +#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 n, int rate, float freq, 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_mode_b) 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); }