问题描述
我想在设备属性->高级-> DefaultFormat部分中枚举Capture设备上所有受支持的格式.
I would like to enumerate all supported formats on Capture device in device Properties -> Advanced -> DefaultFormat section.
我想使用Windows Core Audio Api来做到这一点,但是我真的找不到适合的界面来读取这些格式.
I would like to use Windows Core Audio Api to do so, however I can't really find suitable interface that I could use to read those formats.
https://msdn.microsoft.com/zh-CN/library/windows/desktop/dd370858(v=vs.85).aspx#
您知道哪个界面可以为我提供这种功能吗?
Any idea which interface would provide me with such functionality?
推荐答案
有 IMMDeviceEnumerator 接口,它可以帮助您获取指向 IMMDevice (IMMDevice
接口代表音频终结点设备:呈现或捕获):
There is the IMMDeviceEnumerator interface which can help you to obtain pointer to the IMMDevice you need (IMMDevice
interface represents an audio endpoint device: render or capture):
- 您可以使用 IMMDeviceEnumerator: :EnumAudioEndpoints 方法获取系统中所有活动的捕获设备,或
- 您可以调用 IMMDeviceEnumerator: :GetDefaultAudioEndpoint 获取指向默认捕获设备的指针.
- you can use IMMDeviceEnumerator::EnumAudioEndpoints method to get all active capture devices in the system, or
- you can call IMMDeviceEnumerator::GetDefaultAudioEndpoint to obtain pointer to the default capture device.
无论如何,当您拥有要查找支持的格式的IMMDevice的指针时,可以获取 IMMDevice :: Activate 方法. IAudioClient
界面允许您检查设备是否支持音频格式(方法 IAudioClient :: IsFormatSupported ,音频格式由 WAVEFORMATEX 结构).不幸的是,目前Core Audio API中没有方法可以返回设备支持的格式列表,因此您将需要枚举WAVEFORMATEX成员结构的可能值,并检查设备是否支持自己的每种格式.
Anyway, when you have the pointer to the IMMDevice you need to look up supported formats for, you can get the pointer to the IAudioClient interface using IMMDevice::Activate method. IAudioClient
interface allows you to check if the device supports an audio format or not (method IAudioClient::IsFormatSupported, audio format is described by WAVEFORMATEX structure). Unfortunately, right now there is no method in Core Audio API which returns a list of supported formats by the device, so you will need to enumerate possible values of WAVEFORMATEX members structure and check if every format supported by device by yourself.
但是您可以使用IMMDevice属性存储来获取用户在DefaultFormat部分中选择的格式( IMMDevice :: OpenPropertyStore ),然后检查PKEY_AudioEngine_DeviceFormat
键(此处为描述: MSDN:PKEY_AudioEngine_DeviceFormat ).
But you can get the format that user did select in the DefaultFormat section by using IMMDevice property store (IMMDevice::OpenPropertyStore) and then checking for the PKEY_AudioEngine_DeviceFormat
key (here is the description: MSDN: PKEY_AudioEngine_DeviceFormat).
阅读以下内容会很有帮助
It would be useful to read:
- MSDN: Device Formats
- MSDN: Device Properties
- MSDN: Audio Endpoint Properties
这篇关于Windows Core Audio Api在捕获设备上获取所有受支持的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!