Introduce getPreferredStartPad(), deprecate getLatency() and replace with getStartDelay(); document and test both

This commit is contained in:
Chris Cannam
2022-07-05 17:53:36 +01:00
parent 31984af826
commit 72654b04ea
8 changed files with 255 additions and 70 deletions

View File

@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_offline_faster)
stretcher.process(&inp, n, true);
BOOST_TEST(stretcher.available() == n);
BOOST_TEST(stretcher.getLatency() == 0); // offline mode
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp, n);
BOOST_TEST(got == n);
@@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_offline_finer)
stretcher.process(&inp, n, true);
BOOST_TEST(stretcher.available() == n);
BOOST_TEST(stretcher.getLatency() == 0); // offline mode
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp, n);
BOOST_TEST(got == n);
@@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_2x_offline_finer)
stretcher.process(&inp, n, true);
BOOST_TEST(stretcher.available() == n*2);
BOOST_TEST(stretcher.getLatency() == 0); // offline mode
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp, n*2);
BOOST_TEST(got == n*2);
@@ -225,11 +225,13 @@ BOOST_AUTO_TEST_CASE(sinusoid_2x_offline_finer)
BOOST_TEST(rms < 0.1);
}
BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
static void sinusoid_realtime(RubberBandStretcher::Options options,
double timeRatio,
double pitchScale,
bool printDebug)
{
int n = 40000;
int multiple = 8;
int nOut = n * multiple;
int n = (timeRatio < 1.0 ? 80000 : 40000);
int nOut = int(ceil(n * timeRatio));
float freq = 441.f;
int rate = 44100;
int bs = 512;
@@ -238,12 +240,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
// latency compensation, and checks that the output is all in the
// expected place
RubberBandStretcher stretcher
(rate, 1,
RubberBandStretcher::OptionEngineFiner |
RubberBandStretcher::OptionProcessRealTime |
RubberBandStretcher::OptionFormantPreserved,
multiple, 1.0);
RubberBandStretcher stretcher(rate, 1, options, timeRatio, pitchScale);
stretcher.setMaxProcessSize(bs);
@@ -264,10 +261,10 @@ BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
// Prime the start
{
float *source = out.data(); // just reuse out because it's silent
stretcher.process(&source, stretcher.getLatency(), false);
stretcher.process(&source, stretcher.getPreferredStartPad(), false);
}
int toSkip = stretcher.getLatency();
int toSkip = stretcher.getStartDelay();
int inOffset = 0, outOffset = 0;
@@ -297,7 +294,12 @@ BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
float *source = in.data() + inOffset;
stretcher.process(&source, toProcess, toProcess < required);
inOffset += toProcess;
BOOST_TEST(stretcher.available() > 0);
if (options & RubberBandStretcher::OptionEngineFiner) {
//!!! Faster engine sometimes does return
// available == 0 here - I'm not sure why, need to
// look into this. The process still completes fine
BOOST_TEST(stretcher.available() > 0);
}
continue;
} else { // available > 0
@@ -317,10 +319,12 @@ BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
}
}
// std::cout << "sample\tV" << std::endl;
// for (int i = 0; i < nOut; ++i) {
// std::cout << i << "\t" << out[i] << std::endl;
// }
if (printDebug) {
std::cout << "sample\tV" << std::endl;
for (int i = 0; i < nOut; ++i) {
std::cout << i << "\t" << out[i] << std::endl;
}
}
// Step through the output signal in chunk of 1/20 of its duration
// (i.e. a rather arbitrary two per expected 0.1 increment in
@@ -341,15 +345,36 @@ BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
}
}
int expectedCrossings = int(round((freq * double(i1 - i0)) / rate));
int expectedCrossings = int(round((freq * pitchScale *
double(i1 - i0)) / rate));
// In the last chunk we can miss one crossing
if (chunk == 19) {
BOOST_TEST(positiveCrossings <= expectedCrossings);
BOOST_TEST(positiveCrossings >= expectedCrossings - 1);
// std::cout << chunk << std::endl;
// The check here has to depend on whether we are in Finer or
// Faster mode. In Finer mode, we expect to be generally exact
// but in the first and last chunks we can be out by one
// crossing if slowing, more if speeding up. In Faster mode we
// need to cut more slack
int slack = 0;
if (options & RubberBandStretcher::OptionEngineFiner) {
if (chunk == 0 || chunk == 19) {
slack = (timeRatio < 1.0 ? 10 : 1);
}
} else {
BOOST_TEST(positiveCrossings == expectedCrossings);
if (chunk == 0) {
slack = (timeRatio < 1.0 ? 10 : 2);
} else if (chunk == 19) {
// all bets are off, practically
slack = expectedCrossings / 2;
} else {
slack = 1;
}
}
BOOST_TEST(positiveCrossings <= expectedCrossings + slack);
BOOST_TEST(positiveCrossings >= expectedCrossings - slack);
// amplitude
@@ -364,6 +389,86 @@ BOOST_AUTO_TEST_CASE(sinusoid_8x_realtime_finer)
}
}
BOOST_AUTO_TEST_CASE(sinusoid_slow_samepitch_realtime_finer)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFiner |
RubberBandStretcher::OptionProcessRealTime,
8.0, 1.0,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_slow_samepitch_realtime_faster)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFaster |
RubberBandStretcher::OptionProcessRealTime,
8.0, 1.0,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_fast_samepitch_realtime_finer)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFiner |
RubberBandStretcher::OptionProcessRealTime,
0.5, 1.0,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_fast_samepitch_realtime_faster)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFaster |
RubberBandStretcher::OptionProcessRealTime,
0.5, 1.0,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_slow_higher_realtime_finer)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFiner |
RubberBandStretcher::OptionProcessRealTime,
4.0, 1.5,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_slow_higher_realtime_faster)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFaster |
RubberBandStretcher::OptionProcessRealTime,
4.0, 1.5,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_fast_higher_realtime_finer)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFiner |
RubberBandStretcher::OptionProcessRealTime,
0.5, 1.5,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_fast_higher_realtime_faster)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFaster |
RubberBandStretcher::OptionProcessRealTime,
0.5, 1.5,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_slow_lower_realtime_finer)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFiner |
RubberBandStretcher::OptionProcessRealTime,
8.0, 0.5,
false);
}
BOOST_AUTO_TEST_CASE(sinusoid_slow_lower_realtime_faster)
{
sinusoid_realtime(RubberBandStretcher::OptionEngineFaster |
RubberBandStretcher::OptionProcessRealTime,
8.0, 0.5,
false);
}
BOOST_AUTO_TEST_CASE(impulses_2x_offline_faster)
{
int n = 10000;
@@ -396,7 +501,7 @@ BOOST_AUTO_TEST_CASE(impulses_2x_offline_faster)
stretcher.process(&inp, n, true);
BOOST_TEST(stretcher.available() == n * 2);
BOOST_TEST(stretcher.getLatency() == 0); // offline mode
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp, n * 2);
BOOST_TEST(got == n * 2);
@@ -465,7 +570,7 @@ BOOST_AUTO_TEST_CASE(impulses_2x_offline_finer)
stretcher.process(&inp, n, true);
BOOST_TEST(stretcher.available() == n * 2);
BOOST_TEST(stretcher.getLatency() == 0); // offline mode
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp, n * 2);
BOOST_TEST(got == n * 2);
@@ -535,7 +640,7 @@ BOOST_AUTO_TEST_CASE(impulses_2x_5up_offline_finer)
stretcher.process(&inp, n, true);
BOOST_TEST(stretcher.available() == n * 2);
BOOST_TEST(stretcher.getLatency() == 0); // offline mode
BOOST_TEST(stretcher.getStartDelay() == 0); // offline mode
size_t got = stretcher.retrieve(&outp, n * 2);
BOOST_TEST(got == n * 2);