From 8df9558868754c06d42f219ed4137d9fb076458f Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Tue, 22 Sep 2020 10:35:50 +0100 Subject: [PATCH] In this emergency, increase the buffer size by a factor rather than only by a constant amount - because if this arises because of an overlong increment being broken down into littler bits, we would end up doing it again and again, which is much more expensive. This makes a huge performance difference in cases where a time map ends up mapping very little input into a great expanse of output --- src/StretcherProcess.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/StretcherProcess.cpp b/src/StretcherProcess.cpp index 39da682..d8c912e 100644 --- a/src/StretcherProcess.cpp +++ b/src/StretcherProcess.cpp @@ -521,7 +521,14 @@ RubberBandStretcher::Impl::processChunkForChannel(size_t c, // This is an unhappy situation. RingBuffer *oldbuf = cd.outbuf; - cd.outbuf = oldbuf->resized(oldbuf->getSize() + (required - ws)); + cd.outbuf = oldbuf->resized(oldbuf->getSize() * 2); + + if (m_debugLevel > 1) { + cerr << "(Write space was " << ws << ", needed " << required + << ": resized output buffer from " << oldbuf->getSize() + << " to " << cd.outbuf->getSize() << ")" << endl; + } + m_emergencyScavenger.claim(oldbuf); }