godotengine / godot

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

AudioStreamPlayer's volume ignored on web when playing it with an AnimationPlayer's audio clips track. #95811

Open phantomdesvin opened 2 months ago

phantomdesvin commented 2 months ago

Tested versions

Reproducible with Godot 4.3 Stable. Web export. I'm assuming this happens because of the new (4.3) web audio sample system.

System information

Windows 10, Web export, Chrome, Godot4.3 Stable, wav format.

Issue description

AudioStreamPlayer's volume property is not applied, it doesn't affect the actual volume of the played audio when playing it using an AnimatioPlayer's animation that uses an audio clips track to play the audio. Only happens on web. Only when playing the audio using an audio clips track.

Steps to reproduce

In the minimal reproduction project I have two AudioStreamPlayers. Both can reproduce the same "footsteps.wav" audio, and both are set to -80 dB, so they should both emit no sound when played if they are applying the volume properly. However, when pressing the second button that plays an AnimationPlayer's animation that uses an audio clips track to reproduce the audio, the volume is ignored in the web so the audio can be heard at normal volume.

For reference, pressing the first button will play the audio using another AnimationPlayer's animation but with a track that enables the playing property of the AudioStreamPlayer. Doing it this way, or any other way other than using the audio clips track, volume (-80) is applied correctly so no sound can be heard.

Also, both apply the -80dB volume correctly when not in the web.

I don't see any workarround to make it work. Please inform me if you know one. Using the playing property track works but it doesn't let us use the clipping features of the audio clips track, and we would have to remake all the animations audio timing and edit some audios that need to be clipped in an external audio editing program.

Minimal reproduction project (MRP)

audio-volume-ignored-on-web.zip

akien-mga commented 2 months ago

CC @adamscott

phantomdesvin commented 2 months ago

Trying to work arround this, I discovered that while the Master audio bus volume affects the audio clips volume correctly, if I change the AudioStreamPlayer's Bus property to a different bus, changing this other bus volume does not affect the audio clips volume correctly. This again happens only on web.

adamscott commented 2 months ago

Trying to work arround this, I discovered that while the Master audio bus volume affects the audio clips volume correctly, if I change the AudioStreamPlayer's Bus property to a different bus, changing this other bus volume does not affect the audio clips volume correctly. This again happens only on web.

Can you create another issue?

Edit: I cannot reproduce this issue on web. Here's my MRP: web-bus-volume.zip

phantomdesvin commented 2 months ago

Trying to work arround this, I discovered that while the Master audio bus volume affects the audio clips volume correctly, if I change the AudioStreamPlayer's Bus property to a different bus, changing this other bus volume does not affect the audio clips volume correctly. This again happens only on web.

Can you create another issue?

Edit: I cannot reproduce this issue on web. Here's my MRP: web-bus-volume.zip

I was doing that. But checking the project I used to investigate the workarround, where I discovered the bus volume was not being applied, I saw this error in the debugger:

E 0:00:08:0415   audio_stream_player.gd:28 @ _on_button_3_pressed(): Index p_bus = -1 is out of bounds (buses.size() = 1).
  <C++ Source>   servers/audio_server.cpp:958 @ set_bus_volume_db()
  <Stack Trace>  audio_stream_player.gd:28 @ _on_button_3_pressed()

My function to lower the footsteps bus volume was not getting the correct bus index but I can't understand why. I made sure the bus name was written correctly using autocompletion and double checked the function, but I don't know what I am missing. The code was:

func _on_button_3_pressed() -> void:

    var bus_index = AudioServer.get_bus_index("footsteps")
    AudioServer.set_bus_volume_db(bus_index,-30.0)

I also checked that the AudioStreamPlayer had the bus property set to footsteps

At the end, I decided to delete the footsteps bus, I created a new Footsteps bus, and just changed that capital F in the function (actually using autocompletion again) and this time the function worked and changed the volume correctly, also on web.

So this was probably me making some mistake or maybe a strange bug with the buses system. I honestly don't know how I could be doing something incorrectly if all I was doing was asking the API to give me the index of a bus that was written using autocompletion and the index was not correct. But I'm a begginer so I wouldn't rule out me managing to mess it up somehow.

Sorry for the inconvenience and thank you for the quick response and bugfix. You guys are amazing.