diff --git a/linux/sound.cpp b/linux/sound.cpp index 3db291f7a9..7ea475a91a 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -240,6 +240,9 @@ int CSound::process ( jack_nframes_t nframes, void* arg ) CSound* pSound = static_cast ( arg ); int i; + // make sure we are locked during execution + QMutexLocker locker(&pSound->MutexAudioProcessCb); + if ( pSound->IsRunning() && ( nframes == static_cast ( pSound->iJACKBufferSizeMono ) ) ) { // get input data pointer diff --git a/src/soundbase.cpp b/src/soundbase.cpp index 5807479c37..18b2870f5d 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -75,15 +75,15 @@ void CSoundBase::Stop() // set flag so that thread can leave the main loop bRun = false; - // give thread some time to terminate - if ( !bIsCallbackAudioInterface ) - { - wait ( 5000 ); - } + // drain the audio process callback + QMutexLocker locker(&MutexAudioProcessCb); } void CSoundBase::run() { + // make sure we are locked during execution + QMutexLocker locker(&MutexAudioProcessCb); + // main loop of working thread while ( bRun ) { diff --git a/src/soundbase.h b/src/soundbase.h index ab588a4678..562482a238 100755 --- a/src/soundbase.h +++ b/src/soundbase.h @@ -26,6 +26,7 @@ #include #include +#include #ifndef HEADLESS # include #endif @@ -137,6 +138,7 @@ class CSoundBase : public QThread void run(); bool bRun; + QMutex MutexAudioProcessCb; void ParseMIDIMessage ( const CVector& vMIDIPaketBytes );