Directsound Study Notes (1): enumeration of sound devices

Source: Internet
Author: User

Directsound Device

 

The directsound device object represents a playback device, which is used to manage devices and create sound buffers.

Multiple applicationsProgramAllows you to create objects for the same sound device. When the input is concentrated on changes between applications, the audio output is automatically transferred from one application to another. Therefore, when the input is concentrated on changes, the application does not have to play and pause their buffers repeatedly.


Sound device Enumeration

 

If your program simply uses the user's preferred device to play the sound, there is no need to enumerate available devices. When you callDirectsoundcreate8When creating a device object, you can specify the default device.

 

Enumerative devices are required in the following scenarios:

1.The performance required by your application is not provided by all devices.

2.Your application requires two or more devices.

3.You want to select a device.

 

Enumerative devices have three purposes:

1.It identifies available hardware devices.

2.It providesGuid.

3.It allows you to create a temporary device object for a device when the device is enumerated, so that you can obtain the performance of the device.

 

To enumerate devices, you must first create a callback function that will be called when enumerating each system device. You can perform any operation in this function, and you can give it any function name, but you mustDsenumcallbackThe prototype declares it. If you want to continue enumeration, the callback function must returnTrueOtherwise, returnFalse-For example, find a device that meets your needs.

 

The following callback function adds each enumerated device name to a check box andGuidAs the option content. The first three parameter values are provided by the device drive. The fourth parameter consistsDirectsoundenumerateFunction input. This parameter can be used to input any32Here is the window handle of the check box. InWindowsx. hThe macro defined in is used to add strings and data to the check box.

 

 

Bool callback dsenumproc (lpguid,
Lpctstr lpszdesc,
Lpctstr lpszdrvname,
Lpvoid lpcontext)
{
Hwnd hcombo = (Hwnd) lpcontext;
Lpguid lptemp = NULL;
 
If (Lpguid ! = Null) // Null only for "primary sound driver ".
{< br> If (lptemp = (lpguid) malloc ( sizeof (guid) == null)
{< br> return (true);
}
memcpy (lptemp, lpguid, sizeof (guid ));
}
 
Combobox_addstring (hcombo, lpszdesc );
Combobox_setitemdata (hcombo,
Combobox_findstring (hcombo, 0 , Lpszdesc ),
Lptemp );
Free (lptemp );
Return (True );
}

enable enumeration when the dialog box containing the check box is initialized. Suppose hcombo is the check box handle, hdlg is the handle of the dialog box.

If(Failed (directsoundenumerate (lpdsenumcallback) dsenumproc,
(Void*)&Hcombo )))
{
Enddialog (hdlg, true );
Return(True );
}

In this example, the address of the check box handle is passed in directsoundenumerate, and then passed in the callback function. This parameter can be any 32-bit value that you want to access in the callback function.
Note: The first device to be enumerated is usually called the main sound device. In this case, the callback function parameter lpguid is null. This device represents the preferred playback device set in the control panel. It is enumerated separately to allow applications to conveniently Add "Main sound devices" to the list, which is used to provide users with device selection. The main device is also enumerated by its unique name and guid.

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.