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 ms
which 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?