Skip to content
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

Fix RubberBand segafult when changing audio setting #13649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a duplicate (see line 114)

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
Loading