Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasapi: Workaround for the Realtek driver "Mono" bug #934

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dmitrykos
Copy link
Collaborator

Workaround for the Realtek driver bug when driver mistakenly accepts Mono format with IAudioClient_IsFormatSupported() while subsequently fails in IAudioClient_Initialize().

It is a long-lasting issue #875 which was resolved with a kind debugging help by @arkadijs.

Closes #875.

@arkadijs
Copy link
Contributor

arkadijs commented Jul 1, 2024

Confirming, this fixes the issue with the buggy? Realtek driver.

@dmitrykos
Copy link
Collaborator Author

@arkadijs thank you very much for testing. Now let's wait for a review from @RossBencina and @philburk to get this PR approved.

Copy link
Collaborator

@RossBencina RossBencina left a comment

Choose a reason for hiding this comment

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

I have not tested it, but it looks OK. my main concern would be whether this could introduce a regression on other drivers. is it passing the PortAudio pa_loopback tests?

@dmitrykos dmitrykos force-pushed the win_wasapi_shared_mono_fail_workaround branch 2 times, most recently from 82a2d35 to ca10cd9 Compare July 6, 2024 08:13
@dmitrykos
Copy link
Collaborator Author

I have not tested it, but it looks OK. my main concern would be whether this could introduce a regression on other drivers. is it passing the PortAudio pa_loopback tests?

Great that you mentioned it! I modified workaround to exclude Input mode as this driver bug is related to Output only.

As to pa_loopback - it fails for WASAPI on [Loopback] device because of this #935 issue - when there is no audio sent to WASAPI internal mixer from some opened audio streams the attempt to read data from [Loopback] device will timeout i.e. PaQa_RunInputOnly() fails. But it has nothing to do with workaround of this PR - tested.

I propose to discuss the timeout of [Loopback] WASAPI device in #935, there we can also discuss whether a workaround needed in pa_loopback implementation for loopback devices which timeout without audio data collected from other opened audio streams, or perhaps PA WASAPI needs some workaround for this specific behavior.

This PR looks ok for me to commit.

@dmitrykos dmitrykos force-pushed the win_wasapi_shared_mono_fail_workaround branch from ca10cd9 to 7030e30 Compare July 13, 2024 11:03
@arkadijs
Copy link
Contributor

There is one problem with the latest version though: output == 0 thus workaround never activates.

Removing if (output && allows recording to proceed. Added some printf calls for debug:

device name: Słuchawki (Realtek(R) Audio) [Loopback]; hr = 1; output = 0
device name: Słuchawki (Realtek(R) Audio) [Loopback]; hr = 1; output = 0
device name: Słuchawki (Realtek(R) Audio) [Loopback]; hr = 1; output = 0
device name: Słuchawki (Realtek(R) Audio) [Loopback]; hr = 1; output = 0
device name: Słuchawki (Realtek(R) Audio) [Loopback]; hr = 0; output = 0
should we try Realtek workaround?
activating Realtek workaround
Słuchawki (Realtek(R) Audio) [Loopback]: trying callback API...
device name: Słuchawki (Realtek(R) Audio) [Loopback]; hr = 0; output = 0
should we try Realtek workaround?
activating Realtek workaround
Słuchawki (Realtek(R) Audio) [Loopback]: stream active: 1
Słuchawki (Realtek(R) Audio) [Loopback]: success

@arkadijs
Copy link
Contributor

arkadijs commented Jul 15, 2024

Another issue: callback API works perfectly but sync Pa_ReadStream() produces grabled audio which is recognizable yet sounds like a wrong format, clipped? or bad interleave. Sample rate and length of the audio are correct. Capturing mic with sync API works.
Please let me know if you need the output sample or any additional debug info.

…accepts Mono format with IAudioClient_IsFormatSupported() while subsequently fails in IAudioClient_Initialize() (issue PortAudio#875).
@dmitrykos dmitrykos force-pushed the win_wasapi_shared_mono_fail_workaround branch from 7030e30 to 303d208 Compare July 16, 2024 06:20
@dmitrykos
Copy link
Collaborator Author

@arkadijs thank you very much for testing again, that was typo on my side. I modified that check to !output to limit the case only to capturing devices:

        if (!output && isSharedMode && (params.channelCount == 1) && (sharedClosestMatch == NULL) &&
            (deviceInfo->MixFormat.Format.nChannels > 1))

Would you please double check if it still works well for you to double confirm.

callback API works perfectly but sync Pa_ReadStream() produces grabled audio which is recognizable yet sounds like a wrong format, clipped?

I managed to reproduce it by modifying paex_read_write_wire.c example which reads Loopback and writes to Speakers. I used Speakers for listening and USB DAC for playing to it with another app. It is not related to the workaround of this PR though and is an old bug. I propose to open new issue which we will close with a new PR related to this issue. Would you please open it as long as you initially found and reported this problem.

@arkadijs
Copy link
Contributor

Tested latest version with !output and it works for me. Thanks!

Opened #945.

@dmitrykos
Copy link
Collaborator Author

Tested latest version with !output and it works for me. Thanks!

Great! Lets wait for @RossBencina to resolve his question.

@RossBencina
Copy link
Collaborator

I'll merge this once CI passes

@arkadijs
Copy link
Contributor

arkadijs commented Jul 19, 2024

GHA had issues yesterday, please bump the jobs bumped to clear CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src-wasapi MS WASAPI Host API /src/hostapi/wasapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Win32/WASAPI loopback: can not open stream at mono mode, paInvalidChannelCount
4 participants