Skip to content

Commit

Permalink
updating how to interpret return from IAudioClient.IsFormatSupported …
Browse files Browse the repository at this point in the history
…- see #284
  • Loading branch information
markheath committed Jan 21, 2019
1 parent 5c8183c commit b0c96cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions NAudio/CoreAudioApi/AudioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ public bool IsFormatSupported(AudioClientShareMode shareMode, WaveFormat desired
}
if (hresult == (int)AudioClientErrors.UnsupportedFormat)
{
// Succeeded but the specified format is not supported in exclusive mode.
return shareMode != AudioClientShareMode.Exclusive;
// documentation is confusing as to what this flag means
// https://docs.microsoft.com/en-us/windows/desktop/api/audioclient/nf-audioclient-iaudioclient-isformatsupported
// "Succeeded but the specified format is not supported in exclusive mode."
return false; // shareMode != AudioClientShareMode.Exclusive;
}
Marshal.ThrowExceptionForHR(hresult);
// shouldn't get here
Expand Down

3 comments on commit b0c96cd

@Alexx999
Copy link

@Alexx999 Alexx999 commented on b0c96cd Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ended up debugging this very issue.
Documentation is pretty clear in fact:
https://docs.microsoft.com/en-us/previous-versions//ms678737(v=vs.85)

For exclusive mode, IsFormatSupported returns S_OK if the audio endpoint device supports the caller-specified format, or it returns AUDCLNT_E_UNSUPPORTED_FORMAT if the device does not support the format
For shared mode, ... If the audio engine does not support the caller-specified format or any similar format, the method sets *ppClosestMatch to NULL and returns AUDCLNT_E_UNSUPPORTED_FORMAT

Basically, S_FALSE means there's something in ppClosestMatch and AUDCLNT_E_UNSUPPORTED_FORMAT means that ppClosestMatch is NULL

@markheath
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I had been confused by the phrase "Succeeded but the specified format is not supported in exclusive mode." which sounded to me like the specified format was supported in shared mode. My mistake.

@parapsychopatolog
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very glad for this update. I was many problems with this condition. Thanks!

Please sign in to comment.