godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

Add a `--audio-output-latency` command line argument to override the audio mix latency on any project #5450

Closed Calinou closed 1 year ago

Calinou commented 2 years ago

Related to https://github.com/godotengine/godot-proposals/issues/1923, https://github.com/godotengine/godot-proposals/issues/5448 and https://github.com/godotengine/godot-proposals/issues/5449.

Describe the project you are working on

The Godot editor :slightly_smiling_face:

Describe the problem or limitation you are having in your project

This is a continuation of https://github.com/godotengine/godot-docs/pull/6186 (except it's about audio latency, rather than visual latency).

When playing a game made by someone else, it's sometimes desired to override the audio output latency if the developer doesn't provide any way to control it. This is common in gamejam games, for instance.

If you have a CPU with fast single-core performance, you can often decrease audio latency significantly without introducing audio stutter or popping. Games' default configurations have to work well on low-end CPUs, so it's not uncommon to be able to divide a game's audio latency by 2 or even 3 in commercially released games simply by reducing the output latency setting.

This is particularly important in rythm games, but also in any kind of competitive game where acknowledging sound cues as early as possible can give you an advantage. See this video for more information.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I propose adding a --audio-output-latency <ms> CLI argument that handles overall V-Sync status when the project starts:

  --audio-output-latency <ms>    Audio buffer length in milliseconds. Lower values result in less lag but can introduce popping if the CPU can't keep up.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

main/main.cpp should be modified to accomodate for the new CLI argument.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No.

Is there a reason why this should be core and not an add-on in the asset library?

It can technically be an add-on, but the point here is that this functionality must be built-in to achieve the desired goal (which is, adjusting audio output latency on any project made with Godot).

ellenhp commented 1 year ago

A starting point would be adding the ability for the latency to be adjusted in the first place. Right now the mix buffer is fixed in size so we'd need to change that first.

edit: to be clear I fully support this proposal :)

Calinou commented 1 year ago

A starting point would be adding the ability for the latency to be adjusted in the first place. Right now the mix buffer is fixed in size so we'd need to change that first.

Yes, I agree it should be possible to do this at run-time somehow. I've seen some games be able to do this without requiring a restart of their audio subsystem (e.g. snd_restart in Source games), but I don't know how they achieve this.