Use devicescollection to enumerate multiple sound card devices (playback devices/audio output devices) on a computer ),
Using their guid to create a device for playing a sound, you can hear the sound on two sound cards through traversal. Below is a brief C # code:
Microsoft. DirectX. directsound. devicescollection sound_devices = new Microsoft. DirectX. directsound. devicescollection ();
Foreach (Object sound in sound_devices)
{
Microsoft. DirectX. directsound. deviceinformation deviceinfo = (Microsoft. DirectX. directsound. deviceinformation) sound;
If (string. isnullorempty (deviceinfo. modulename) continue;
MessageBox. Show (deviceinfo. tostring ());
Microsoft. DirectX. directsound. device sound_device_output = new Microsoft. DirectX. directsound. Device (deviceinfo. driverguid );
Sound_device_output.setcooperativelevel (this, Microsoft. DirectX. directsound. cooperativelevel. Normal); // sets the device collaboration level
Microsoft. DirectX. directsound. bufferdescription buffdes = new Microsoft. DirectX. directsound. bufferdescription ();
Buffdes. globalfocus = true; // sets the global focus of the buffer.
Buffdes. controlvolume = true; // specifies that the buffer can control the sound.
Buffdes. controlpan = true; // specifies that the buffer can control sound channel balancing.
Microsoft. DirectX. directsound. secondarybuffer secondary_buffer = new Microsoft. DirectX. directsound. secondarybuffer (textbox1.text, buffdes, sound_device_output); // create a secondary buffer
Secondary_buffer.play (0, Microsoft. DirectX. directsound. bufferplayflags. looping); // set the buffer to loop playback.
}
The problem is that if the sound is synchronized to play on two devices, such as a RealTek integrated sound card and a USB audio device