Skip to content

Commit

Permalink
Fix Rubberband v2 compatibility in padding
Browse files Browse the repository at this point in the history
  • Loading branch information
robbert-vdh committed Dec 7, 2022
1 parent e1db59a commit d8c8ca9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/engine/bufferscalers/enginebufferscalerubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,13 @@ void EngineBufferScaleRubberBand::reset() {
// need to run some silent samples through the time stretching engine first
// before using it. Otherwise it will eat add a short fade-in, destroying
// the initial transient.
#ifdef RUBBERBANDV3
size_t remaining_padding = m_pRubberBand->getPreferredStartPad();
#else
// This _should_ be equal to the latency in older Rubber Band versions:
// https://github.com/breakfastquay/rubberband/blob/c5f99d5ff2cba2f4f1def6c38c7843bbb9ac7a78/main/main.cpp#L652
size_t remaining_padding = m_pRubberBand->getLatency();
#endif
std::fill_n(m_buffers[0].begin(), kRubberBandBlockSize, 0.0f);
std::fill_n(m_buffers[1].begin(), kRubberBandBlockSize, 0.0f);
while (remaining_padding > 0) {
Expand All @@ -300,7 +306,11 @@ void EngineBufferScaleRubberBand::reset() {
remaining_padding -= pad_samples;
}

#ifdef RUBBERBANDV3
size_t padding_to_drop = m_pRubberBand->getStartDelay();
#else
size_t padding_to_drop = m_pRubberBand->getLatency();
#endif
while (padding_to_drop > 0) {
const size_t drop_samples = std::min<size_t>(padding_to_drop, kRubberBandBlockSize);
m_pRubberBand->retrieve(m_bufferPtrs.data(), drop_samples);
Expand Down

0 comments on commit d8c8ca9

Please sign in to comment.