You do this:
if (bFirstPacket && AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY == dwFlags) {
LOG(L"%s", L"Probably spurious glitch reported on first packet");
} else if (0 != dwFlags) {
LOG(L"IAudioCaptureClient::GetBuffer set flags to 0x%08x on pass %u after %u frames", dwFlags, nPasses, *pnFrames);
return E_UNEXPECTED;
}
On my PC I systematically receive a combination of AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY and AUDCLNT_BUFFERFLAGS_SILENT on the 1st packet so the code will return E_UNEXPECTED and I don't see why it should.
I think you should just test for AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR (maybe? can't we just continue even on this error?) and don't care about the other flags? At least it works for me with these changes.
PS: There's another glitch with the keyboard test: if I run the app from a console, it exits immediately. I had to change the stdin test events.