pwfx->wFormatTag = WAVE_FORMAT_EXTENSIBLE; // not WAVE_FORMAT_IEEE_FLOAT;
WASAPI IsFormatSupported succeeds but causes Initialize to fail
Is there a situation where IsFormatSupported will succeed but the input format will not actually be a valid format for an exclusive mode stream for audio?
I'm using WASAPI's Exclusive Mode stream to try to get raw audio data from the OS and would like to get it in IEEE float (for it's increased accuracy over s16 PCM). The IsFormatSupported passes without error using the format specified below, yet, when I call Initialize, I get back an error of 0x80070057. Has anyone experienced anything similar to this?
A snippet of my code is shown below (everything runs successfully except the last printf, which is never reached. The above error is thrown directly before that line is run):
WAVEFORMATEXTENSIBLE pwfx_ex_back;
pwfx = (WAVEFORMATEX *) &pwfx_ex_back;
WAVEFORMATEXTENSIBLE *pwfx_ex = (WAVEFORMATEXTENSIBLE*) &pwfx_ex_back;
pwfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
pwfx->nChannels = 2;
pwfx->nSamplesPerSec = 48000;
pwfx->wBitsPerSample = 32;
pwfx->nBlockAlign = (pwfx->nChannels * pwfx->wBitsPerSample) / 8;
pwfx->nAvgBytesPerSec = pwfx->nChannels * pwfx->nSamplesPerSec * (pwfx->wBitsPerSample / 8);
pwfx->cbSize = 22;
pwfx_ex->Samples.wValidBitsPerSample = 32;
pwfx_ex->dwChannelMask = 0x00000001 | 0x00000002;
pwfx_ex->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
print_waveformat(pwfx);
write_headers_for_wav_file(wavfile, pwfx);
WAVEFORMATEX **ppClosestMatch = NULL;
hr = pAudioClient->IsFormatSupported(
AUDCLNT_SHAREMODE_EXCLUSIVE,
pwfx,
NULL
);
EXIT_ON_ERROR(hr)
printf("Closest match pointer-to-a-pointer value: %llx\n", (uint64_t) ppClosestMatch);
REFERENCE_TIME phnsDefaultDevicePeriod;
REFERENCE_TIME phnsMinimumDevicePeriod;
hr = pAudioClient->GetDevicePeriod(
&phnsDefaultDevicePeriod,
&phnsMinimumDevicePeriod);
EXIT_ON_ERROR(hr)
printf("Default Period: %lli, Minimum Period: %lli\n", phnsDefaultDevicePeriod, phnsMinimumDevicePeriod);
hr = pAudioClient->Initialize(
AUDCLNT_SHAREMODE_EXCLUSIVE,
0,
60000, // 10 is 1 us, 10000 is 1 ms, 10000000 is 1 second, 0 is defaultminimumperiod for exclusive mode streams
30000,
pwfx,
NULL
);
EXIT_ON_ERROR(hr)
printf("Audioclient Initialized successfully.\n");