LoopbackCapture (`ActivateAudioInterfaceAsync` with `VIRTUAL_AUDIO_DEVICE_PROCESS_LOOPBACK` ), m_AudioClient->GetMixFormat failed with E_NOTIMPL

TianpingHsu 26 Reputation points
2022-12-12T12:57:24.777+00:00

Hi, I use the applicationloopbackaudio-sample to record system audio, it works fine. However, the capture format is hard coded:

// The app can also call m_AudioClient->GetMixFormat instead to get the capture format.  
// 16 - bit PCM format.  
m_CaptureFormat.wFormatTag = WAVE_FORMAT_PCM;  
m_CaptureFormat.nChannels = 2;  
m_CaptureFormat.nSamplesPerSec = 44100;  
m_CaptureFormat.wBitsPerSample = 16;  
m_CaptureFormat.nBlockAlign = m_CaptureFormat.nChannels * m_CaptureFormat.wBitsPerSample / 8;  
m_CaptureFormat.nAvgBytesPerSec = m_CaptureFormat.nSamplesPerSec * m_CaptureFormat.nBlockAlign;  

according to the comment, I can use m_AudioClient->GetMixFormat to get the capture format, but it failed with error code: E_NOTIMPL

WAVEFORMATEX* pWfxOut = NULL;  
HRESULT hr = m_AudioClient->GetMixFormat(&pWfxOut);  
// hr is E_NOTIMPL, failed to GetMixFormat  

I'd like to know:

  1. why does this happen?
  2. how should I get the valid capture format supported by System
  3. or is it just ok to use the hard coded capture format (channel: 2, sampleRate: 44100, bitsPerSample: 16)?

many thanks.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,608 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,716 questions
{count} vote

Accepted answer
  1. Junjie Zhu - MSFT 17,801 Reputation points Microsoft Vendor
    2023-03-03T08:57:12.89+00:00

    Hi @TianpingHsu @learner~.~ ,

    Welcome to Microsoft Q&A!

    The audio sample demonstrates the scenario for process-based loopback capture, and this is actually not tied to a specific audio endpoint. Internally the m_AudioClient interface points to the AudioSes!CMixerClient class but unfortunately the GetMixFormat() and IsFormatSupported() methods are not supported in the class. This is the reason why you get E_NOTIMPL on COM calls.

    User's image

    The audio format hard coded in the sample code, this is the CD quality audio format (2 channel, 16 bit, 44100 Hz) which is the most popular format used in WAV audio, so it is safe to use this hard coded format. You can submit a request to the Github to remove the incorrect comments.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Tony 96 Reputation points
    2024-05-09T15:30:03.31+00:00

    So, If I read this correctly: Some methods of IAudioClient are not implemented as the result code = E_NOT_IMPLEMENTED. So are the interfaces IAudioClient2 and IAudioClient3 (E_NOINTERFACE)?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.