-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Add support for variable output latency in WASAPI audio driver #38210
Add support for variable output latency in WASAPI audio driver #38210
Conversation
I've also implemented this in my own 3.2 branch for a musc/rhythm based project I am working on that requires this fix. Let me know if you'd like me to create a pull request for that. |
Could you squash commits into one? See PR workflow. |
Apologies, will do and I'll review the PR workflow |
dcc59a8
to
4d40ff3
Compare
0d7cb78
to
30acc29
Compare
Removed |
GetBufferSize appears to return an incorrect value when using InitializeSharedAudioStream to set a buffer size different than default, this is probably due to window compatibility stuff? I have a (I believe) fix here: EIRTeam@68e098a |
Thank you, I'll give it a look. Which Windows version(s) did you test on and what compiler(s) did you use? |
I can reproduce this, but only sometimes; IAudioClient3 behaves differently for different audio devices.
This works like a charm, thank you! I'll squash that into my PR. P.S. Sorry about closing/reopening, accidentally hit 'close with comment' |
You're welcome! I've also done some testing on linux with pulse and it appears like the reported latency by get_output_latency is way too high (on the order of 50 ms) but it sure doesn't FEEL like it, I wonder what's going on. |
544af92
to
4013841
Compare
I think I may have found part your problem. From this page:
PA_STREAM_INTERPOLATE_TIMING and PA_STREAM_AUTO_TIMING_UPDATE are passed in Godot's pulse driver so this applies. PA_STREAM_ADJUST_LATENCY is also passed allowing pulse to adjust the latency of the stream as it sees fit. This means means that After realising this could be an issue I modified
And I got the following output:
When this was run the engine audio output latency was set to 5ms (256 audio frames). So I guess in your case it's plausible that AudioDriverPulseAudio::get_latency() returned the correct latency at the time it was called, but Pulse eventually reduced it which is why it doesn't feel as high as Godot claims it is. DISCLAIMER: I skimmed the Pulse Audio documentation extremely briefly. Apologies for getting off topic. I guess this should submitted as an issue if it hasn't been already? |
I'm starting to believe my change isn't entirely a good idea, users have reported pops and desyncs, so maybe we should actually believe getbuffersize after all. |
Reading the documentation:
so from what I understand getbuffersize is the size of the internal buffer that's between the application and WASPI, and wasapi might read this buffer with a periodicity that's higher than the actual buffer size |
…sing the WASAPI audio driver. Added variable output latency support to the WASAPI audio driver for systems that support it.
ec334e2
to
880d470
Compare
I polled the audio channel on rocket chat. This is a lot of Windows specific code and one person said they're not qualified to say if it's a good change or not because of that. Is there a way to have an easier review? |
I asked around for people who've written similar IAudioClient3 code for rhythm games (particularly project DIVA) and they say it appears to be spot on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked around for people who've written similar IAudioClient3 code for rhythm games (particularly project DIVA) and they say it appears to be spot on.
I also reviewed it when the PR came out and it looked correct comparing it to MS's documentation.
I've also been using it in production for a while and people report it's fine on w7 too (which is where the iaudioclient3 interface stops existing).
Approved because of review by @EIREXE.
Calinou marked this conversation as resolved.
Thanks. |
With this merged we should probably make an issue/PR for the docs that mention the limitations of the audio latency project setting. Depending on the operating system and hardware audio driver Godot may have to pick the nearest latency that the system allows. Examples:
Should I go ahead and do this? |
@benjarmstrong yes please, doc changes are usually included with PRs as appropriate. It would be great if you could make a docs PR as soon as convenient. |
Will do |
A backport for |
Oh absolutely, I've been using my own backport of this for ages now. I'll get on that |
I have a backport to current-ish 3.x here: EIRTeam@7df5185 |
A PR would be welcome yes :) Be sure to include the fix from #53319 too. |
If a cherry-pick PR is made, #54880 should also be included to solve a regression. |
Fixed the audio 'output latency' project setting not appearing when using the WASAPI audio driver (see #30562). Added variable output latency support to the WASAPI audio driver for systems that support it.
Bugsquad edit: This closes #30562.