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

Sync AudioServer & AudioDriver buffer sizes and fix latency inaccuracies #52626

Closed
wants to merge 1 commit into from

Conversation

ellenhp
Copy link
Contributor

@ellenhp ellenhp commented Sep 13, 2021

This is a rebase of #38280 with some style fixes and slight changes all around. More accurately I reapplied all changes by hand, so if you've previously reviewed that PR please still look carefully at this one.

Please review paying special attention to any assumptions that may have been made about the buffer size in the AudioServer being 1024, and more recently 512. According to Ben and another developer in the comments of # #38280 it sounds like this change or some variation of it has been used in at least one shipped title, but I worry that (as an example) perhaps there's an FFT in one of the AudioEffects that will break when passed a non-power-of-two by an AudioDriver that chooses to only allocate 500 samples instead of 512, or something.

Overall this change will be an incredible help for developers that need low-latency audio, since before the AudioServer limited latency to at least the length of its hardcoded buffer.

@ellenhp ellenhp force-pushed the latency_fixes_4_0_dev branch 4 times, most recently from d50d934 to f545022 Compare September 13, 2021 04:26
Co-authored-by: Ben Armstrong <ben@avsoftlabs.com>
@ellenhp ellenhp marked this pull request as ready for review September 13, 2021 04:32
@ellenhp ellenhp requested review from a team as code owners September 13, 2021 04:32
@Calinou Calinou added this to the 4.0 milestone Sep 13, 2021
@fire fire requested a review from reduz September 16, 2021 15:39
@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Sep 19, 2021
@ellenhp
Copy link
Contributor Author

ellenhp commented Sep 19, 2021

Reduz mentioned in rocket.chat that we should be talking to the audio system in each driver to determine the latency, and that this method of calculation isn't accurate enough to be acceptable. I'm considering splitting this into two PRs. One to make the buffer size impacted by the latency parameter, and the other to make get_latency behave correctly. The second goal will be much more difficult for me, since I can't really test all platforms easily.

reduz
reduz previously approved these changes Jun 22, 2022
@@ -1345,7 +1345,14 @@ void AudioServer::init() {
channel_disable_threshold_db = GLOBAL_DEF_RST("audio/buses/channel_disable_threshold_db", -60.0);
channel_disable_frames = float(GLOBAL_DEF_RST("audio/buses/channel_disable_time", 2.0)) * get_mix_rate();
ProjectSettings::get_singleton()->set_custom_property_info("audio/buses/channel_disable_time", PropertyInfo(Variant::FLOAT, "audio/buses/channel_disable_time", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"));
buffer_size = 512; //hardcoded for now
if (AudioDriver::get_singleton()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be always assumed you have an audio driver at this point, so the check is unnecessary.

@reduz
Copy link
Member

reduz commented Jun 22, 2022

I think the general idea for this PR is good, and it could be merged as is, but I have the feeling that

  1. Not all the audio APIs let you choose a buffer size (as an example, jack and PA to some extent)
  2. Not all the audio APIs will respect your chosen buffer size, because it may be hardware restricted.
  3. Not all the audio the APIs have latency depend on buffer size entirely since you can control the amount of buffers (fragments).

I have the feeling that this needs a bit more of research to ensure its really done as best as it can possibly be.

@akien-mga akien-mga modified the milestones: 4.0, 4.1, 4.x Feb 10, 2023
@YuriSizov YuriSizov dismissed reduz’s stale review March 15, 2023 14:45

Needs more work

@ellenhp ellenhp closed this Apr 25, 2024
@AThousandShips AThousandShips removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Apr 25, 2024
@AThousandShips AThousandShips removed this from the 4.x milestone Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants