diff --git a/src/StretcherChannelData.cpp b/src/StretcherChannelData.cpp index 8378975..968feb5 100644 --- a/src/StretcherChannelData.cpp +++ b/src/StretcherChannelData.cpp @@ -104,6 +104,14 @@ RubberBandStretcher::Impl::ChannelData::construct(const std::set &window for (size_t i = 0; i < initialWindowSize * oversample; ++i) { dblbuf[i] = 0.0; } + + for (size_t i = 0; i < maxSize; ++i) { + accumulator[i] = 0.f; + windowAccumulator[i] = 0.f; + } + + // Avoid dividing opening sample (which will be discarded anyway) by zero + windowAccumulator[0] = 1.f; } void diff --git a/src/StretcherImpl.cpp b/src/StretcherImpl.cpp index c175ab3..7ec7c16 100644 --- a/src/StretcherImpl.cpp +++ b/src/StretcherImpl.cpp @@ -934,9 +934,18 @@ RubberBandStretcher::Impl::calculateStretch() { Profiler profiler("RubberBandStretcher::Impl::calculateStretch"); + size_t inputDuration = m_inputDuration; + + if (!m_realtime && m_expectedInputDuration > 0) { + if (m_expectedInputDuration != inputDuration) { + std::cerr << "RubberBandStretcher: WARNING: Actual study() duration differs from duration set by setExpectedInputDuration (" << m_inputDuration << " vs " << m_expectedInputDuration << ", diff = " << (m_expectedInputDuration - m_inputDuration) << "), using the latter for calculation" << std::endl; + inputDuration = m_expectedInputDuration; + } + } + std::vector increments = m_stretchCalculator->calculate (getEffectiveRatio(), - m_inputDuration, + inputDuration, m_phaseResetDf, m_stretchDf); diff --git a/src/StretcherProcess.cpp b/src/StretcherProcess.cpp index 7c3f1e7..3f7d1fb 100644 --- a/src/StretcherProcess.cpp +++ b/src/StretcherProcess.cpp @@ -735,7 +735,7 @@ RubberBandStretcher::Impl::modifyChunk(size_t channel, bool inherit = false; if (laminar) { - if (distance >= mi) { + if (distance >= mi || i == count) { inherit = false; } else if (bandlimited && (i == bandhigh || i == bandlow)) { inherit = false; diff --git a/src/sysutils.cpp b/src/sysutils.cpp index 1e6ef3a..af482e9 100644 --- a/src/sysutils.cpp +++ b/src/sysutils.cpp @@ -110,7 +110,7 @@ float *allocFloat(float *ptr, int count) void *allocated; #ifndef _WIN32 #ifndef __APPLE__ - if (!posix_memalign(&allocated, 16, count * sizeof(float))) + if (posix_memalign(&allocated, 16, count * sizeof(float))) #endif #endif allocated = malloc(count * sizeof(float)); @@ -134,7 +134,7 @@ double *allocDouble(double *ptr, int count) void *allocated; #ifndef _WIN32 #ifndef __APPLE__ - if (!posix_memalign(&allocated, 16, count * sizeof(double))) + if (posix_memalign(&allocated, 16, count * sizeof(double))) #endif #endif allocated = malloc(count * sizeof(double));