wasapi,延迟m_audioclient-> start()

发布于 2025-02-11 12:57:28 字数 1357 浏览 1 评论 0原文

该应用使用Wasapi从麦克风中捕获声音。

此代码初始化m_audioclient类型iaudioclient*

const LONG CAPTURE_CLIENT_LATENCY = 50 * 10000;
DWORD loopFlag = m_IsLoopback ? AUDCLNT_STREAMFLAGS_LOOPBACK : 0;
hr = m_AudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED
    , AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST | loopFlag
    , CAPTURE_CLIENT_LATENCY, 0, m_WaveFormat->GetRawFormat(), NULL); 

然后,我使用m_audioclient-> start()m_audioclient-> stop()暂停或简历捕获。

美国m_audioclient-> start()采用5-6 ms,但有时需要大约150 ms,这对于应用程序来说太多了。

如果我曾经打电话m_audioclient-> start(),那么在下一个下一个ocaudioclient-> start() 5 seconds> seconds> seconds> seconds> seconds>秒钟将很快快但是在大约10-15秒后,m_audioclient-> start()的下一个呼叫将吸收logner(150 ms)。因此,看起来它可以保持几秒钟的状态,然后需要再次到达该状态,这需要一些时间。

在另一台计算机上,这延迟永远不会发生,m_audioclient-> start()的每个呼叫都大约30 ms

在第三台计算机平均持续时间m_audioclient-> start()140 ms,但峰值值大于1 s

我在所有3台机器上运行相同的代码。在大多数情况下,michrophone并不相同,它是麦克风阵列Realtek高清音频

有人可以解释为什么在持续时间内这些峰值m_audioclient-> start()发生以及如何解决它?

The app captures sound from a microphone using WASAPI.

This code initializes m_AudioClient that is of type IAudioClient*.

const LONG CAPTURE_CLIENT_LATENCY = 50 * 10000;
DWORD loopFlag = m_IsLoopback ? AUDCLNT_STREAMFLAGS_LOOPBACK : 0;
hr = m_AudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED
    , AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST | loopFlag
    , CAPTURE_CLIENT_LATENCY, 0, m_WaveFormat->GetRawFormat(), NULL); 

Then I use m_AudioClient->Start() and m_AudioClient->Stop() to pause or resume capturing.

Usaually m_AudioClient->Start() takes 5-6 ms, but sometimes it takes about 150 mswhich is too much for the application.

If I once call m_AudioClient->Start() then subsecuent calls of m_AudioClient->Start() during next 5 seconds will be fast but after about 10-15 seconds next call of m_AudioClient->Start() will take logner (150 ms). So looks like it keeps some state several seconds and after that it needs to get to that state again which takes some time.

On another machine this delays never happen, every call of m_AudioClient->Start() takes about 30 ms

On the third machine average duration of m_AudioClient->Start() is 140 ms but peak values are about 1 s.

I run the same code on all 3 machines. The michrophone is not exatly the same on most cases it is Microphone Array Realtek High Definition Audio.

Can somebody explain why these peak values for the duration m_AudioClient->Start() happen and how I can fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文