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: Improvement to lower possible cases of underruns due to coarse system timer and time-hungry user-side processing.. #307

Merged
merged 1 commit into from
Oct 3, 2020

Conversation

dmitrykos
Copy link
Collaborator

To combat underruns there were several changes implemented:

  1. Implemented workaround for system timer coarse granularity causing underruns by using timeBeginPeriod/timeEndPeriod APIs inside the Event and Poll thread handlers. Coarse system timer breaks precision of waiting for a next time slot causing underruns as a result.

  2. Updated next sleep time of the Poll rendering loop dynamically depending on time taken for processing/rendering of audio data into the available host buffer to avoid underruns and fit processing time into periodic polling time slots. It will minimize possibility of the underruns if user buffer is 1/2 of the host buffer and user code takes less than 1/2 of the host buffer duration.

@dmitrykos dmitrykos closed this Sep 30, 2020
@dmitrykos dmitrykos reopened this Sep 30, 2020
@dmitrykos dmitrykos linked an issue Sep 30, 2020 that may be closed by this pull request
@dmitrykos dmitrykos added the src-wasapi MS WASAPI Host API /src/hostapi/wasapi label Sep 30, 2020
@dmitrykos dmitrykos self-assigned this Sep 30, 2020
@RossBencina
Copy link
Collaborator

@dmitrykos to remove the unwanted merge commits, you should be able to rebase your branch off master and force update, something like:

https://www.digitalocean.com/community/tutorials/how-to-rebase-and-update-a-pull-request

Please don't merge untidy commit history to master. Use squash and/or rebase GitHub merge options.

@dmitrykos
Copy link
Collaborator Author

@RossBencina thank you very much for the tutorial on rebasing, managed to cleanup that mess successfully :)

@dmitrykos dmitrykos changed the title WASAPI: Improvement to lower possible cases of underruns due to coarse system timer and time-hungry user-side processing.. wasapi: Improvement to lower possible cases of underruns due to coarse system timer and time-hungry user-side processing.. Oct 1, 2020
@sveinse
Copy link
Contributor

sveinse commented Oct 3, 2020

@dmitrykos I confirm that aecafb1 is an effective fix to #303 on my system in shared mode. My system has 1056 samples as the lowest host buffer size. I have tested user buffer size of 2112, 1056, 528, 264, 132, 66, 1024 on multiple devices (built-in audio, HDMI and USB), each 5 times each and I have no glitching.

…ow host latency requsted (22 ms):

- Implement workaround for system timer coarse granularity causing underruns by using timeBeginPeriod/timeEndPeriod APIs inside the Event and Poll thread handlers.
- Update next sleep time of the Poll rendering loop dynamically depending on time taken for processing/rendering of audio data into the available host buffer to avoid underruns and fit processing time into periodic polling time slots.
- Add support for time slots logging in Poll mode if PA_WASAPI_LOG_TIME_SLOTS is defined. Fixed audible glitches by preloading the whole host buffer before stream is started.
- Fix audible glitches on stream start by preloading the whole host buffer before stream is started.
@dmitrykos
Copy link
Collaborator Author

@sveinse , thank you very much for testing and confirmation, I summarized our work in #303 and hope other PA's user will find it useful.

@dmitrykos dmitrykos closed this Oct 3, 2020
@dmitrykos dmitrykos reopened this Oct 3, 2020
@dmitrykos dmitrykos merged commit 8c6cc73 into master Oct 3, 2020
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.

Glitching in WASAPI in shared mode
3 participants