Music/sound is very important in a video game. It adds a ton of immersion and having awesome background tracks to go with each and every moment in a game can make the experience so refreshing.
Tonight I finished an implementation of the audio engine for the game! I had a discussion with my composer over what techniques we could implement to make the music/sound in the game more dynamic and as it turns out, with a couple of tracks muted/unmuted you get a completely different experience in any song!
This led us to use a simple technique where we load up multiple channels into the game at once and define what the volumes at various times should be. This will give the effective result of hearing different tracks at different moments in a game without having to add any extra technical strain or complex features to the game!
Take one of our early tracks here:
If we split up our track into lows and highs, we have effectively separated the bass track from the main melody and all the accompaniments.
Now let's spin up a configuration system that allows us to define the volumes of the two tracks at various points in a game. I'll make a few in-game events we can respond to. Default Volume
, LowHealth
, InCombat
, Underwater
. A few likely scenarios we can expect to put the player into.
Now onto the configuration:
BGM
{
Default Fade Time = 1.0
#Song title followed by filenames for individual parts
foresty1_1
{
Track Name = Foresty
# High
channel[0]=foresty1_1_1.mp3
# Low
channel[1]=foresty1_1_2.mp3
# Underwater High
channel[2]=foresty1_1_alt1.mp3
# Underwater Low
channel[3]=foresty1_1_alt2.mp3
Default Volume = 70%,50%,0%,0%
# Transition time between one phase to the next.
Fade Time = 2.0
Events
{
LowHealth = 50%,100%,20%,20%
InCombat = 90%,100%,0%,0%
Underwater = 0%,0%,100%,100%
}
}
foresty0
{
Track Name = Foresty Preview
channel[0]=foresty0.mp3
channel[1]=foresty0_alt.mp3
Default Volume = 70%,0%
# Transition time between one phase to the next.
Fade Time = 2.0
Events
{
LowHealth = 50%,20%
InCombat = 100%,0%
Underwater = 0%,100%
}
}
}
I've thrown in an underwater version of each track as well. In foresty0
, we can see I have just a normal version of the track and an underwater version of the track. However in foresty1_1
, we can see that I've taken the low and high pass filter versions of my track and added them as separate channels on top of the underwater versions. Now to put it all together with some code and a parser for these and we can run some code like
if(game->GetKey(F1).bPressed){
Audio::PlayBGM("foresty1_1");
}else
if(game->GetKey(F2).bPressed){
Audio::PlayBGM("foresty0");
}
if(game->GetKey(K2).bPressed){
Audio::SetAudioEvent("Default Volume");
}
if(game->GetKey(K3).bPressed){
Audio::SetAudioEvent("LowHealth");
}
if(game->GetKey(K4).bPressed){
Audio::SetAudioEvent("InCombat");
}
if(game->GetKey(K5).bPressed){
Audio::SetAudioEvent("Underwater");
}
and we can hear different events! Here's a sneak peak of it in action!
While at first it sounds like you are hearing one track, you are actually hearing 4 tracks being played simultaneously! Their volumes are just adjusted to fit the ebb and flow of what's going on in-game!
We will be using this system to great effect to give the user some great immersion while fighting and exploring the lands of Lestoria! Thanks for reading!