Skip to content

Commit

Permalink
Merge pull request #13649 from acolombier/fix/segfault-with-mt-rubber…
Browse files Browse the repository at this point in the history
…band

Fix RubberBand segafult when changing audio setting
  • Loading branch information
JoergAtGithub authored Oct 1, 2024
2 parents e779238 + 0823ccb commit 60bdaca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/engine/bufferscalers/enginebufferscalerubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void EngineBufferScaleRubberBand::onSignalChanged() {
// TODO: Resetting the sample rate will cause internal
// memory allocations that may block the real-time thread.
// When is this function actually invoked??
m_rubberBand.clear();
if (!getOutputSignal().isValid()) {
return;
}
Expand Down
8 changes: 8 additions & 0 deletions src/preferences/dialog/dlgprefsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ void DlgPrefSound::slotApply() {
ScopedWaitCursor cursor;
const auto keylockEngine =
keylockComboBox->currentData().value<EngineBuffer::KeylockEngine>();

// Temporary set an empty config to force the audio thread to stop and
// stay off while we are swapping the keylock settings. This is
// necessary because the audio thread doesn't have any synchronisation
// mechanism due to its realtime nature and editing the RubberBand
// config while it is running leads to race conditions.
m_pSoundManager->closeActiveConfig();

m_pKeylockEngine.set(static_cast<double>(keylockEngine));
m_pSettings->set(kKeylockEngingeCfgkey,
ConfigValue(static_cast<int>(keylockEngine)));
Expand Down
18 changes: 8 additions & 10 deletions src/soundio/soundmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,22 +553,20 @@ SoundManagerConfig SoundManager::getConfig() const {
return m_config;
}

SoundDeviceStatus SoundManager::setConfig(const SoundManagerConfig& config) {
SoundDeviceStatus status = SoundDeviceStatus::Ok;
m_config = config;
checkConfig();

void SoundManager::closeActiveConfig() {
// Close open devices. After this call we will not get any more
// onDeviceOutputCallback() or pushBuffer() calls because all the
// SoundDevices are closed. closeDevices() blocks and can take a while.
const bool sleepAfterClosing = true;
closeDevices(sleepAfterClosing);
}

SoundDeviceStatus SoundManager::setConfig(const SoundManagerConfig& config) {
SoundDeviceStatus status = SoundDeviceStatus::Ok;
m_config = config;
checkConfig();

// certain parts of mixxx rely on this being here, for the time being, just
// letting those be -- bkgood
// Do this first so vinyl control gets the right samplerate -- Owen W.
m_pConfig->set(ConfigKey("[Soundcard]", "Samplerate"),
ConfigValue(static_cast<int>(m_config.getSampleRate().value())));
closeActiveConfig();

status = setupDevices();
if (status == SoundDeviceStatus::Ok) {
Expand Down
1 change: 1 addition & 0 deletions src/soundio/soundmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SoundManager : public QObject {
QList<QString> getHostAPIList() const;
SoundManagerConfig getConfig() const;
SoundDeviceStatus setConfig(const SoundManagerConfig& config);
void closeActiveConfig();
void checkConfig();

void onDeviceOutputCallback(const SINT iFramesPerBuffer);
Expand Down

0 comments on commit 60bdaca

Please sign in to comment.