-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 audio pops when playing an AudioStreamPlaybackResampled after calling AudioStreamPlayer[2D/3D]::set_stream() #38216
Conversation
04d91b4
to
8fe0d31
Compare
Can confirm this fixes the issue. |
My issue was merged into this, but might be different. With this commit, I still get some subtle clicking sound when an audio player is restarted. Sounds sort of like a rewinding effect for a fraction of second. Here is my minimal project. If you click around rapidly, some of the 2D audio will replay, and periodically have a clicking sound. Not sure if it is what you'd call a pop. |
can this be merged in 3.2 ? |
I need @reduz to review the changes. |
This noticeably fixes pops I'm experiencing when playing OGG streams in 3.2. Any word on that review? |
I've been having similar issues when using OGG files but for me it's been occurring when using a regular AudioStreamPlayer (not specifically the 2D or 3D one). I'm not overly familiar with the source code, but I noticed the changes here were only for AudioStreamPlayer2D and AudioStreamPlayer3D respectively. I'm curious if the same fix would need to be applied to the regular AudioStreamPlayer too. godot/scene/audio/audio_stream_player.cpp Line 252 in 18fc857
|
@CristCorsac No, the regular AudioStreamPlayer doesn't interact with physics, so it would just end up never playing if this fix were applied... Have you checked if it's specifically related to calling |
See https://github.com/Waridley/godot/blob/8fe0d31b925238289f2036114edf727a76132795/scene/2d/audio_stream_player_2d.cpp#L255 where active is set to true near the end of |
Sorry, I'm struggling to recreate an accurate minimal reproduction project as the bug seemingly occurs at totally random intervals. Sometimes not occurring for 5 minutes then suddenly cropping up. In my setup I have a separate AudioStreamPlayer for each sound effect and I simply call play() on them when needed. The AudioStreamPlayer nodes are all instanced onto the main scene. In my experience the bug seems to be much more likely to occur after a scene change has been made through code. As others mentioned in the issues posted in the initial comment here, this does not occur for WAV files and converting all my sound files to WAV fixed the issue for me. |
Yeah, that seems to be the pattern with audio issues in Godot 😆 They're always intermittent. Hence why it took me like 2-3 weeks of staring at the code to find this issue where I expected it to be all along. |
When are you calling EDIT: Now I see you said you aren't changing the streams, only calling |
I was using _physics_process() to call the .play() commands with the streams being set via the editor. What I find strange is that the audio popping glitch seems to occur significantly more often when the scene that contains the AudioStreamPlayer nodes is loaded via a get_tree().change_scene() call. If the scene is the initial scene to load (set by application/run/main_scene in project settings) the audio glitch seems to occur a lot less often. In fact, as of right now, I can't even get the audio glitch to occur until the scene has been changed by a get_tree().change_scene() call, even if it's just reloading the current scene. This is just speculation as I'm not familiar with the source code but could it be that changing the scene causes the problem to come to light? |
8fe0d31
to
fda7066
Compare
Fixes pops after calling `set_stream()`
This is probably superseded by #46151 |
Indeed. Closing as superseded by #46151. Thanks for the contribution! |
AudioStreamPlayer2D
andAudioStreamPlayer3D
usesetplay
to communicate with the physics thread instead of settingsetseek
directly, but they were settingactive
in theplay()
function, which, depending on thread scheduling, could cause the audio thread to see the player as active, and try to read data without callingstream_playback->start()
. This only surfaced for subclasses ofAudioStreamPlaybackResampled
(such asAudioStreamPlaybackOGGVorbis
) because they use an internal buffer which starts uninitialized, while other stream types read the data directly.This fixes the other serious popping issue mentioned by Jitspoe in #22016, but does not address either the "calling stop() on a looping sound" issue (which he says he worked around anyway), or calling
set_stream()
while a sound is still playing (which is obviously kind of a bad idea anyway, but was fixed forAudioStreamPlayer
as mentioned in #25087 and #30827).