-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rubberband V3 stretcher #4853
Merged
Merged
Rubberband V3 stretcher #4853
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,13 @@ using RubberBand::RubberBandStretcher; | |
|
||
namespace { | ||
|
||
// TODO (XXX): this should be removed. It is only needed to work around | ||
// a Rubberband 1.3 bug. | ||
// This is the default increment from RubberBand 1.8.1. | ||
size_t kRubberBandBlockSize = 256; | ||
|
||
#define RUBBERBANDV3 (RUBBERBAND_API_MAJOR_VERSION >= 2 && RUBBERBAND_API_MINOR_VERSION >= 7) | ||
|
||
} // namespace | ||
|
||
EngineBufferScaleRubberBand::EngineBufferScaleRubberBand( | ||
|
@@ -53,14 +57,16 @@ void EngineBufferScaleRubberBand::setScaleParameters(double base_rate, | |
// | ||
// References: | ||
// https://bugs.launchpad.net/ubuntu/+bug/1263233 | ||
// https://bitbucket.org/breakfastquay/rubberband/issue/4/sigfpe-zero-division-with-high-time-ratios | ||
constexpr double kMinSeekSpeed = 1.0 / 128.0; | ||
// https://todo.sr.ht/~breakfastquay/rubberband/5 | ||
Swiftb0y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
double speed_abs = fabs(*pTempoRatio); | ||
if (speed_abs < kMinSeekSpeed) { | ||
// Let the caller know we ignored their speed. | ||
speed_abs = *pTempoRatio = 0; | ||
if (runningEngineVersion() == 2) { | ||
constexpr double kMinSeekSpeed = 1.0 / 128.0; | ||
if (speed_abs < kMinSeekSpeed) { | ||
// Let the caller know we ignored their speed. | ||
speed_abs = *pTempoRatio = 0; | ||
} | ||
} | ||
|
||
// RubberBand handles checking for whether the change in pitchScale is a | ||
// no-op. | ||
double pitchScale = fabs(base_rate * *pPitchRatio); | ||
|
@@ -80,21 +86,22 @@ void EngineBufferScaleRubberBand::setScaleParameters(double base_rate, | |
m_pRubberBand->setTimeRatio(1.0 / timeRatioInverse); | ||
} | ||
|
||
if (m_pRubberBand->getInputIncrement() == 0) { | ||
qWarning() << "EngineBufferScaleRubberBand inputIncrement is 0." | ||
<< "On RubberBand <=1.8.1 a SIGFPE is imminent despite" | ||
<< "our workaround. Taking evasive action." | ||
<< "Please report this message to [email protected]."; | ||
|
||
// This is much slower than the minimum seek speed workaround above. | ||
while (m_pRubberBand->getInputIncrement() == 0) { | ||
timeRatioInverse += 0.001; | ||
m_pRubberBand->setTimeRatio(1.0 / timeRatioInverse); | ||
if (runningEngineVersion() == 2) { | ||
if (m_pRubberBand->getInputIncrement() == 0) { | ||
qWarning() << "EngineBufferScaleRubberBand inputIncrement is 0." | ||
<< "On RubberBand <=1.8.1 a SIGFPE is imminent despite" | ||
<< "our workaround. Taking evasive action." | ||
<< "Please file an issue on https://github.com/mixxxdj/mixxx/issues"; | ||
|
||
// This is much slower than the minimum seek speed workaround above. | ||
while (m_pRubberBand->getInputIncrement() == 0) { | ||
timeRatioInverse += 0.001; | ||
m_pRubberBand->setTimeRatio(1.0 / timeRatioInverse); | ||
} | ||
speed_abs = timeRatioInverse / base_rate; | ||
*pTempoRatio = m_bBackwards ? -speed_abs : speed_abs; | ||
} | ||
speed_abs = timeRatioInverse / base_rate; | ||
*pTempoRatio = m_bBackwards ? -speed_abs : speed_abs; | ||
} | ||
|
||
// Used by other methods so we need to keep them up to date. | ||
m_dBaseRate = base_rate; | ||
m_dTempoRatio = speed_abs; | ||
|
@@ -109,10 +116,18 @@ void EngineBufferScaleRubberBand::onSampleRateChanged() { | |
m_pRubberBand.reset(); | ||
return; | ||
} | ||
RubberBandStretcher::Options rubberbandOptions = RubberBandStretcher::OptionProcessRealTime; | ||
#if RUBBERBANDV3 | ||
// TODO make this a runtime option | ||
rubberbandOptions |= RubberBandStretcher::OptionEngineFiner; | ||
#endif | ||
|
||
m_pRubberBand = std::make_unique<RubberBandStretcher>( | ||
getOutputSignal().getSampleRate(), | ||
getOutputSignal().getChannelCount(), | ||
RubberBandStretcher::OptionProcessRealTime); | ||
rubberbandOptions); | ||
// TODO (XXX): we should always be able to provide rubberband as | ||
// many samples as it wants. So remove this. | ||
m_pRubberBand->setMaxProcessSize(kRubberBandBlockSize); | ||
// Setting the time ratio to a very high value will cause RubberBand | ||
// to preallocate buffers large enough to (almost certainly) | ||
|
@@ -190,6 +205,9 @@ double EngineBufferScaleRubberBand::scaleBuffer( | |
|
||
size_t iLenFramesRequired = m_pRubberBand->getSamplesRequired(); | ||
if (iLenFramesRequired == 0) { | ||
// TODO (XXX): Rubberband 1.3 is not being packaged anymore. | ||
// Remove this workaround. | ||
// | ||
// rubberband 1.3 (packaged up through Ubuntu Quantal) has a bug | ||
// where it can report 0 samples needed forever which leads us to an | ||
// infinite loop. To work around this, we check if available() is | ||
|
@@ -245,3 +263,11 @@ double EngineBufferScaleRubberBand::scaleBuffer( | |
|
||
return framesRead; | ||
} | ||
|
||
int EngineBufferScaleRubberBand::runningEngineVersion() { | ||
#if RUBBERBANDV3 | ||
return m_pRubberBand->getEngineVersion(); | ||
#else | ||
return 2; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we ifdef it based on the rubberband version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was only able to verify that this is not present the newer rubberband version. So I didn't want to introduce regressions based on speculation.