Tutorial #1 – Godot Audio Volume

I will keep my tutorials short. They usually cover only the basics. The simplest solution to a problem at hand. My intentions are not to guide how to make production ready code or design.

There are multiple ways of handling audio in your Godot project. I’m going to show some of the technics to make your life a bit easier.

Let’s start from the top. In Godot you can find an Audio tab at the bottom of the editor (see the image below). There is only one bus available by default called Master. Here I have added two extra buses. One for music and one for sound effects. You can choose which bus to use in your AudioStreamPlayer properties. This makes it easy to create global volume options for your project.

Audio Bus Settings in Godot

Let’s then take a look on how to actually use the buses in your project. First add a slider into your project (HSlider will do). Set the max value to 0 and the min value to -80. I don’t think the volume should be increased above the zero level as it tends add distortion. Also it seems that -80 is the minimum value for an audio bus. I’m not sure if those are the best settings for your project so please try to find values that suit you best. Then connect a signal from the slider value_changed to your script. It passes the slider value as a parameter. Then in the connected function you can set a bus volume like this:

func _on_MasterVolumeSlider_value_changed(value):
	AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), value)

What this does is it tells the AudioServer to set the bus volume to the value from the slider. The set_bus_volume_db -function takes bus index and our slider value as parameters. The bus index we can get by calling the get_bus_index -function with the bus name as a parameter.

And that’s it. If know a better and simpler way of handling audio volume, please let me know in the comments below. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: