0 votes

Is there a way to verify if a bus is playing something, I know that it is possible to do with AudioStreamPlayer, but I have many AudioPlayers playing in the master bus, so it would be easier and performance friendly.

Something hypothetically like this

AudioServer.is_playing(bus_idx: int)
in Engine by (15 points)

1 Answer

+1 vote
Best answer

You could use get_bus_peak_volume_left_db (or right, it's stereo): https://docs.godotengine.org/en/stable/classes/class_audioserver.html#class-audioserver-method-get-bus-peak-volume-left-db

# Volume of master bus on left ear (I don't know what the second parameter is for)
var vol = AudioServer.get_bus_peak_volume_left_db(0, 0)

The result is in relative decibels so it's going to be -200 when nothing plays, and fluctuating around -10 when stuff plays (depends how loud your sound is). This is affected by volume as well.

You might find that you need to refine this approach because "checking if sound is audible right now" could be different than what you expect as "stuff playing". For example if you play a rapid repetitive beat sound, the peaks will be zero between the beats, but stuff is actually playing, so it's a matter of time maybe.

by (28,735 points)
selected by

It works perfectly, the zero db between the beats is exactly what I was looking for. Thank you for your answer.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.