diff --git a/include/Mixer.h b/include/Mixer.h index 757a08d4991..79fbf7db392 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -171,7 +171,10 @@ class EXPORT Mixer : public QObject return m_audioDevStartFailed; } + //! Set new audio device. Old device will be deleted, + //! unless it's stored using storeAudioDevice void setAudioDevice( AudioDevice * _dev , bool startNow ); + //! See overloaded function void setAudioDevice( AudioDevice * _dev, const struct qualitySettings & _qs, bool _needs_fifo, @@ -396,6 +399,7 @@ class EXPORT Mixer : public QObject bool m_isProcessing; // audio device stuff + void doSetAudioDevice( AudioDevice *_dev ); AudioDevice * m_audioDev; AudioDevice * m_oldAudioDev; QString m_audioDevName; diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index c873056419a..ac1aa256455 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -575,21 +575,35 @@ void Mixer::changeQuality( const struct qualitySettings & _qs ) -void Mixer::setAudioDevice( AudioDevice * _dev, - bool startNow ) +void Mixer::doSetAudioDevice( AudioDevice * _dev ) { - stopProcessing(); + // TODO: Use shared_ptr here in the future. + // Currently, this is safe, because this is only called by + // ProjectRenderer, and after ProjectRenderer calls this function, + // it does not access the old device anymore. + if( m_audioDev != m_oldAudioDev ) {delete m_audioDev;} - if( _dev == NULL ) + if( _dev ) { - printf( "param _dev == NULL in Mixer::setAudioDevice(...). " - "Trying any working audio-device\n" ); - m_audioDev = tryAudioDevices(); + m_audioDev = _dev; } else { - m_audioDev = _dev; + printf( "param _dev == NULL in Mixer::setAudioDevice(...). " + "Trying any working audio-device\n" ); + m_audioDev = tryAudioDevices(); } +} + + + + +void Mixer::setAudioDevice( AudioDevice * _dev, + bool startNow ) +{ + stopProcessing(); + + doSetAudioDevice( _dev ); emit sampleRateChanged(); @@ -599,26 +613,16 @@ void Mixer::setAudioDevice( AudioDevice * _dev, -void Mixer::setAudioDevice( AudioDevice * _dev, +void Mixer::setAudioDevice(AudioDevice * _dev, const struct qualitySettings & _qs, bool _needs_fifo, - bool startNow ) + bool startNow) { - // don't delete the audio-device stopProcessing(); m_qualitySettings = _qs; - if( _dev == NULL ) - { - printf( "param _dev == NULL in Mixer::setAudioDevice(...). " - "Trying any working audio-device\n" ); - m_audioDev = tryAudioDevices(); - } - else - { - m_audioDev = _dev; - } + doSetAudioDevice( _dev ); emit qualitySettingsChanged(); emit sampleRateChanged();