I'm trying to access a specific USB audio device with WASAPI in exclusive mode in a UWP app. First, I'm creating a WAVEFORMATEXTENSIBLE
and check if my device supports this format :
WAVEFORMATEXTENSIBLE wf;
wf.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
wf.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wf.Format.nChannels = 2;
wf.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
// PCM 16
wf.Format.wBitsPerSample = 16;
wf.Samples.wValidBitsPerSample = wf.Format.wBitsPerSample;
wf.Format.nBlockAlign = wf.Format.nChannels * (wf.Format.wBitsPerSample / 8);
wf.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
wf.Format.nSamplesPerSec = 48000;
wf.Format.nAvgBytesPerSec = wf.Format.nSamplesPerSec * wf.Format.nBlockAlign;
hr = IAudioClient_IsFormatSupported(
pAudioClient,
AUDCLNT_SHAREMODE_EXCLUSIVE,
(WAVEFORMATEX*)&wf,
NULL);
IsFormatSupported
returns S_OK
. Then, I'm initializing the AudioClient
like this :
hr = IAudioClient_Initialize(
pAudioClient,
AUDCLNT_SHAREMODE_EXCLUSIVE,
AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
bufferDuration,
bufferDuration,
(WAVEFORMATEX*) &wf,
NULL);
The problem is here: Initialize
returns E_INVALIDARG
. According to Microsoft documentation, this can be caused by a few issues, but in my case I suspect it's the "Parameter pFormat points to an invalid format description" because I don't use any of the mentioned flags and I don't call SetClientProperty
.
Am I correctly initializing the WAVEFORMAT
?
question from:
https://stackoverflow.com/questions/65938671/iaudioclient-initialization-issues-in-exclusive-mode 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…