Skip to content

Commit

Permalink
Add missing const qualifier and add checks on RB retrieve
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Jun 3, 2024
1 parent 406fc3a commit 3937274
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/engine/bufferscalers/rubberbandworkerpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ RubberBandWorkerPool::RubberBandWorkerPool(UserSettingsPointer pConfig)
m_channelPerWorker = multiThreadedOnStereo
? mixxx::audio::ChannelCount::mono()
: mixxx::audio::ChannelCount::stereo();
DEBUG_ASSERT(0 == mixxx::kEngineChannelCount % m_channelPerWorker);
DEBUG_ASSERT(mixxx::kEngineChannelCount % m_channelPerWorker == 0);

setThreadPriority(QThread::HighPriority);
setMaxThreadCount(mixxx::kEngineChannelCount / m_channelPerWorker);
setMaxThreadCount(mixxx::kEngineChannelCount / m_channelPerWorker - 1);

// We allocate one runner less than the total of maximum supported channel,
// so the engine thread will also perform a stretching operation, instead of
Expand All @@ -27,7 +27,3 @@ RubberBandWorkerPool::RubberBandWorkerPool(UserSettingsPointer pConfig)
reserveThread();
}
}

RubberBandWorkerPool::~RubberBandWorkerPool() {
waitForDone();
}
2 changes: 0 additions & 2 deletions src/engine/bufferscalers/rubberbandworkerpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// can be distributed stretching job
class RubberBandWorkerPool : public QThreadPool, public Singleton<RubberBandWorkerPool> {
public:
~RubberBandWorkerPool();

const mixxx::audio::ChannelCount& channelPerWorker() const {
return m_channelPerWorker;
}
Expand Down
18 changes: 11 additions & 7 deletions src/engine/bufferscalers/rubberbandwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ void RubberBandWrapper::setTimeRatio(double ratio) {
}
size_t RubberBandWrapper::getSamplesRequired() const {
size_t require = 0;
for (auto& stretcher : m_pInstances) {
for (const auto& stretcher : m_pInstances) {
require = qMax(require, stretcher->getSamplesRequired());
}
return require;
}
int RubberBandWrapper::available() const {
int available = std::numeric_limits<int>::max();
for (auto& stretcher : m_pInstances) {
for (const auto& stretcher : m_pInstances) {
available = qMin(available, stretcher->available());
}
return available == std::numeric_limits<int>::max() ? 0 : available;
Expand All @@ -49,14 +49,17 @@ size_t RubberBandWrapper::retrieve(float* const* output, size_t samples) const {
if (m_pInstances.size() == 1) {
return m_pInstances[0]->retrieve(output, samples);
} else {
size_t ret = 0;
// 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) {
size_t thisRet = stretcher->retrieve(output, samples);
DEBUG_ASSERT(!ret || thisRet == ret);
ret = qMax(thisRet, ret);
size_t numSamplesRequested = stretcher->retrieve(output, samples);

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

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

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

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

View workflow job for this annotation

GitHub Actions / macOS 11 x64

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

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

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

unused variable 'numSamplesRequested' [-Werror,-Wunused-variable]
;
// there is something very wrong if we got a different of amount
// of samples than we requested
DEBUG_ASSERT(numSamplesRequested == samples);
output += getChannelPerWorker();
}
return ret;
return samples;
}
}
size_t RubberBandWrapper::getInputIncrement() const {
Expand Down Expand Up @@ -151,6 +154,7 @@ void RubberBandWrapper::setup(mixxx::audio::SampleRate sampleRate,
return;
}

m_pInstances.reserve(chCount / channelPerWorker);
for (int c = 0; c < chCount; c += channelPerWorker) {
m_pInstances.emplace_back(
std::make_unique<RubberBandTask>(
Expand Down

0 comments on commit 3937274

Please sign in to comment.