Skip to content

Add volume_db to AudioStream #104908

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RoyBerardo
Copy link
Contributor

This adds a volume_db property to all AudioStreams. For wav, mp3, and ogg AudioStreams, this property is set during import.

All AudioStreams can have their volume_db property set during runtime.

Changing volume_db while audio plays should not result in clicks because the value is interpolated over the course of one buffer of audio frames.

This closes godotengine/godot-proposals#12133

@RoyBerardo RoyBerardo requested review from a team as code owners April 2, 2025 08:32
@RoyBerardo RoyBerardo changed the title Add "volume_db" to AudioStream Add volume_db to AudioStream Apr 2, 2025
@RoyBerardo RoyBerardo force-pushed the audio_stream_volume branch 2 times, most recently from 30f9775 to 11c237b Compare April 2, 2025 08:53
@AThousandShips AThousandShips added this to the 4.x milestone Apr 2, 2025
@RoyBerardo RoyBerardo marked this pull request as draft April 3, 2025 08:50
@RoyBerardo
Copy link
Contributor Author

Going to try to squeeze as much performance out of this as I can. Converting to draft for now.

@RoyBerardo RoyBerardo force-pushed the audio_stream_volume branch from 11c237b to 1277fed Compare April 4, 2025 08:51
@RoyBerardo RoyBerardo force-pushed the audio_stream_volume branch from 1277fed to 803ff51 Compare April 4, 2025 09:12
@RoyBerardo
Copy link
Contributor Author

Made some pretty big optimizations to this, thanks to some good suggestions from a friend. I did a test with a lot of AudioStreams all playing at once. It had 128 AudioStreamPlayer3Ds, all with AudioStreamSynchronized, each with lots of other simultaneously-playing streams. Each stream had its volume_db set to 0, so no volume adjustment was actually applied. Here are the (approximate) measurements of the audio thread from the project's profiler:

Godot without this PR: 2.1ms
This original PR: 2.79ms
This PR with these optimizations : 2.15ms

With optimizations, that's approximately a 2.4% increase from where Godot currently is, as opposed to a 32.9% increase with this PR's original code. I should mention that I don't feel these tests were the most accurate, but they definitely get the numbers in the ballpark.

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

Successfully merging this pull request may close these issues.

Add volume control to AudioStream
2 participants