0

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?

Ashot
  • 10,807
  • 14
  • 66
  • 117
  • 1
    Post this question on the appropriate Windows support forum. There's a guy there called Matthew van Eerde who will likely answer this. – Paul Sanders Jun 28 '22 at 22:23
  • 1
    Not sure if it is the right place but I asked it here https://answers.microsoft.com/en-us/windows/forum/windows_10-performance/wasapi-delays-on-maudioclient-start/ac25153f-698f-4c4c-b34f-cb5615412497 – Ashot Jun 28 '22 at 22:36
  • Worth a shot. I'll see if I can find somewhere better targeted. – Paul Sanders Jun 29 '22 at 06:16
  • Hokay, last time I had an audio-related question I posted here: https://social.msdn.microsoft.com/Forums/WINDOWS (and I did get a reply from Matthew). But that was a while ago now, so YMMV, as they say. Oh, and you might need an MSDN membership to post there, I'm not actually sure. – Paul Sanders Jun 29 '22 at 11:43

0 Answers0