Is it possible to check if a bus is emitting sound?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Leonardo154

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)
:bust_in_silhouette: Reply From: Zylann

You could use get_bus_peak_volume_left_db (or right, it’s stereo): AudioServer — Godot Engine (stable) documentation in English

# 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.

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

Leonardo154 | 2020-04-29 02:28