Padding and key-frame fixes

This commit is contained in:
Chris Cannam
2022-06-29 16:51:18 +01:00
parent 56c60d2420
commit 54b10f155c

View File

@@ -328,23 +328,17 @@ R3Stretcher::updateRatioFromMap()
keyFrameAtOutput = m_totalTargetDuration; keyFrameAtOutput = m_totalTargetDuration;
} }
// size_t toKeyFrameAtInput = keyFrameAtInput - i0->first; size_t toKeyFrameAtInput = keyFrameAtInput - i0->first;
// size_t toKeyFrameAtOutput = keyFrameAtOutput - i0->second; size_t toKeyFrameAtOutput = keyFrameAtOutput - i0->second;
size_t toKeyFrameAtInput = keyFrameAtInput - m_processInputDuration;
size_t toKeyFrameAtOutput = 0;
if (keyFrameAtOutput > m_totalOutputDuration) {
toKeyFrameAtOutput = keyFrameAtOutput - m_totalOutputDuration;
}
double ratio = double(toKeyFrameAtOutput) / double(toKeyFrameAtInput); double ratio = double(toKeyFrameAtOutput) / double(toKeyFrameAtInput);
m_log.log(1, "next key frame input and output", m_log.log(1, "next key frame input and output",
double(keyFrameAtInput), double(keyFrameAtOutput)); double(keyFrameAtInput), double(keyFrameAtOutput));
m_log.log(1, "diff to next key frame input and output",
double(toKeyFrameAtInput), double(toKeyFrameAtOutput));
m_log.log(1, "current input and output", m_log.log(1, "current input and output",
double(m_processInputDuration), double(m_totalOutputDuration)); double(m_processInputDuration), double(m_totalOutputDuration));
m_log.log(1, "to next key frame input and output",
double(toKeyFrameAtInput), double(toKeyFrameAtOutput));
m_log.log(1, "new ratio", ratio); m_log.log(1, "new ratio", ratio);
m_timeRatio = ratio; m_timeRatio = ratio;
@@ -487,11 +481,9 @@ R3Stretcher::process(const float *const *input, size_t samples, bool final)
} }
// Update this on every process round, checking whether we've // Update this on every process round, checking whether we've
// surpassed th next key frame yet. It's important that we do // surpassed the next key frame yet. This must follow the
// this (the first time through) before the padding // overall target calculation above, which uses the "global"
// calculation below, since it may change the effective // time ratio, but precede any other use of the time ratio.
// starting ratio. But it has to follow the overall target
// calculation above, which uses the "global" ratio.
if (!m_keyFrameMap.empty()) { if (!m_keyFrameMap.empty()) {
updateRatioFromMap(); updateRatioFromMap();
@@ -504,13 +496,11 @@ R3Stretcher::process(const float *const *input, size_t samples, bool final)
createResampler(); createResampler();
} }
// Pad to the longest frame. As with R2, in real-time mode // Pad to half the longest frame. As with R2, in real-time
// we don't do this -- it's better to start with a swoosh // mode we don't do this -- it's better to start with a
// than introduce more latency, and we don't want gaps // swoosh than introduce more latency, and we don't want
// when the ratio changes. // gaps when the ratio changes.
int pad = m_guideConfiguration.longestFftSize / 2;
int half = m_guideConfiguration.longestFftSize / 2;
int pad = half + half;
m_log.log(1, "offline mode: prefilling with", pad); m_log.log(1, "offline mode: prefilling with", pad);
for (int c = 0; c < m_parameters.channels; ++c) { for (int c = 0; c < m_parameters.channels; ++c) {
m_channelData[c]->inbuf->zero(pad); m_channelData[c]->inbuf->zero(pad);
@@ -518,8 +508,7 @@ R3Stretcher::process(const float *const *input, size_t samples, bool final)
// NB by the time we skip this later we may have resampled // NB by the time we skip this later we may have resampled
// as well as stretched // as well as stretched
m_startSkip = int(round(pad / m_pitchScale));
m_startSkip = half + int(round(half / m_pitchScale * m_timeRatio));
if (m_startSkip < 0) { if (m_startSkip < 0) {
m_log.log(0, "WARNING: calculated start skip < 0", m_startSkip); m_log.log(0, "WARNING: calculated start skip < 0", m_startSkip);
m_startSkip = 0; m_startSkip = 0;