WASAPI:选择专用输出波形格式 [英] WASAPI: Choosing a wave format for exclusive output

查看:1490
本文介绍了WASAPI:选择专用输出波形格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开使用WASAPI输出设备的独家流。我无法选择一个可以接受的格式,因为似乎没有提示至于什么格式由给定的设备接受。

I'm trying to open an exclusive stream with an output device using WASAPI. I'm having trouble choosing an acceptable format, since there appear to be no hints as to what formats are accepted by a given device.

在我的情况下, IAudioClient :: GetMixFormat(),否则会返回一个排序默认格式为设备,返回不能使用的格式独占模式( IAudioClient :: IsFormatSupported()收益 AUDCLNT_E_UNSUPPORTED_FORMAT )。我不知道从哪里里去。有波格式参数组合的一些荒谬 - 我从字面上通过他们的每一个迭代,直到一些作品

In my case, IAudioClient::GetMixFormat(), which would otherwise return a sort of default format for the device, returns a format that can't be used in exclusive mode (IAudioClient::IsFormatSupported() returns AUDCLNT_E_UNSUPPORTED_FORMAT). I don't know where to go from there. There's a ridiculous number of combinations of wave format parameters - do I literally have to iterate through every one of them until something works?

推荐答案

好吧,我问在MSDN论坛,他们想出了一个很好的答案。

Well, I asked the MSDN forums and they came up with a good answer.

您需要通过 IMMDevice :: OpenPropertyStore(),随后 IPropertyStore ::的GetValue(),而不是 IAudioClient :: GetMixFormat()。下面是获取一个可接受的WAVEFORMATEX结构code:

You need to check the device's default device format via IMMDevice::OpenPropertyStore(), and subsequently IPropertyStore::GetValue(), not IAudioClient::GetMixFormat(). Here is the code that retrieved an acceptable WAVEFORMATEX structure:

//CoInitialize/Enumerate devices

IPropertyStore* store = nullptr;

hr = device->OpenPropertyStore(STGM_READ, &store);

if (FAILED(hr)) {
    ExitProcess(1);
}

PROPVARIANT prop;

hr = store->GetValue(PKEY_AudioEngine_DeviceFormat, &prop);

if (FAILED(hr)) {
    ExitProcess(2);
}

hr = device->Activate (
    __uuidof(IAudioClient), 
    CLSCTX_ALL,
    NULL,
    (void**)&audioClient
);

device->Release();
device = nullptr;

if (FAILED(hr)) {
    ExitProcess(3);
}

hr = audioClient->IsFormatSupported (
    AUDCLNT_SHAREMODE_EXCLUSIVE,
    (PWAVEFORMATEX)prop.blob.pBlobData,
    NULL
);

if (FAILED(hr)) {
    ExitProcess(4);
}

h的最终值是S_OK。

The final value of hr is S_OK.

这篇关于WASAPI:选择专用输出波形格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