From fbcb7f717a54d14d3e49d96c1714b53f37a7d34e Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Fri, 20 Nov 2015 18:39:28 +0000 Subject: [PATCH] add device notification for a property change (e.g. if the number of channels is changed) --- mac/sound.cpp | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/mac/sound.cpp b/mac/sound.cpp index a1a7d7af..161eaa46 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -533,15 +533,28 @@ void CSound::Start() // setup callback for xruns (only for input is enough) AudioObjectPropertyAddress stPropertyAddress; - stPropertyAddress.mSelector = kAudioDeviceProcessorOverload; stPropertyAddress.mElement = kAudioObjectPropertyElementMaster; stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal; + stPropertyAddress.mSelector = kAudioDeviceProcessorOverload; + AudioObjectAddPropertyListener ( audioInputDevice[lCurDev], &stPropertyAddress, deviceNotification, this ); + stPropertyAddress.mSelector = kAudioDevicePropertyDeviceHasChanged; + + AudioObjectAddPropertyListener ( audioInputDevice[lCurDev], + &stPropertyAddress, + deviceNotification, + this ); + + AudioObjectAddPropertyListener ( audioOutputDevice[lCurDev], + &stPropertyAddress, + deviceNotification, + this ); + // register the callback function for input and output AudioDeviceCreateIOProcID ( audioInputDevice[lCurDev], callbackIO, @@ -574,10 +587,23 @@ void CSound::Stop() // unregister the callback function for xruns AudioObjectPropertyAddress stPropertyAddress; - stPropertyAddress.mSelector = kAudioDeviceProcessorOverload; stPropertyAddress.mElement = kAudioObjectPropertyElementMaster; stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal; + stPropertyAddress.mSelector = kAudioDevicePropertyDeviceHasChanged; + + AudioObjectRemovePropertyListener( audioOutputDevice[lCurDev], + &stPropertyAddress, + deviceNotification, + this ); + + AudioObjectRemovePropertyListener( audioInputDevice[lCurDev], + &stPropertyAddress, + deviceNotification, + this ); + + stPropertyAddress.mSelector = kAudioDeviceProcessorOverload; + AudioObjectRemovePropertyListener( audioInputDevice[lCurDev], &stPropertyAddress, deviceNotification, @@ -679,13 +705,18 @@ UInt32 CSound::SetBufferSize ( AudioDeviceID& audioDeviceID, OSStatus CSound::deviceNotification ( AudioDeviceID, UInt32, - const AudioObjectPropertyAddress* /* inAddresses */, - void* /* inRefCon */ ) + const AudioObjectPropertyAddress* inAddresses, + void* inRefCon ) { -// TODO: Do we need this anymore? If not, we can completely remove this function... -/* CSound* pSound = static_cast ( inRefCon ); + if ( inAddresses->mSelector == kAudioDevicePropertyDeviceHasChanged ) + { + // if any property of the device has changed, to a full reload + pSound->EmitReinitRequestSignal ( RS_RELOAD_RESTART_AND_INIT ); + } + +/* if ( inAddresses->mSelector == kAudioDeviceProcessorOverload ) { // xrun handling (it is important to act on xruns under CoreAudio