Hello and welcome to another episode in the Godot Basics tutorial series. Keep in mind that Godot Tutorials is not affiliated with or sponsored by Godot Game Engine. In this episode, we will be taking a look at the audio server class and audio buses. But before we get into that, we must first understand audio signals and audio signal is a representation of sound. There are two different types of signals analog signals and digital signals.
Analog signals uses electrical voltage and digital signals are basically a series of binary numbers. Another terminology you should understand is signal flow. Signal flow is basically a path and audio signal takes from source to destination. In a sense, audio signals may pass through multiple devices before reaching its destination. This can also be referred to as audio mixing. Now audio mixing is the process by which multiple audio signals are combined into one or more channels and audio signals volume level frequencies and sound may be altered before reaching its destination.
Now an audio buzz is a signal path which can be used to combine individual audio signals together. On top of that, audio buses can be used to manipulate an individual or a group of audio signals. The main benefit of audio buses in terms of manipulating audio signals is that it allows for easier and consistent editing of similar audio signals.
This is important to note because Godot uses an audio bus when it comes to manipulating sound. Now, by default, Godot uses only the master bus in Godot. If you want to use your own custom setup, you will need to create your own audio bus layout resource. And this can be done through the audio tab, Ed, which we will be taking a look at later in this episode. Now, this is what a bus looks like in Godot.
As you can see here, we have our audio bus named Master. And by default, this is the only active bus in your game. And as you can see here, we're set to zero decibels and we have no effects. And our destination is the speakers of the user's device. Now, three important things to understand about the bus, especially when it comes to manually debugging sounds in Godot are the following buttons, the solo button, the mute button and the bypass button.
The solo button denoted by the S allows only the highlighted buses to send audio signal out. However, in order to hear the sounds when the solo button is active will require the audio signal to reach the master bus. So keep that in mind. The second button to understand is the mute button. And when the mute button is activated, mute all audio signals that go through the bus.
The last button we have is the bypass button. When the bypass button is active or audio effects are ignored, the bypass button is great. When you want to manually debug the original sounds of audio that go through the bus versus the audio signal with the added effects if you add effects onto your bus. Now, adding audio effects is quite simple down here. You can see we have the add effect drop down menu and it will list all the possible audio effects you may pick from.
And when you select something, it will appear in this box. And right now, as you can see, by default, our master bus does not have any audio effects. Now towards the bottom, we can choose our destination by default. The master buses destination is your speakers. However, when you add more buses, you will have the ability to choose its destination path. And basically only the master bus can reach the user's device, in this case the speakers. So any new audio buses you create must connect to another bus.
One thing to keep in mind is that buses are a little glitchy, so don't expect the safe shortcut to work. Sometimes, for example, if you add an effect or change in effect setting and you use the safe shortcut on your computer sometimes not all the time, but sometimes it will not save. So I recommend that you use the save as button and I will show you that later in this episode.
Also, another thing to keep in mind is that if you're not using code to load your bus settings, make sure that you check your project settings to see if you are using the correct audio bus layout resource file. One last thing I want to point out is that the order that your buses are in play in.
To row when determining the output of your audio signals. So, for example, your master bus will always be on the left side of your audio tab and it will always have the default name master and output to the user's audio device, in this case, its speakers.
Now, let's say I have another audio bus, in this case the bus. His name is bus one. As you can see here in the drop down by default, it's set to Mester. And when you click on it, the only choice you have is Mester, because it is the only bus to your left. And so bus one can only choose Mester. Now let's take bus two as another example. The buses to the left of bus to our bus one a.m. And so therefore, when you choose the audio signal output, you can choose either master or bus one. Now, bus three has bus two to the left, bus one a.m.
And so therefore, if you were to click the drop down menu, it's hidden behind this pop up. You'll see we have three choices. Mester, bus one, bus two and so on.
Choosing an audio signal output on your bus. You can only choose buses that are to the left of your selected bus.
Now let's take a look at the audio server Singleton class, the audio server. Singleton is a server interface for low level audio access. It basically allows you to customize buses through code. One thing to keep in mind is that the audio server class inherits from the object class. One thing to keep in mind is that the audio server Singleton uses the default bus setting unless otherwise specified. Now to change your audio by setting, you have the set bus layout method provided to you by the audio server Singleton.
It takes in one argument, which is the audio bus layout data type, and that is just basically your audio bus layout resource file. And we'll take a look at that in code later in this episode. Now, keep in mind that customized bus settings will not work unless manually added. And that's because the audio server Singleton by default, uses whatever is set in your project setting. And what is set in your project setting is the default file you're given to useful methods. The first is you can manually add a bus through the bus method.
It takes in an optional argument. Basically you are pending to an array and the second method is the adverse effect method. It takes in to mandatory arguments, the third being optional. The first argument must be a bus index and the second argument must be an audio effect data type. There are a lot of other methods that the audio server Singleton provides you, but in this episode we will just focus on these three and I will provide you a link to the Godot engine documentation if you would like to dig more into the audio server.
Singleton here we are inside Godot. Now, if you go towards the bottom, you're going to see Tab's. You want to click on the audio tab and voila, as you can see here, we have our audio buses that our Godot game engine will be using decibels set to zero and no effects on top of that. Your bus is called Mester. This value cannot be changed. And towards the bottom, we have our output, which is to speakers. Now, towards the top, you can see layout followed by the name of your audio bus layout.
And by default it will be called default bus layout. And it is a resource file towards the left. You can see that there are no resource files here, but when we start editing, you'll see one automatically created for you and it will be named whatever it is that you named it in the layout. Now, when we go to the project tab. And click project settings are pop up will appear. Head down to audio and as you can see here, we have defocus layout and by default it is pointing to the default bus layout resource file.
Now, over here we have other options. We can add a bus load, save us, load our default and create in this case. Let's go ahead and add a bus now as we created our new bus notice here on our filesystems tab that an audio bus now resource file was automatically created for us. Now, let me show you a problem that may happen, especially if you're starting out now. Let's say you delete this file. And you go ahead and press remove. Well, what happens is if you go back to your project settings, go back to your audio tab, you'll see default bus layout.
The file has now been deleted. And so if we were to edit our layout, we would not see the changes reflected when running our game. And that's because our game will revert to the default bus layout if we aren't using code. And in this case, we are not using code. And so therefore what the video game engine does is it reverts back to the default settings, which is the master bus, zero decibels and no effects. So just keep that in mind. If your audio effects aren't working, you may want to check project settings and see if it is empty.
And if it is, you just click this button here, refresh or excuse me, reset and it will reset the value back to the default layout resource file. And that's basically it. As you can see here, I went ahead and created three different buses.
The first is called distortion. The second is called background music, and the third is called sound effects. Beneath the name of your buses, you'll see the three buttons solo, mute and bypass. And over here you can see we have additional options for buses. They include duplicate, delete and reset value. Now, you may be wondering why exactly do you need to create multiple buses for audio? And in many, many cases, you probably don't want to or don't even need to create additional buses outside the default layout.
However, if your game comes with more audio, you may want to look into creating additional buses for different audio signals you have in your game. For example, you may have multiple background music for your game and multiple sound effects, and perhaps you would like your background music to be really, really loud and your sound effects to be really, really soft. So that way, different sounds don't clash or vice versa. You may want your background music to be a little layered on the ears and your sound effects to stand out more compared to the other noises or audio in your game.
On top of that, there may be times where you'd like to add effects on two different audio signals. And that's why we have this bus called distortion, because at some point in our game we would like to distort the noises of our audio. Perhaps it's just a special level the player has to go through.
Moving on, I'm going to add an effect on distortion with the distortion button. And we are playing the audio effect called distortion, and by default it is checkmark. And so it will be active and all audio signals that go through distortion will go to Mr. and Mester will come out to the speakers. So let's go ahead and see what happens to our audio. I'm going to leave the distortion checkmark. True. And so if we press the button, you'll realize that.
The music didn't distort, and that's because over here in our audio stream node, if we come to the right in our inspector tab, you'll see here in the bus setting that we're routed to master. And so our audio will not change and sound. We need to root it to one of the two buses that route into distortion in order to apply our distortion effect. And so I'm going to come here. I'm going to pick background music now. I can go ahead and press the play button up here, but I'm not going to I'm going to press the checkmark button down here next to playing.
And that allows us to play our music without having to enter the scene through the play button.
So I'm going to reduce the music and show you what's happening in our audio tab, you're going to see that music is being routed into our background music bus. It is then being routed toward distortion, thus therefore distorting the music a little bit and finally being rooted into mester, which outputs to our device. And on top of that, because we edit it here, you could see in the file systems that by default it automatically creates a new bass layout resource file. So I'm going to add our audio gdscript gd file onto audio stream player.
Now, on top of adding the gd file, I'm also going to delete what we've created, but don't worry, I'm going to redo these buses and upload them to get up after the episode is finished. Now, if we take a look at our code, you can see I've created three constant values, one, to hold the string value of our path into our bus layout file and have a constant value for our master index. By default, master index will be zero. On top of that, I have a constant value for the bus name. In this case, it will be mester.
So as you can see here in our already virtual method, we use the audio server Singleton. And just keep in mind that when we have singletons, we do not need to load it into a variable using the new method. And on top of that, we're using the set bus layout method and we are loading our bus layout, which is the default bus layout, resourceful. Now, again, index zero is for mester. And so in this case, if we want to add effects such as Kooris and distortion, we must pass into arguments. The first is the bus in which we want to add an effect to and because we want to add the effect to the master bus, that will be the zero value.
And then the second argument is your audio effect. In this case, we are going to use the audio effect course. Don't forget the new because that is a class and therefore needs to be instantiated. And we're also adding another effect in this case, our distortion. And lastly, a half print statement so you can see in the console the value of our mester, how many buses we have. And on top of that, how many bus effects are on masters? Well, that's all I have for you in this episode. Thank you so much for joining me. Thank you for clicking the like button.
And thank you for clicking the subscribe button. I'm going to upload the example in this episode onto GitHub, so please feel free to download that and play around with audio buses and audio effects, either manually or through the audio tab. I look forward to seeing you in the next episode. Have an amazing day.