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

Audio playback progress times are not updated in real time #71122

Open
Tracked by #76797
L2750558108 opened this issue Jan 9, 2023 · 11 comments · May be fixed by #81873
Open
Tracked by #76797

Audio playback progress times are not updated in real time #71122

L2750558108 opened this issue Jan 9, 2023 · 11 comments · May be fixed by #81873

Comments

@L2750558108
Copy link
Contributor

Godot version

3.5.1mono

System information

windows10

Issue description

Audio playback progress times are not updated in real time.They are updated only every two to three frames.This is prone to errors in timing and need to be fixed.

Steps to reproduce

Run my test project
Check the console
Each output is found to be repeated two to three times

Minimal reproduction project

(https://github.com/godotengine/godot/files/10375421/Audio.Time.Update.Test.zip)

@Lunarexxy
Copy link

Lunarexxy commented Jan 10, 2023

This is known and expected behavior. You can read more about it in the documentation, here: https://docs.godotengine.org/en/stable/tutorials/audio/sync_with_audio.html

I doubt there is a simple way to completely eliminate this. It's a side-effect of how audio streaming works in pretty much any modern engine. (And possibly other software as well; I'm not an audio expert.) You'll get similar results in engines like Unity and Game Maker, for example.

While it's kind of an annoying quirk of audio systems, it is not a bug, and you can work around it just fine. Examples of how to do this are also in the link above.

@L2750558108
Copy link
Contributor Author

L2750558108 commented Jan 10, 2023

The results I got in Gamemaker are different from what you said. The audio time is updated every frame. This is part of the output, the second number of every line is audio time
image
These are codes
image
image
Maybe Godot could improve on this in the same way as Gamemaker?

@Lunarexxy
Copy link

Lunarexxy commented Jan 10, 2023

Ah, fair enough! It certainly used to have the same quirk for playing audio, but it's been a while since I used GameMaker, so it's very possible they updated it to avoid that somehow.

It's also possible that the delay in updates doesn't happen in GM when sound resources use the non-streamed or compressed settings, but the trade-off there will be a much higher memory and/or CPU use, and much longer load times. I think "Uncompressed" is the default for sounds in GM, which could explain why you didn't see the same issue in your test.* (Edit: Welp, guess that wasn't the cause after all. Not sure why GameMaker behaves differently then...)

I believe Godot streams all its audio from disk. If you'd like the option to store it in memory for faster and more reliable playback in Godot, (assuming that's the solution) perhaps it's worth submitting a proposal.

*(I'm making a lot of guesses here, since I don't currently have a copy of GameMaker installed to test this for myself. Feel free to correct me if I'm wrong!)

@L2750558108
Copy link
Contributor Author

I tried all four compression methods, and also tried the audio obtained by audio_create_stream functions, none of them went wrong, and their time was updated in real time without exception
image

@L2750558108
Copy link
Contributor Author

So will it be fixed?

@AThousandShips
Copy link
Member

It depends on if it is considered a bug, or just how things work, I would recommend the suggestion above to make a proposal for audio being stored in memory to get around this, which would be more flexible. The current implementation is likely the way it is for a reason, that having the stream position update every frame might not be cheap to accomplish for all cases and the choice was made to make it more efficient and performance focused.

The Godot engine and the community is a volunteer effort, with people working on what they want and are able to, on their own schedule. While major bugs are focused on and we try to fix them as soon as possible there aren't any guarantees that this thing or that will be fixed in a timely manner. And you need to recognize and respect that.

@L2750558108
Copy link
Contributor Author

Sorry, I was just wondering if this is in the plan to be solved , without rushing to resolve it as soon as possible.

@AThousandShips
Copy link
Member

Thank you, I wanted to point this out given some comments I've seen from you, I'm sorry if this has been due to language barrier

@API-Beast
Copy link

API-Beast commented Feb 20, 2023

You can calculate the actual frame perfect audio playback progress by adding the time since the last mix (playback_position updates every mix)

func get_actual_playback_position():
  return get_playback_position() + AudioServer.get_time_since_last_mix() * pitch_scale

@ronyeh
Copy link
Contributor

ronyeh commented Mar 31, 2023

Does it hurt graphics performance a lot if we have Godot calculate audio progress on every frame, for higher precision? Or maybe it can be a setting in the editor, to improve the precision for audio apps/games? It would be cool if Godot engine allowed for more precise audio apps & games, even if it needs to be enabled via a checkbox in the settings. :-)

@Mickeon
Copy link
Contributor

Mickeon commented Sep 18, 2023

The following is a poorly educated suggestion because threads may come into play here.
The more accurate playback position could only be calculated when get_playback_position is called. @API-Beast 's workaround doesn't look particularly CPU-intensive to me. It could be included within AudioStreamPlayer. Users that don't... use the method would not be affected by this, and users that do would get more reliable results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants