-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
AudioServer.get_time_to_next_mix()
can return negative values
#49403
Comments
AudioServer.get_time_to_next_mix()
can return negative values
As far as i tested, you dont need to set the stream and call func _process(_delta):
print(AudioServer.get_time_to_next_mix()) |
But this still exists in 3.3.3. I will check what is the difference |
This comment has been minimized.
This comment has been minimized.
CC @godotengine/audio |
Does this cause problems in practice? That said, I can't figure out what the default implementation of this method is doing: godot/servers/audio_server.cpp Lines 87 to 95 in d187bb4
|
Took a look at this, and _last_mix_frames is a bit of a misnomer. It's the number of frames to mix, set by void AudioDriver::update_mix_time (and only used in this function). Dividing that by the mix rate will give the time, in seconds, for each mix buffer. So it's calculating how much time has passed since the last mix, converting that to seconds, and finding how long the mix buffer, in seconds is, and returning the difference between the two. The thing that's tricky here is that, since the mixing happens in a different thread, you could query the time to the next mix and get a negative value since enough time has passed to start a mix, but it hasn't started doing the mix on the audio thread yet. So if you play your sound, it might mix that frame, or it might be delayed 1 full mix. In fact, that has potential to happen even with values that are greater than 0. UNLESS, the audio mixing does not start until the end of the frame, in which case, the fix for this is to simply return 0 if the value is less than 0. All that being said, I'm trying to figure out how to actually use get_time_to_next_mix() in practice. For example, if I have some sounds I want to play exactly on a beat, knowing the time to the next mix could mean I could play them sooner, but they'd still be off. It's like I'd need a way to play a sound with a delay that happens within the mixing thread. This is probably not the place for this discussion, but I found this github issue when searching for a practical use for get_time_to_next_mix(), so if somebody knows how to apply it, maybe throw a link in here for wild internet wanderers like myself who might stumble upon this. |
Is this still reproducible in 4.0 RC 3 or later? |
Confirmed happening with latest mainline (synced within 24 hours). Printed the values in the _physics_process():
|
Confirmed on Ubuntu 20.04, driver PulseAudio. Could trigger it thrice in 16 attempts of running the scene of the MRP (after using the auto-upgrade). All negative values were always before Godot Engine v4.0.2.stable.official.7a0977ce2 - https://godotengine.org
|
reduz said about the return value of
|
Godot version:
3.3.2
OS/device including version:
Macbook Pro 2018 13 inch, Big Sur 11.3.1
Issue description:
AudioServer.get_time_to_next_mix() can return negative values. It seems that this happens if a relatively longer stream (eg 2 minutes long) was just set in the audio player.
Expectation: time to the next mix should always be non negative.
Steps to reproduce:
In the same call to _process, set the stream of an AudioStreamPlayer then print AudioServer.get_time_to_next_mix().
Minimal reproduction project:
AudioServerBug.zip
The text was updated successfully, but these errors were encountered: