From d2f4833a0a49d622444df8a658a47f8830b87146 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Tue, 6 Nov 2007 23:07:13 +0000 Subject: [PATCH] ... --- src/StretchCalculator.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/StretchCalculator.cpp b/src/StretchCalculator.cpp index caf72ef..e970d5a 100644 --- a/src/StretchCalculator.cpp +++ b/src/StretchCalculator.cpp @@ -567,9 +567,23 @@ StretchCalculator::distributeRegion(const std::vector &dfIn, } } -// for (size_t i = 0; i < df.size(); ++i) { -// if (i == 0 || df[i] > maxDf) maxDf = df[i]; -// } + float maxDf = 0; + + for (size_t i = 0; i < df.size(); ++i) { + if (i == 0 || df[i] > maxDf) maxDf = df[i]; + } + + // We want to try to ensure the last 100ms or so (if possible) are + // tending back towards the maximum df, so that the stretchiness + // reduces at the end of the stretched region. + + int reducedRegion = (0.1 * m_sampleRate) / m_increment; + if (reducedRegion > df.size()/5) reducedRegion = df.size()/5; + + for (size_t i = 0; i < reducedRegion; ++i) { + size_t index = df.size() - reducedRegion + i; + df[index] = df[index] + ((maxDf - df[index]) * i) / reducedRegion; + } long toAllot = long(duration) - long(m_increment * df.size()); // bool negative = (toAllot < 0); @@ -600,7 +614,7 @@ StretchCalculator::distributeRegion(const std::vector &dfIn, double totalDisplacement = 0; double maxDisplacement = 0; // min displacement will be 0 by definition - float maxDf = 0; + maxDf = 0; float adj = 0; while (!acceptableSquashRange) {