-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Fix AudioStreamPlayer3D still processing when out of range #96677
Fix AudioStreamPlayer3D still processing when out of range #96677
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
b834bf9
to
0b6d7be
Compare
So, when you retreat from an AudioStreamPlayer3D that is continuously playing audio, the audio stream will not stop playing audio in this PR, right? |
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.
Tested the PR. I confirm the sound not shutting off when moving outside the distance.
I tested also that this PR doesn't shut off other AudioStream3D
playing when moving. Here's the MRP:
audiostreamplayer3d-range-bug-local.zip
The audio playhead will still "continue", but no sound will be heard nor processed. |
I'm not too familiar with this class, but I see this is in a Also, should similar changes be done for AudioStreamPlayer2D, or does it already behave like this PR implements? |
Multiple Camera2D/3D or AudioListener2D/3Ds do not increase processing time. Looks like it only processes current camera per viewport. A subviewport with Camera3D increased processing time from 15 ms to 500 ms on my machine. Subviewport + Camera2D doubled processing time as expected.
Looks like it has same issue. MRP for 2D: audiostreamplayer2d-range-mrp.zip |
I can confirm what masterthedev said, for my unscientific tests I saw that:
I forgot to bring this up earlier: For the early exit of |
If you rotate the camera quickly, panning may need to update even though you're outside the range as you're still hearing the sound via the reverb effect. |
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.
Tested locally (rebased on top of master
694d3c2), it works as expected.
However, there's now an object leak that occurs on exit with the MRP:
master
$ bin/godot.linuxbsd.editor.x86_64.master --path /tmp/audiostreamplayer3d-range-bug --quit
Godot Engine v4.4.dev.custom_build.694d3c293 (2024-09-18 15:41:12 UTC) - https://godotengine.org
Vulkan 1.3.280 - Forward+ - Using Device #0: NVIDIA - NVIDIA GeForce RTX 4090
Requested V-Sync mode: Disabled
This PR
$ bin/godot.linuxbsd.editor.x86_64 --path /tmp/audiostreamplayer3d-range-bug --quit
Godot Engine v4.4.dev.custom_build.6819c26b1 (2024-09-19 12:31:25 UTC) - https://godotengine.org
Vulkan 1.3.280 - Forward+ - Using Device #0: NVIDIA - NVIDIA GeForce RTX 4090
Requested V-Sync mode: Disabled
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
at: cleanup (./core/object/object.cpp:2329)
ERROR: 1 resources still in use at exit (run with --verbose for details).
at: clear (./core/io/resource.cpp:592)
Edit: Nevermind, it happens with master
too and is sporadic.
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.
0b6d7be
to
a3158d8
Compare
This would make sense, but the
No clue myself, perhaps an internal process. It's not very straightforward to stop the mixing, from my limited experience. By the way, the performance gain when using the ogg or mp3 version of the sound is lesser, probably from the overhead of still resampling. Will look into this more, maybe I can set something so the resampling doesn't occur. I updated the PR to cache if it was out of range last frame, so it doesn't set the volume to zilch each time. Performance of audio server with all players out of range:
Seems to only make a measurable difference when overwhelmed with players, but maybe it's more noticeable on a slower CPU. |
Thanks! |
Fixes #96670
Although said in documentation, AudioStreamPlayer3D doesn't do the claimed optimization: avoiding audio mixing when further than
max_distance
from the AudioListener3D. So I did a seemingly simple change to the if statement for an early exit of its processing loop:Into this,
Without
set_playback_bus_volumes_linear()
, the sound keeps playing if you exit themax_distance
radius, and the audio server doesn't get the speed boost.Note: the playhead position will continue to be updated even if this is called.
This oversight looks like it is also the case in 3.x, so it should probably be updated too.