Toward properly testing reset

This commit is contained in:
Chris Cannam
2023-03-20 10:08:01 +00:00
parent 9e5ebdbafb
commit 2dcb27d3dd
2 changed files with 80 additions and 3 deletions

View File

@@ -545,9 +545,6 @@ R3Stretcher::reset()
cd->reset();
}
m_prevInhop = m_inhop;
m_prevOuthop = int(round(m_inhop * getEffectiveRatio()));
m_studyInputDuration = 0;
m_suppliedInputDuration = 0;
m_totalTargetDuration = 0;
@@ -557,6 +554,14 @@ R3Stretcher::reset()
m_keyFrameMap.clear();
m_mode = ProcessMode::JustCreated;
m_prevInhop = 1;
m_prevOuthop = 1;
calculateHop();
m_prevInhop = m_inhop;
m_prevOuthop = int(round(m_inhop * getEffectiveRatio()));
}
void

View File

@@ -1251,5 +1251,77 @@ BOOST_AUTO_TEST_CASE(final_fast_lower_realtime_finer_after)
false);
}
BOOST_AUTO_TEST_CASE(impulses_2x_5up_offline_reset_finer)
{
int n = 10000;
int rate = 44100;
RubberBandStretcher stretcher
(rate, 1, RubberBandStretcher::OptionEngineFiner);
stretcher.setTimeRatio(2.0);
stretcher.setPitchScale(1.5);
vector<float> in(n, 0.f), out1(n * 2, 0.f), out2(n * 2, 0.f);
in[100] = 1.f;
in[101] = -1.f;
in[5000] = 1.f;
in[5001] = -1.f;
in[9900] = 1.f;
in[9901] = -1.f;
float *inp = in.data(), *outp1 = out1.data(), *outp2 = out2.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 * 2);
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp1, n * 2);
BOOST_TEST(got == n * 2);
BOOST_TEST(stretcher.available() == -1);
stretcher.reset();
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 * 2);
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
got = stretcher.retrieve(&outp2, n * 2);
BOOST_TEST(got == n * 2);
BOOST_TEST(stretcher.available() == -1);
for (int i = 0; i < n * 2; ++i) {
BOOST_TEST(outp1[i] == outp2[i]);
if (outp1[i] != outp2[i]) {
std::cerr << "Failure at index " << i << std::endl;
break;
}
}
/*
std::cout << "ms\tV" << std::endl;
for (int i = 0; i < n*2; ++i) {
std::cout << i << "\t" << out[i] << std::endl;
}
*/
}
BOOST_AUTO_TEST_SUITE_END()