Automatic Selection of Output device

Started by Ravindra, May 30, 2023, 05:40:38 PM

Previous topic - Next topic

Ravindra

Hi Severino,

I use InitSoundSystem method to detect output device in my application.

It so happens that my application is running and i connect external sound source other than built in
speakers then my audio sound output goes. I have to restart the application and get back the sound again.

Sometimes we may have multiple playback devices like Bluetooth speaker, audio interface etc. connected then can we detect automatically which of them is currently active and giving audio output so that my application set the output device to active playback device.

It happens may times in musical programs where Laptop is connected to external Mixer/Amplifier system.
If software is already open and external sound system is connected the audio output stops.
After restarting application it comes back.

Thanks and Regards,

Ravindra.





Administrator

Hello,

many device drivers have this behaviour: when the new device added is connected, its driver will set itself as the system default one, causing the current device to stop playing (not in every system but it happens in many).

Unfortunately this happens at low level and, when using the default DirectSound protocol, if something affecting the order of listed output devices should happen, like a new insertion or a change of the system default device, the engine will not be able to recover the situation automatically so a reset of the engine (through the combination of our ResetEngine and ResetControl methods) will be required in order to have an updated list.

Due to the fact that our component is compatible with CoreAudio APIs introduced with Windows Vista, you can be notified when something affecting the list happens by catching the CoreAudioDeviceStateChange event: after catching this event, you may eventually reset the engine and the component by calling the ResetEngine and ResetControl methods.

A solution to avoid having to deal with ResetEngine/ResetControl combination would be adopting the Wasapi protocol in place of DirectSound: this protocol allows the engine to manage connections/disconnections with more flexibility so, after connecting/disconnecting a device, you could get an updated list of devices, allowing to avoid the need to shut-down and restart the engine.
Please, check the tutorial "How to manage audio flow through WASAPI" inside the documentation and the few Wasapi-related sample projects installed inside the system.

Hope this helps

Kind regards

Severino Delaurenti