Skip to content

Commit

Permalink
Add better comments and various nits
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Jun 4, 2024
1 parent 5996927 commit b8a874e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/engine/bufferscalers/enginebufferscalerubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ SINT EngineBufferScaleRubberBand::retrieveAndDeinterleave(
// immediately read those frames in addition to the frames we actually
// need for the output
const SINT frames_to_read = math_min(frames_available, frames + m_remainingPaddingInOutput);

Check failure on line 143 in src/engine/bufferscalers/enginebufferscalerubberband.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

unused variable ‘frames_to_read’ [-Werror=unused-variable]

Check failure on line 143 in src/engine/bufferscalers/enginebufferscalerubberband.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

unused variable 'frames_to_read' [-Werror,-Wunused-variable]

Check failure on line 143 in src/engine/bufferscalers/enginebufferscalerubberband.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

unused variable 'frames_to_read' [-Werror,-Wunused-variable]
DEBUG_ASSERT(frames_to_read <= MAX_BUFFER_LEN);
DEBUG_ASSERT(frames_to_read <= m_buffers[0].size());
SINT received_frames;
{
ScopedTimer t(QStringLiteral("RubberBand::retrieve"));
received_frames = static_cast<SINT>(m_rubberBand.retrieve(
m_bufferPtrs.data(), frames_to_read));
m_bufferPtrs.data(), frames + m_remainingPaddingInOutput, m_buffers[0].size()));
}
SINT frame_offset = 0;

Expand Down
45 changes: 33 additions & 12 deletions src/engine/bufferscalers/rubberbandwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "engine/bufferscalers/rubberbandworkerpool.h"
#include "engine/engine.h"
#include "util/assert.h"
#include "util/sample.h"

using RubberBand::RubberBandStretcher;

