Simply use Microsoft. DirectX. directsound to play a wave audio file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.