0

我正在研究游戏的音频引擎和被调用的 Microsoft Core Audio API 之间的交互。我想弄清楚游戏是如何从默认端点获取“WAVEFORMATEX”信息的。我看到在游戏开始期间的某个时间点,使用* pFormat(IsFormatSupported 的第二个参数)填充了默认端点的格式信息(即通道、bitspersample、采样率等)。我还看到在此之前游戏没有调用 GetMixFormat() [ https://msdn.microsoft.com/en-us/library/windows/desktop/dd370872(v=vs.85).aspx]

但是,有一系列与 IMMDeviceEnumerator(EnumAudioEndpoints、QuryInterface、AddRef 等)、IMMDeviceCollection(GetCount、Item)和 IMMDevice(QueryInterface、AddRef 等)相关的调用。查看这些文档,似乎没有直接获取“格式”(WAVEFORMATEX)信息的方法。虽然调用了 MMDevice::OpenPropertyStore() 并随后调用了“GetId()”,但我没有看到使用“PKEY_AudioEngine_DeviceFormat”参数调用“GetValue()”,这可能提供了“格式”信息。因此,我对游戏如何获得“格式”信息感到有些困惑。上述任何调用都可以间接获得“格式”信息吗?

我正在使用 API 监控应用程序 [ http://www.rohitab.com/downloads]进行分析,并启用了“音频和视频”过滤器。

4

1 回答 1

0

实际上可以从IsFormatSupported.

HRESULT IsFormatSupported(
  [in]        AUDCLNT_SHAREMODE ShareMode,
  [in]  const WAVEFORMATEX      *pFormat,
  [out]       WAVEFORMATEX      **ppClosestMatch //< Audio format suggested by the Windows audio engine
);

IsFormatSupported用于格式协商,在 Windows 中,如果音频图中存在能够进行转换的音频处理对象,则可以打开不同于混音器格式的音频格式。但是,如果您提供的pFormat不是混音器格式并且没有可用的转换,那么 Windows 将分配ppClosestMatch一个已分配WAVEFORMATEX的混音器格式填充。这是我测试过的示例代码,它能够从中获取混音器格式IsFormatSupported(为简单起见,没有错误处理):

CComPtr<IMMDeviceEnumerator> pEnum;
pEnum.CoCreateInstance(__uuidof(MMDeviceEnumerator));
CComPtr<IMMDevice> pDevice;
pEnum->GetDefaultAudioEndpoint(eRender, eMultimedia,&pDevice);
CComPtr<IAudioClient> pAudioClient;
pDevice->Activate( __uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pAudioClient);
// Provide an empty weveformatex
WAVEFORMATEX wfxEmpty = {};
WAVEFORMATEX *pClosestWfx;
HRESULT hr = pAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &wfxEmpty, &pClosestWfx);
if (hr == S_FALSE) {
    // The audio engine suggest us a format in pClosestWfx
    // which is the mixer format because we did not provide a valid input format.
    // the current application did not use any windows API to get the mixer format directly
    // ...
    CoTaskMemFree(pClosestWfx);
}

这是获得混音器格式的另一种方法。

于 2016-04-24T09:25:53.753 回答