godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.97k stars 20.18k forks source link

AudioServer.get_bus_peak_volume_left_db should return -INF when silent #37562

Closed robbertzzz closed 3 years ago

robbertzzz commented 4 years ago

Godot version: v3.2.1.stable.official

OS/device including version: Windows

Issue description: AudioServer.get_bus_peak_volume_left_db returns values below 0 when sound below peak volume is playing, as expected. However, when there is no sound coming through the bus, the volume output should be -INF, like in digital audio workstations. Instead, the value is 0, which means you can't know whether 0 means no sound or maximum levels.

Steps to reproduce: Create an audiobus. Don't send audio through it. Create a script and use it to print volume using AudioServer.get_bus_peak_volume_left_db in _process.

Minimal reproduction project: n/a

aaronfranke commented 4 years ago

I can't reproduce this bug exactly as you described it. In my testing, when no audio is playing, this method returns 0 only for the first frame, and -200 for every other frame. Unlike as you describe, the reported volume is not always 0 with no audio playing. (This is one of the reasons why we ask users to provide a minimal reproduction project - please don't just leave the field blank).

Anyway, one idea would be to make the default value -200 for consistency, but I have no idea if this is the right solution. If silence should indeed be negative infinity, I don't know where the existing -200 value comes from, but that would have to be changed too.

robbertzzz commented 4 years ago

I'm unfortunately too busy at the moment to create a reproduction project for this one. I didn't do much with audio in the project where I ran into this bug though, just added a separate bus to play my audio through and get the volume from to animate something on screen. I got a consistent output of 0 when no audio was playing.

Negative infinity is a thing because every other absolute value means some sound is still coming through. -200 dB is pretty extreme and should probably be virtually silent, but absolute silence only exists at negative infinity. See this image for an example inside a DAW: https://cdn-resources.ableton.com/80bA26cPQ1hEJDFjpUKntxfqdmG3ZykO/static/images/manual/en/ProSessionMixerSizes_opt.45353db30c9a.png (all channels quiet - no green bars, resulting in -Inf on the output meter).

Anyway, getting 0 on a single frame would likewise be a bug in my opinion...