Expand Down Expand Up @@ -45,40 +46,51 @@ int RubberBandWrapper::available() const {
}
return available == std::numeric_limits<int>::max() ? 0 : available;
}
size_t RubberBandWrapper::retrieve(float* const* output, size_t samples) const {
size_t RubberBandWrapper::retrieve(
float* const* output, size_t samples, SINT channelBufferSize) const {
// ensure we don't fetch more samples than we really have available.
samples = std::min(static_cast<size_t>(available()), samples);
VERIFY_OR_DEBUG_ASSERT(samples <= channelBufferSize) {

Check failure on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / clazy

comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'SINT' (aka 'long') [-Werror,-Wsign-compare]

Check failure on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘SINT’ {aka ‘long int’} [-Werror=sign-compare]

Check failure on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'SINT' (aka 'long') [-Werror,-Wsign-compare]

Check warning on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / coverage

comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘SINT’ {aka ‘long int’} [-Wsign-compare]

Check failure on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'SINT' (aka 'long') [-Werror,-Wsign-compare]

Check failure on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

the following warning is treated as an error

Check warning on line 53 in src/engine/bufferscalers/rubberbandwrapper.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'<=': signed/unsigned mismatch
return 0;
}
if (m_pInstances.size() == 1) {
return m_pInstances[0]->retrieve(output, samples);
} else {
// ensure we don't fetch more samples than we really have available.
samples = std::min(static_cast<size_t>(available()), samples);
for (const auto& stretcher : m_pInstances) {
#ifdef MIXXX_DEBUG_ASSERTIONS_ENABLED
size_t numSamplesRequested =
#endif
size_t numSamplesRetrieved =
stretcher->retrieve(output, samples);
// there is something very wrong if we got a different of amount
// of samples than we requested
DEBUG_ASSERT(numSamplesRequested == samples);
// We clear the buffer to limit the damage, but the signal
// interruption will still create undesirable audio artefacts.
VERIFY_OR_DEBUG_ASSERT(numSamplesRetrieved == samples) {
if (samples > numSamplesRetrieved) {
for (int ch = 0; ch < getChannelPerWorker(); ch++) {
SampleUtil::clear(output[ch] + numSamplesRetrieved,
samples - numSamplesRetrieved);
}
}
}
output += getChannelPerWorker();
}
return samples;
}
}
size_t RubberBandWrapper::getInputIncrement() const {
VERIFY_OR_DEBUG_ASSERT(isValid()) {
return -1;
return {};
}
return m_pInstances[0]->getInputIncrement();
}
size_t RubberBandWrapper::getLatency() const {
VERIFY_OR_DEBUG_ASSERT(isValid()) {
return -1;
return {};
}
return m_pInstances[0]->getLatency();
}
double RubberBandWrapper::getPitchScale() const {
VERIFY_OR_DEBUG_ASSERT(isValid()) {
return -1;
return {};
}
return m_pInstances[0]->getPitchScale();
}
Expand All @@ -87,7 +99,7 @@ double RubberBandWrapper::getPitchScale() const {
// for how these two functions were implemented within librubberband itself
size_t RubberBandWrapper::getPreferredStartPad() const {
VERIFY_OR_DEBUG_ASSERT(isValid()) {
return -1;
return {};
}
#if RUBBERBANDV3
return m_pInstances[0]->getPreferredStartPad();
Expand All @@ -101,7 +113,7 @@ size_t RubberBandWrapper::getPreferredStartPad() const {
}
size_t RubberBandWrapper::getStartDelay() const {
VERIFY_OR_DEBUG_ASSERT(isValid()) {
return -1;
return {};
}
#if RUBBERBANDV3
return m_pInstances[0]->getStartDelay();
Expand All @@ -121,11 +133,16 @@ void RubberBandWrapper::process(const float* const* input, size_t samples, bool
RubberBandWorkerPool* pPool = RubberBandWorkerPool::instance();
for (auto& pInstance : m_pInstances) {
pInstance->set(input, samples, isFinal);
// We try to get the stretching job ran by the RBPool if there is a
// worker slot available
if (!pPool->tryStart(pInstance.get())) {
// Otherwise, it means the main thread should take care of the stretching
pInstance->run();
}
input += pPool->channelPerWorker();
}
// We always perform a wait, even for task that were ran in the main
// thread, so it resets the semaphore
for (auto& pInstance : m_pInstances) {
pInstance->waitReady();
}
Expand All @@ -150,6 +167,10 @@ void RubberBandWrapper::setup(mixxx::audio::SampleRate sampleRate,
auto channelPerWorker = getChannelPerWorker();
qDebug() << "RubberBandWrapper::setup" << channelPerWorker;
VERIFY_OR_DEBUG_ASSERT(0 == chCount % channelPerWorker) {
// If we have an uneven number of channel, which we can't evenly
// distribute across the RubberBandPool workers, we fallback to using a
// single instance to limit the audio impefection that may come from
// using RB withg different parameters.
m_pInstances.emplace_back(
std::make_unique<RubberBandTask>(
sampleRate, chCount, opt));
Expand Down
2 changes: 1 addition & 1 deletion src/engine/bufferscalers/rubberbandwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RubberBandWrapper {
void setTimeRatio(double ratio);
std::size_t getSamplesRequired() const;
int available() const;
size_t retrieve(float* const* output, size_t samples) const;
size_t retrieve(float* const* output, size_t samples, SINT channelBufferSize) const;
size_t getInputIncrement() const;
size_t getLatency() const;
double getPitchScale() const;
Expand Down
25 changes: 17 additions & 8 deletions src/preferences/dialog/dlgprefsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ bool soundItemAlreadyExists(const AudioPath& output, const QWidget& widget) {
}

#ifdef __RUBBERBAND__
const QString kKeylockMultiThreadedAvailable = QObject::tr(
"<p><span style=\"font-weight:600;\">Warning!</span></p><p>Using multi "
"threading may result in pitch and tone imperfection, and this is "
"mono-incompatible, due to third party limitations.</p>");
const QString kKeylockMultiThreadedUnavailableMono = QObject::tr(
"<i>Multi threading mode is incompatible with mono main mix.</i>");
const QString kKeylockMultiThreadedUnavailableRubberband = QObject::tr(
"<i>Multi threading mode is only available with RubberBand.</i>");
const QString kKeylockMultiThreadedAvailable =
QStringLiteral("<p><span style=\"font-weight:600;\">") +
QObject::tr("Warning!") + QStringLiteral("</span></p><p>") +
QObject::tr(
"Using multi "
"threading may result in pitch and tone imperfection, and this "
"is "
"mono-incompatible, due to third party limitations.") +
QStringLiteral("</p>");
const QString kKeylockMultiThreadedUnavailableMono = QStringLiteral("<i>") +
QObject::tr(
"Multi threading mode is incompatible with mono main mix.") +
QStringLiteral("</i>");
const QString kKeylockMultiThreadedUnavailableRubberband =
QStringLiteral("<i>") +
QObject::tr("Multi threading mode is only available with RubberBand.") +
QStringLiteral("</i>");
#endif
} // namespace

Expand Down

0 comments on commit b8a874e

Please sign in to comment.