3

我第一次尝试使用 AudioClient 接口,但没有运气。到目前为止,我设法使用成功的 MMDeviceEnumerator 和 MMDevice 接口获得了默认的 AudioClient 接口:

CoCreateInstance(
       CLSID_MMDeviceEnumerator, nil,
       CLSCTX_ALL, IID_IMMDeviceEnumerator,
       MMEnumerator);
MMEnumerator.GetDefaultAudioEndpoint(eRender,eConsole,MMDevice);
MMDevice.Activate(IID_IAudioClient, CLSCTX_ALL, nil, AudioClient);

(这里不包括结果检查代码)。这 3 个调用都没有返回任何错误,并且我在 AudioClient 变量中有一个非零接口 ptr。我的问题是当我尝试获得混合波形时:

AudioClient.GetMixFormat(pwfx)

这将返回代码 0x88890001,即 AUDCLNT_E_NOT_INITIALIZED。-> 当然没有初始化,因为我只想先得到它喜欢的波形。

查找msdn告诉可以在AudioClient.Initialization之前调用AudioClient.GetMixFormat。AUDCLNT_E_NOT_INITIALIZED 也不在可能的返回值列表中。所以我很困惑我做错了什么。GetMixFormat() 文档-> http://msdn.microsoft.com/en-us/library/windows/desktop/dd370872(v=vs.85).aspx

另一个奇怪的事情是,当我调用 AudioClient.GetStreamLatency() 时,它返回 S_OK 和一个大约 1000 毫秒的准随机值。但是文档指出“此方法需要事先初始化 IAudioClient 接口。在客户端通过成功调用初始化音频流之前,对该方法的所有调用都将失败并出现错误 AUDCLNT_E_NOT_INITIALIZED”。因此,我认为我有一个可用的 AudioClient 接口,我只是不明白为什么它不像文档所说的那样工作。

(我使用的是 64 位 win7,Sound Blaster Live 5.1 和 kx-project 驱动程序(DSound 和经典 windows MM 声音工作正常,但有 100 毫秒可怕的长延迟,这就是我要在 win7 上使用 WASAPI 的唯一原因)

先感谢您。

4

1 回答 1

3

我实际上发现了这个错误。MFPackIAudioClient中的定义不正确,接口函数顺序错误。(我想有一天以某种方式推动它,如果我找到时间,转移到 git 等。)这是 IAudioClient 中方法的正确顺序:

IAudioClient = interface(IUnknown)
['{1CB9AD4C-DBFA-4c32-B178-C2F568A703B2}']
    function Initialize(ShareMode: AUDCLNT_SHAREMODE; StreamFlags: Dword; hnsBufferDuration: REFERENCE_TIME; hnsPeriodicity: REFERENCE_TIME; pFormat: PWaveFormatEx; AudioSessionGuid: LPCGUID): HResult; stdcall;
    function GetBufferSize(out pNumBufferFrames: UINT32): HResult; stdcall;
    function GetStreamLatency(out phnsLatency: REFERENCE_TIME): HResult; stdcall;
    function GetCurrentPadding(out pNumPaddingFrames: UINT32): HResult; stdcall;
    function IsFormatSupported(ShareMode: AUDCLNT_SHAREMODE; pFormat: PWaveFormatEx; out ppClosestMatch: PWaveFormatEx): HResult; stdcall;
    function GetMixFormat(out ppDeviceFormat: PWaveFormatEx): HResult; stdcall;
    function GetDevicePeriod(out phnsDefaultDevicePeriod: REFERENCE_TIME; phnsMinimumDevicePeriod: REFERENCE_TIME): HResult; stdcall;
    function Start(): HResult; stdcall;
    function Stop(): HResult; stdcall;
    function Reset(): HResult; stdcall;
    function SetEventHandle(const eventHandle: HANDLE): HResult; stdcall;
    function GetService(const riid: TGUID; out ppv: Pointer): HResult; stdcall;
    //The GetService method supports the following service interfaces: IAudioCaptureClient, IAudioClock, IAudioRenderClient,
    //IAudioSessionControl, IAudioStreamVolume, IChannelAudioVolume, IMFTrustedOutput, ISimpleAudioVolume.
    //Since Windows 7 the new interface indentifier IID_IMFTrustedOutput has been added, but is not implemented here.
end;

函数ReleaseBuffer也是错误的,这是正确的参数:

IAudioRenderClient = interface(IUnknown)
['{F294ACFC-3146-4483-A7BF-ADDCA7C260E2}']
    function GetBuffer(const NumFramesRequested: UINT; out ppData: PByte): HResult; stdcall;
    function ReleaseBuffer(const NumFramesWritten: UINT32; const dwFlags: DWord): HResult; stdcall;
end;
于 2015-02-26T11:06:39.060 回答