I'm developing audio code for a program that needs to be able to record and playback on a variety of devices, some of them high end, with a variety of different wav and AIFF formats. I expected to be able to use the WASAPI library, but I'm hitting some major problems. The biggest one right now is that, as far as I can tell, devices are only allowed to play streams that are in exactly matching formats.
Here's what I'm doing- I set the device (here I'm just getting the default console device) with:
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pPlaybackDevice);
I activate the device with:
hr = pPlaybackDevice->Activate( __uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pTakeAudioClient);
Then I check the mix format with:
hr = pTakeAudioClient->GetMixFormat(&pWaveFormatEx);
However, if I use a different format when calling Initialize:
hr = pTakeAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST,hnsRequestedDuration, 0, pAnotherWaveFormatEx,NULL);
I get an error. It seems like the file absolutely has to be in the format returned by GetMixFormat. If I call IsFormatSupported to find out what formats I can submit:
hr = pTakeAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &waveFormatEx, &pAnotherWaveFormatEx);
I get E_INVALIDARG
, even if both structures are exactly the same. According to the WASAPI documents, that return comes when "Parameter ShareMode is a value other than AUDCLNT_SHAREMODE_SHARED
or AUDCLNT_SHAREMODE_EXCLUSIVE
." I am passing AUDCLNT_SHAREMODE_SHARED
. This appears to be an error in the documentation.
The mystery deepens when, for the sake of experimentation, I try:
hr = pTakeAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, &waveFormatEx, NULL);
The error return is 0x8889000e
- I have not been able to find a reference to that error.
Any help you can provide will be received most gratefully, even if it is "use MMSystem". I would have started with MMSystem except that we need to be able to control the playback device when there are multiple devices.