Skip to content

Commit c396306

Browse files
committed
- Mitigate and compensate for padding and start-delay/latency to
(lib)RubberBand time-stretching and pitch-shifting processing. (short-window option) (EXPERIMENTAL)
1 parent e8cfe0c commit c396306

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/qtractorTimeStretcher.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ qtractorTimeStretcher::qtractorTimeStretcher (
3434
, m_pRubberBandStretcher(nullptr)
3535
, m_iRubberBandChannels(iChannels)
3636
, m_iRubberBandLatency(0)
37+
, m_iRubberBandPadding(0)
3738
, m_iRubberBandFrames(0)
3839
, m_ppRubberBandFrames(nullptr)
3940
, m_ppRubberBandBuffer(nullptr)
40-
, m_bRubberBandStart(false)
4141
, m_bRubberBandFlush(false)
4242
#endif
4343
{
@@ -79,7 +79,8 @@ qtractorTimeStretcher::qtractorTimeStretcher (
7979
if (fPitchShift < 1e-3f)
8080
fPitchShift = 1.0f;
8181
RubberBand::RubberBandStretcher::Options options
82-
= RubberBand::RubberBandStretcher::OptionProcessRealTime;
82+
= RubberBand::RubberBandStretcher::OptionProcessRealTime
83+
| RubberBand::RubberBandStretcher::OptionWindowShort;
8384
if (iFlags & RubberBandFormant)
8485
options |= RubberBand::RubberBandStretcher::OptionFormantPreserved;
8586
#ifdef CONFIG_LIBRUBBERBAND_R3
@@ -94,11 +95,12 @@ qtractorTimeStretcher::qtractorTimeStretcher (
9495
m_ppRubberBandBuffer = new float * [m_iRubberBandChannels];
9596
#ifdef CONFIG_LIBRUBBERBAND_R3
9697
m_iRubberBandLatency = m_pRubberBandStretcher->getStartDelay();
97-
m_iRubberBandFrames = m_pRubberBandStretcher->getPreferredStartPad();
98-
if (m_iRubberBandFrames < m_iRubberBandLatency)
99-
m_iRubberBandFrames = m_iRubberBandLatency;
98+
m_iRubberBandPadding = m_pRubberBandStretcher->getPreferredStartPad();
99+
m_iRubberBandPadding += m_iRubberBandLatency;
100+
m_iRubberBandFrames = qMax(m_iRubberBandLatency, m_iRubberBandPadding);
100101
#else
101102
m_iRubberBandLatency = m_pRubberBandStretcher->getLatency();
103+
m_iRubberBandPadding = m_iRubberBandLatency;
102104
m_iRubberBandFrames = m_iRubberBandLatency;
103105
#endif
104106
if (m_iRubberBandFrames > 0) {
@@ -153,13 +155,11 @@ void qtractorTimeStretcher::process (
153155
}
154156
#ifdef CONFIG_LIBRUBBERBAND
155157
if (m_pRubberBandStretcher) {
156-
if (!m_bRubberBandStart) {
157-
// Process the first dummy empty buffer...
158-
if (m_iRubberBandFrames > 0) {
159-
m_pRubberBandStretcher->process(
160-
m_ppRubberBandFrames, m_iRubberBandFrames, false);
161-
}
162-
m_bRubberBandStart = true;
158+
// Process the first dummy empty buffer...
159+
if (m_iRubberBandPadding > 0) {
160+
m_pRubberBandStretcher->process(
161+
m_ppRubberBandFrames, m_iRubberBandPadding, false);
162+
m_iRubberBandPadding = 0;
163163
}
164164
m_pRubberBandStretcher->process(ppFrames, iFrames, false);
165165
}
@@ -243,11 +243,11 @@ void qtractorTimeStretcher::reset (void)
243243
m_pRubberBandStretcher->reset();
244244
#ifdef CONFIG_LIBRUBBERBAND_R3
245245
m_iRubberBandLatency = m_pRubberBandStretcher->getStartDelay();
246-
m_iRubberBandFrames = m_pRubberBandStretcher->getPreferredStartPad();
247-
if (m_iRubberBandFrames < m_iRubberBandLatency)
248-
m_iRubberBandFrames = m_iRubberBandLatency;
246+
m_iRubberBandPadding = m_pRubberBandStretcher->getPreferredStartPad();
247+
m_iRubberBandFrames = qMax(m_iRubberBandLatency, m_iRubberBandPadding);
249248
#else
250249
m_iRubberBandLatency = m_pRubberBandStretcher->getLatency();
250+
m_iRubberBandPadding = m_iRubberBandLatency;
251251
m_iRubberBandFrames = m_iRubberBandLatency;
252252
#endif
253253
if (m_iRubberBandFrames > 0) {
@@ -261,7 +261,6 @@ void qtractorTimeStretcher::reset (void)
261261
for (unsigned short i = 1; i < m_iRubberBandChannels; ++i)
262262
m_ppRubberBandFrames[i] = m_ppRubberBandFrames[0];
263263
}
264-
m_bRubberBandStart = false;
265264
m_bRubberBandFlush = false;
266265
}
267266
#endif

src/qtractorTimeStretcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ class qtractorTimeStretcher
8686
RubberBand::RubberBandStretcher *m_pRubberBandStretcher;
8787
unsigned short m_iRubberBandChannels;
8888
unsigned int m_iRubberBandLatency;
89+
unsigned int m_iRubberBandPadding;
8990
unsigned int m_iRubberBandFrames;
9091
float **m_ppRubberBandFrames;
9192
float **m_ppRubberBandBuffer;
92-
bool m_bRubberBandStart;
9393
bool m_bRubberBandFlush;
9494
#endif
9595
};

0 commit comments

Comments
 (0)