From 35dc16b611f7511f70f250985a80f4d6beb4392e Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Fri, 16 Nov 2007 22:22:01 +0000 Subject: [PATCH] * Various tweaks to improve performance at large ratios --- src/StretcherImpl.cpp | 6 ++++-- src/StretcherProcess.cpp | 30 ++++++++++++++++++++++++++- src/ladspa/RubberBandPitchShifter.cpp | 10 ++++----- src/main.cpp | 2 +- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/StretcherImpl.cpp b/src/StretcherImpl.cpp index 8462283..42c4d2d 100644 --- a/src/StretcherImpl.cpp +++ b/src/StretcherImpl.cpp @@ -303,7 +303,8 @@ RubberBandStretcher::Impl::calculateSizes() inputIncrement /= 2; outputIncrement = lrint(ceil(inputIncrement * r)); } - blockSize = std::max(blockSize, roundUp(outputIncrement * 4.5)); + blockSize = std::max(blockSize, roundUp(outputIncrement * 6)); + if (r > 5) while (blockSize < 8192) blockSize *= 2; } } else { @@ -327,6 +328,7 @@ RubberBandStretcher::Impl::calculateSizes() inputIncrement = int(outputIncrement / r); } blockSize = std::max(blockSize, roundUp(outputIncrement * 6)); + if (r > 5) while (blockSize < 8192) blockSize *= 2; } } @@ -391,7 +393,7 @@ RubberBandStretcher::Impl::calculateSizes() //necessary. clearly something wrong in our calculations... or do //we just need to ensure client calls setMaxProcessBlockSize? if (!m_realtime && !m_threaded) { -//!!! m_outbufSize = m_outbufSize * 2; + m_outbufSize = m_outbufSize * 2; } } diff --git a/src/StretcherProcess.cpp b/src/StretcherProcess.cpp index fba0fe7..d025444 100644 --- a/src/StretcherProcess.cpp +++ b/src/StretcherProcess.cpp @@ -481,9 +481,27 @@ RubberBandStretcher::Impl::modifyChunk(size_t channel, size_t outputIncrement, cd.freqPeak[0] = 0; - size_t limit0 = lrint((m_freq0 * m_blockSize) / rate); + float freq0 = m_freq0; + + // As the stretch ratio increases, so the frequency thresholds + // for phase lamination should increase. Beyond a ratio of + // about 1.5, the threshold should be about 1200Hz; beyond a + // ratio of 2, we probably want no lamination to happen at all + // by default. This calculation aims for that. + + //!!! we should only do this if asked to -- and when not + //setting f0,f1,f2 explicitly + float r = getEffectiveRatio(); + if (r > 1) { + float rf0 = 600 + (600 * ((r-1)*(r-1)*2)); +// std::cerr << "ratio = " << r << ", rf0 = " << rf0 << std::endl; + freq0 = std::max(freq0, rf0); + } + + size_t limit0 = lrint((freq0 * m_blockSize) / rate); size_t limit1 = lrint((m_freq1 * m_blockSize) / rate); size_t limit2 = lrint((m_freq2 * m_blockSize) / rate); + size_t range = 0; if (limit1 < limit0) limit1 = limit0; @@ -700,6 +718,11 @@ RubberBandStretcher::Impl::writeChunk(size_t channel, size_t shiftIncrement, boo cd.resamplebuf = new float[cd.resamplebufSize]; } +#ifdef HAVE_IPP + if (m_threaded) { + m_resamplerMutex.lock(); + } +#endif size_t outframes = cd.resampler->resample(&cd.accumulator, &cd.resamplebuf, @@ -707,6 +730,11 @@ RubberBandStretcher::Impl::writeChunk(size_t channel, size_t shiftIncrement, boo 1.0 / m_pitchScale, last); +#ifdef HAVE_IPP + if (m_threaded) { + m_resamplerMutex.unlock(); + } +#endif writeOutput(*cd.outbuf, cd.resamplebuf, outframes, cd.outCount, theoreticalOut); diff --git a/src/ladspa/RubberBandPitchShifter.cpp b/src/ladspa/RubberBandPitchShifter.cpp index 03117c9..8ac545e 100644 --- a/src/ladspa/RubberBandPitchShifter.cpp +++ b/src/ladspa/RubberBandPitchShifter.cpp @@ -183,12 +183,12 @@ RubberBandPitchShifter::RubberBandPitchShifter(int sampleRate, size_t channels) m_extraLatency(8192), //!!! this should be at least the maximum possible displacement from linear at input rates, divided by the pitch scale factor. It could be very large m_stretcher(new RubberBand::RubberBandStretcher (sampleRate, channels, - RubberBand::RubberBandStretcher::OptionProcessRealTime | - RubberBand::RubberBandStretcher::OptionStretchPrecise | + RubberBand::RubberBandStretcher::OptionProcessRealTime)),// | +// RubberBand::RubberBandStretcher::OptionStretchPrecise | // RubberBand::RubberBandStretcher::OptionTransientsSmooth | - RubberBand::RubberBandStretcher::OptionTransientsCrisp | - RubberBand::RubberBandStretcher::OptionPhasePeakLocked | - RubberBand::RubberBandStretcher::OptionThreadingNone)), +// RubberBand::RubberBandStretcher::OptionTransientsCrisp | +// RubberBand::RubberBandStretcher::OptionPhasePeakLocked | +// RubberBand::RubberBandStretcher::OptionThreadingNone)), m_sampleRate(sampleRate), m_channels(channels) { diff --git a/src/main.cpp b/src/main.cpp index 4429786..5968af4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -376,7 +376,7 @@ int main(int argc, char **argv) float value = obf[c][i]; if (fabsf(value) > outpeak) outpeak = fabsf(value); outsum += value * value; - value *= 0.75; + value *= 0.75;//!!! if (value > 1.f) value = 1.f; if (value < -1.f) value = -1.f; fobf[i * channels + c] = value;