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: Fixed Pa_ReadStream()/Pa_WriteStream() for 1-channel (Mono) I/O #948

Merged

Conversation

dmitrykos
Copy link
Collaborator

  • Fixes Pa_ReadStream()/Pa_WriteStream() for 1-channel (Mono) stream
  • Made several examples configurable for 1-channel operation for easier testing of Mono I/O

The problem is covered by #945 issue. Modified examples can be used to test 1-channel input/output stream, including the loopback.

After the acceptance of this PR I will further address #946 issue in another PR and refactor mono-stereo mixer's implementation names.

Closes #945

@dmitrykos dmitrykos added the src-wasapi MS WASAPI Host API /src/hostapi/wasapi label Jul 22, 2024
@dmitrykos dmitrykos self-assigned this Jul 22, 2024
@arkadijs
Copy link
Contributor

arkadijs commented Jul 22, 2024

It's better but not completely free of cracking for some? devices.

Here are two examples:
http://0x0.st/Xp1-.wav - PortAudio master
http://0x0.st/Xp1o.wav - this PR

Each file has 4 segments of ~3sec:

  1. Headphone callback
  2. Headphones read
    (short silence while msedge.exe switches to another output)
  3. Speakers callback
  4. Speakers read

While (2) is still obviously problematic it's much better now.
Test program here.

@dmitrykos dmitrykos force-pushed the win_wasapi_mono_blocking_api_fix branch from f49366e to 00770bf Compare July 24, 2024 07:46
@dmitrykos
Copy link
Collaborator Author

While (2) is still obviously problematic it's much better now.

I found the problematic place, we were writing some trash/silence behind buffer when saving trailing frames into the circular buffer. Now all is fine. I used your test bench in my tests.

Would you please check from your side.

@arkadijs
Copy link
Contributor

Tested, it works, no problems. 🎉

@dmitrykos
Copy link
Collaborator Author

That's great! I hope @RossBencina and @philburk will review this PR soon.

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 made various comments. Also:

The patch updates examples/tests with compile-time options to select number of CHANNELS and to find and select the [Loopback] device for input.

examples/paex_read_write_wire.c
examples/paex_write_sine.c
test/patest_read_record.c

Since the loopback device with this name is a WASAPI-specific thing I'm not sure whether it makes sense to update the generic examples with this feature. No need to change anything yet but this is something to discuss with Phil when he shows up.

examples/paex_read_write_wire.c Outdated Show resolved Hide resolved
examples/paex_read_write_wire.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
…tream, made some examples configurable for 1-channel operation for easier testing of Mono I/O
@dmitrykos dmitrykos force-pushed the win_wasapi_mono_blocking_api_fix branch from 00770bf to 6248ea0 Compare July 26, 2024 18:09
@dmitrykos
Copy link
Collaborator Author

@RossBencina I updated implementation based on your review notes, please check.

examples/paex_read_write_wire.c Outdated Show resolved Hide resolved
examples/paex_read_write_wire.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
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.

Hi Dmitry, I've resolved a bunch of the old feedback and added some more.

Unfortunately Phil is absent today so I can't discuss some of the remaining issues with him.

This was very time consuming to re-review. You could help by:

  1. Please do not force-push during the middle of a review. We need to be able to see what changes you made to resolve our review comments. We can always squash when we merge, or you could force-push once we have agreed to the changes.

  2. Please do not fold-in irrelevant changes such as whitespace and variable renaming. Especially when the PR is big like this one. I know that it is more work for you to keep things separate but it will make it much quicker for us to review the PRs.

Thank you!

src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
examples/paex_read_write_wire.c Outdated Show resolved Hide resolved
dmitrykos and others added 2 commits August 9, 2024 11:21
examples/paex_read_write_wire.c Outdated Show resolved Hide resolved
examples/paex_write_sine.c Outdated Show resolved Hide resolved
Added WASAPI-specific patest_read_write_wire_wasapi.c test which allows to also use Loopback devices (USE_LOOPBACK_INPUT must be 1).
…s the lowest value specified by the process.
@dmitrykos
Copy link
Collaborator Author

@philburk I made all changes we discussed, would you please check and approve if all is fine now.

…use the Loobpack WASAPI device, reverted test 'patest_read_record' back to its original state.
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.

Hi Dmitry, I'm not going to hold up the merge for my latest request, more of a nice to have.

…fer's memory succeeds, set it to 0 if memory allocation fails.
@dmitrykos
Copy link
Collaborator Author

Hi Dmitry, I'm not going to hold up the merge for my latest request, more of a nice to have.

Ross, I made proposed change, thank you for pointing to it.

@dmitrykos dmitrykos requested a review from philburk August 30, 2024 18:17
@RossBencina
Copy link
Collaborator

@philburk waiting for your review...

Copy link
Collaborator

@philburk philburk left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for doing this.
Just a minor nit about an assert being a NOOP. OK to merge as is.

src/hostapi/wasapi/pa_win_wasapi.c Outdated Show resolved Hide resolved
src/hostapi/wasapi/pa_win_wasapi.c Show resolved Hide resolved
@RossBencina RossBencina merged commit c121482 into PortAudio:master Sep 26, 2024
11 checks passed
@arkadijs
Copy link
Contributor

arkadijs commented Oct 7, 2024

I've tested the version merged into master and it works for me, thank you!

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: distorted audio while capturing via sync API
4 participants