XAudio2 Learning III acquisition of audio output device information __xaudio2

Source: Internet
Author: User
XAudio2 Learning three get output device informationThe output device information includes the audio format supported by the output device, the device ID, the device name, and the role. Audio format: Number of channels, sample rate, valid bit, audio type, and so on. Device ID: Unique identification for each device, playing a role: used to indicate the purpose of the audio device, as detailed below. Device name: Refers to the full name of the audio output device. Open your own audio synthesizer and click the Drop-down button in the device to see all the devices and the full name. The following figure:

To get information about the output device, first we need to know the number of output devices, because the access information is indexed by integer index.
HRESULT getdevicedetails (
         UINT32 Index,
         xaudio2_device_details *pdevicedetails
Index represents the first few devices. The pdevicedetails contains the equipment information we need.

Pdevicedetails is a xaudio2_device_details type of struct pointer.
typedef struct XAUDIO2_DEVICE_DETAILS {
    WCHAR deviceid[256];
    WCHAR displayname[256];
    Xaudio2_device_role role;
    Waveformatextensible OutputFormat;
} Xaudio2_device_details;
The structure body contains the device ID, name, role, and extended output format. For extended output formats:
typedef struct {
    waveformatex format;//output format
    Union {
        WORD wvalidbitspersample;
        WORD Wsamplesperblock;
        WORD wreserved;
    } samples;//valid digits
    DWORD dwchannelmask;//channel corresponding
    GUID subformat;//identity
} waveformatextensible, * Pwaveformatextensible, *lppwaveformatextensible;

Where the channel corresponds to the left channel, right channel and so on:

A subtype of data, a unique identifier, such as KSDATAFORMAT_SUBTYPE_PCM.
typedef struct TWAVEFORMATEX {
    word wformattag;//type
    word nchannels;//channel number
    DWORD nsamplespersec;//sampling rate
    DWORD navgbytespersec;//bytes
    per second Word nblockalign;//byte block
    word wbitspersample;//bit width
    word cbsize;//structure body size
} waveformatex, *pwaveformatex, * Lpwaveformatex;
The type refers to the logo that Microsoft registers for many compression algorithms.
Device role:
typedef enum Xaudio2_device_role
    Notdefaultdevice = 0x0,//device is not used for program default output device
    Defaultconsoledevice = 0x1,// Device for console audio program
    Defaultmultimediadevice = 0x2,//device for multimedia playback
    Defaultcommunicationsdevice = 0x4,//device for voice communication program
    Defaultgamedevice = 0x8,//device for game audio
    Globaldefaultdevice = 0xf,//All cases described above
    invaliddevicerole = ~ globaldefaultdevice//not valid
} xaudio2_device_role;

Get the number of output devices as in the previous article, add the method of acquiring device information: Get the result as follows: First device:
Second device:

Full program:
#include "XAudio2.h"
#include <stdio.h>
#include <iostream>

using namespace std;

int main (int argc, char *argv[])
	HRESULT hr =  CoInitialize (0);//Initialize COM component
	if (FAILED (HR))
		return -1;

	IXAudio2 *pengine = NULL;
	hr = Xaudio2create (&pengine);//Create a IXAudio2 object
	if (FAILED (HR))

	UINT uplayer = 0;
	hr = Pengine->getdevicecount (&uplayer);//Get audio output device number
	if (FAILED (HR))

	cout << uplayer << Endl;

	Xaudio2_device_details deviceinfo;
	for (int i = 0; i < Uplayer i++)
		pengine->getdevicedetails (i, &deviceinfo);//Get device information

	Pengine->release ()//releasing Resource
	couninitialize ()//releasing resource return


Note: Please respect the copyright, reprint please contact author qq:1245178753. This article link: http://blog.csdn.net/u011417605/article/details/50561691 source code Download: http://download.csdn.net/detail/u011417605/9451860

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.