* Various tweaks to improve performance at large ratios

This commit is contained in:
Chris Cannam
2007-11-16 22:22:01 +00:00
parent 94f85c2db4
commit 35dc16b611
4 changed files with 39 additions and 9 deletions

View File

@@ -303,7 +303,8 @@ RubberBandStretcher::Impl::calculateSizes()
inputIncrement /= 2; inputIncrement /= 2;
outputIncrement = lrint(ceil(inputIncrement * r)); 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 { } else {
@@ -327,6 +328,7 @@ RubberBandStretcher::Impl::calculateSizes()
inputIncrement = int(outputIncrement / r); inputIncrement = int(outputIncrement / r);
} }
blockSize = std::max(blockSize, roundUp(outputIncrement * 6)); 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 //necessary. clearly something wrong in our calculations... or do
//we just need to ensure client calls setMaxProcessBlockSize? //we just need to ensure client calls setMaxProcessBlockSize?
if (!m_realtime && !m_threaded) { if (!m_realtime && !m_threaded) {
//!!! m_outbufSize = m_outbufSize * 2; m_outbufSize = m_outbufSize * 2;
} }
} }

View File

@@ -481,9 +481,27 @@ RubberBandStretcher::Impl::modifyChunk(size_t channel, size_t outputIncrement,
cd.freqPeak[0] = 0; 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 limit1 = lrint((m_freq1 * m_blockSize) / rate);
size_t limit2 = lrint((m_freq2 * m_blockSize) / rate); size_t limit2 = lrint((m_freq2 * m_blockSize) / rate);
size_t range = 0; size_t range = 0;
if (limit1 < limit0) limit1 = limit0; 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]; cd.resamplebuf = new float[cd.resamplebufSize];
} }
#ifdef HAVE_IPP
if (m_threaded) {
m_resamplerMutex.lock();
}
#endif
size_t outframes = cd.resampler->resample(&cd.accumulator, size_t outframes = cd.resampler->resample(&cd.accumulator,
&cd.resamplebuf, &cd.resamplebuf,
@@ -707,6 +730,11 @@ RubberBandStretcher::Impl::writeChunk(size_t channel, size_t shiftIncrement, boo
1.0 / m_pitchScale, 1.0 / m_pitchScale,
last); last);
#ifdef HAVE_IPP
if (m_threaded) {
m_resamplerMutex.unlock();
}
#endif
writeOutput(*cd.outbuf, cd.resamplebuf, writeOutput(*cd.outbuf, cd.resamplebuf,
outframes, cd.outCount, theoreticalOut); outframes, cd.outCount, theoreticalOut);

View File

@@ -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_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 m_stretcher(new RubberBand::RubberBandStretcher
(sampleRate, channels, (sampleRate, channels,
RubberBand::RubberBandStretcher::OptionProcessRealTime | RubberBand::RubberBandStretcher::OptionProcessRealTime)),// |
RubberBand::RubberBandStretcher::OptionStretchPrecise | // RubberBand::RubberBandStretcher::OptionStretchPrecise |
// RubberBand::RubberBandStretcher::OptionTransientsSmooth | // RubberBand::RubberBandStretcher::OptionTransientsSmooth |
RubberBand::RubberBandStretcher::OptionTransientsCrisp | // RubberBand::RubberBandStretcher::OptionTransientsCrisp |
RubberBand::RubberBandStretcher::OptionPhasePeakLocked | // RubberBand::RubberBandStretcher::OptionPhasePeakLocked |
RubberBand::RubberBandStretcher::OptionThreadingNone)), // RubberBand::RubberBandStretcher::OptionThreadingNone)),
m_sampleRate(sampleRate), m_sampleRate(sampleRate),
m_channels(channels) m_channels(channels)
{ {

View File

@@ -376,7 +376,7 @@ int main(int argc, char **argv)
float value = obf[c][i]; float value = obf[c][i];
if (fabsf(value) > outpeak) outpeak = fabsf(value); if (fabsf(value) > outpeak) outpeak = fabsf(value);
outsum += value * value; outsum += value * value;
value *= 0.75; value *= 0.75;//!!!
if (value > 1.f) value = 1.f; if (value > 1.f) value = 1.f;
if (value < -1.f) value = -1.f; if (value < -1.f) value = -1.f;
fobf[i * channels + c] = value; fobf[i * channels + c] = value;