From 4d875a5ef4dbcf70ac433d99d92d9f673b95fb60 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Mon, 13 Oct 2008 19:13:21 +0000 Subject: [PATCH] * Warn and recover if time or pitch ratio is zero (or smaller) --- src/StretcherImpl.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/StretcherImpl.cpp b/src/StretcherImpl.cpp index 126b001..c175ab3 100644 --- a/src/StretcherImpl.cpp +++ b/src/StretcherImpl.cpp @@ -342,6 +342,19 @@ RubberBandStretcher::Impl::calculateSizes() size_t windowSize = m_baseWindowSize; size_t outputIncrement; + if (m_pitchScale <= 0.0) { + // This special case is likelier than one might hope, because + // of naive initialisations in programs that set it from a + // variable + std::cerr << "RubberBandStretcher: WARNING: Pitch scale must be greater than zero!\nResetting it from " << m_pitchScale << " to the default of 1.0: no pitch change will occur" << std::endl; + m_pitchScale = 1.0; + } + if (m_timeRatio <= 0.0) { + // Likewise + std::cerr << "RubberBandStretcher: WARNING: Time ratio must be greater than zero!\nResetting it from " << m_timeRatio << " to the default of 1.0: no time stretch will occur" << std::endl; + m_timeRatio = 1.0; + } + double r = getEffectiveRatio(); if (m_realtime) {