diff --git a/src/test/TestStretcher.cpp b/src/test/TestStretcher.cpp index db29c66..5f2355f 100644 --- a/src/test/TestStretcher.cpp +++ b/src/test/TestStretcher.cpp @@ -36,12 +36,14 @@ namespace tt = boost::test_tools; BOOST_AUTO_TEST_SUITE(TestStretcher) -BOOST_AUTO_TEST_CASE(sinusoid_unchanged_single_offline) +BOOST_AUTO_TEST_CASE(sinusoid_unchanged_single_offline_faster) { int n = 10000; float freq = 440.f; int rate = 44100; - RubberBandStretcher stretcher(rate, 1); + RubberBandStretcher stretcher + (rate, 1, RubberBandStretcher::OptionEngineFaster); + vector in(n), out(n); for (int i = 0; i < n; ++i) { in[i] = sinf(float(i) * freq * M_PI * 2.f / float(rate)); @@ -58,6 +60,8 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_single_offline) stretcher.process(&inp, n, true); BOOST_TEST(stretcher.available() == n); + BOOST_TEST(stretcher.getLatency() == 0); // offline mode + size_t got = stretcher.retrieve(&outp, n); BOOST_TEST(got == n); BOOST_TEST(stretcher.available() == -1); @@ -66,7 +70,10 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_single_offline) // 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. + // threshold of 0.1; in the middle we expect better + // precision. Note that these are relative precisions, not + // absolute, i.e. 0.001 means 0.001 of the smaller value - so they + // are tighter than they appear. // This syntax for comparing containers with a certain tolerance // using BOOST_TEST is just bonkers. I can't find the << syntax to @@ -80,9 +87,57 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_single_offline) BOOST_TEST(in == out, tt::tolerance(0.1f) << tt::per_element()); - BOOST_TEST(vector(in.begin() + 1000, in.begin() + n - 1000) == - vector(out.begin() + 1000, out.begin() + n - 1000), - tt::tolerance(0.0001f) << tt::per_element()); + BOOST_TEST(vector(in.begin() + 1024, in.begin() + n - 1024) == + vector(out.begin() + 1024, out.begin() + n - 1024), + tt::tolerance(0.001f) << tt::per_element()); +} + +BOOST_AUTO_TEST_CASE(sinusoid_unchanged_single_offline_finer) +{ + int n = 10000; + float freq = 440.f; + int rate = 44100; + + RubberBandStretcher stretcher + (rate, 1, RubberBandStretcher::OptionEngineFiner); + + vector in(n), out(n); + for (int i = 0; i < n; ++i) { + in[i] = sinf(float(i) * freq * M_PI * 2.f / float(rate)); + } + float *inp = in.data(), *outp = out.data(); + + stretcher.setMaxProcessSize(n); + stretcher.setExpectedInputDuration(n); + BOOST_TEST(stretcher.available() == 0); + + stretcher.study(&inp, n, true); + BOOST_TEST(stretcher.available() == 0); + + stretcher.process(&inp, n, true); + BOOST_TEST(stretcher.available() == n); + + BOOST_TEST(stretcher.getLatency() == 0); // offline mode + + size_t got = stretcher.retrieve(&outp, n); + BOOST_TEST(got == n); + BOOST_TEST(stretcher.available() == -1); + + // The R3 engine is actually less precise than R2 here because of + // its different windowing design, though see the note above about + // what these tolerances mean + + BOOST_TEST(in == out, + tt::tolerance(0.15f) << tt::per_element()); + + BOOST_TEST(vector(in.begin() + 1024, in.begin() + n - 1024) == + vector(out.begin() + 1024, out.begin() + n - 1024), + tt::tolerance(0.01f) << tt::per_element()); + +// std::cout << "ms\tV" << std::endl; +// for (int i = 0; i < n; ++i) { +// std::cout << i << "\t" << out[i] - in[i] << std::endl; +// } } BOOST_AUTO_TEST_SUITE_END()