From 408b72c798cddb6d837cd09d83f3369f9f3b98f1 Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Fri, 13 Jul 2018 10:40:24 +0900 Subject: [PATCH] Use tryLock in audio threads for VST/ZynAddSubFX (#4460) Prevent loading VST or toggling ZynAddSubFX GUI from blocking entire audio processing --- plugins/VstEffect/VstEffect.cpp | 8 +++++--- plugins/vestige/vestige.cpp | 4 +--- plugins/zynaddsubfx/ZynAddSubFx.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/VstEffect/VstEffect.cpp b/plugins/VstEffect/VstEffect.cpp index ea0241a5a..05cc7a070 100644 --- a/plugins/VstEffect/VstEffect.cpp +++ b/plugins/VstEffect/VstEffect.cpp @@ -95,9 +95,11 @@ bool VstEffect::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames ) sampleFrame * buf = new sampleFrame[_frames]; #endif memcpy( buf, _buf, sizeof( sampleFrame ) * _frames ); - m_pluginMutex.lock(); - m_plugin->process( buf, buf ); - m_pluginMutex.unlock(); + if (m_pluginMutex.tryLock()) + { + m_plugin->process( buf, buf ); + m_pluginMutex.unlock(); + } double out_sum = 0.0; const float w = wetLevel(); diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index 9ea053e8e..540c8b5ce 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -359,14 +359,12 @@ void vestigeInstrument::loadFile( const QString & _file ) void vestigeInstrument::play( sampleFrame * _buf ) { - m_pluginMutex.lock(); + if (!m_pluginMutex.tryLock()) {return;} const fpp_t frames = Engine::mixer()->framesPerPeriod(); if( m_plugin == NULL ) { - BufferManager::clear( _buf, frames ); - m_pluginMutex.unlock(); return; } diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 8bba1f10f..8c1da751f 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -326,7 +326,7 @@ QString ZynAddSubFxInstrument::nodeName() const void ZynAddSubFxInstrument::play( sampleFrame * _buf ) { - m_pluginMutex.lock(); + if (!m_pluginMutex.tryLock()) {return;} if( m_remotePlugin ) { m_remotePlugin->process( NULL, _buf );