Dynamic music in games, that is adapting to what’s happening on the screen, is something I’m very passionate about. Today I’m gonna explain to you how it works, what kind of challenges have I encountered while writing our music player, and what is currently impossible to do.
Before we start, I have to mention, the entire soundtrack of BAR has been uploaded to our official YouTube channel and collected in this playlist. https://www.youtube.com/playlist?list=PLuMFASJQTPeIvvNJyHcuSp_b_-j0a0pLQ
Allright so let’s start with what is currently NOT possible to do.
Sound engine of Recoil has very limited controls over sound streams. It’s impossible to control volume of 2 sound tracks independently, and it’s also impossible to start 2 sound streams exactly at the same time, so any kind of layering gets desynchronized. Besides that, the engine becomes quite unstable with 3 and more streams last time I’ve tried it.
Well. There really are only 3 callouts I can give to the engine:
I can also receive information of the currently played track - how much time has passed and how long the track is. So what have I decided to do with this limited toolset?
First of all I’ve divided our music into multiple playlists. Each playlist corresponds to different state of the game. Menu, Loading, Peace, WarLow, WarHigh, BossFight and GameOver. Each playlist is created, shuffled and saved when you start up the game. Yes, that’s right. We’re not playing tracks from the playlist at random, but instead it’s set up as shuffled sequential looped playlist. Benefit of this solution is that we’re maximizing the track variety within the match, only replaying tracks when it’s necessary, and since it’s shuffled, every match plays tracks in different order! Every playlist also remembers which track from it was played last, which is important, because they’re switching between each other depending on the situation.
Second, since i can manipulate volume of currently played tracks, we can use fade-ins and fade-outs! These are used when track is starting, ending or when we need to cut mid-way through it. The transitions and track starts never feel sharp which helps a lot with making the music flow nicely in the background and not be distracting.
Third, I’ve mentioned “cutting mid-way through”. Yes, when intensity of the battle changes quickly, we want the music to reflect that, so it does, at specific thresholds.
And lastly, there are “Silence Periods”. After each track that ended without interruption, which is a random amount of seconds between 30 and 120 - This gives some extra time that reduce repetition of music even further by playing less of it.
Menu music is the one i’m gonna talk about first. Menu music is split into 2 categories:
Intro themes are menu specific tracks that you cannot hear anywhere else in the game. Music player is set up to always play one of those when you start the game. Then you have fillers, which currently is music from Peace state. I’ve decided to include those to reduce repetition in menu. As it is now, the music player is switching between Intro and Filler playlists back and forth with every track play, so every 2nd track is an Intro track, and every 2nd track is a Filler track. Simple, right? There’s nothing complicated here.
When you press Start, it then plays one of the Loading tracks (of which there’s only one right now). There’s nothing special about this one, except the fact that if it doesn’t end before the match starts, it fades out. This also shows the first limitation I encountered. Menu music cannot be faded out into loading nicely. The moment you press start, the engine calls for a reset, which kills the music player and so, the music stops.
Peace, WarLow and WarHigh, but before we move on I should explain the term that i’m gonna be using quite a lot here.
WarMeter - A dynamic value determining how intense the battle on the field is. It’s calculated based on damage your and ally units recieve.
If your unit recieved 100 damage, WarMeter raises by a 100. Additionally, it’s cutting itself by 4% every second, so when there’s no combat, the value slowly cools down. ADDITIONALLY, if there’s no combat for 30 seconds, it resets itself and goes all the way to 0.
When music player has to pick playlist to play the next track from, it’s comparing current WarMeter value with two thresholds. For WarLow it’s a 1000, and for WarHigh it’s 40000. So if we need to play new track, and WarMeter is at 27824, it’s above WarLow threshold, but below WarHigh threshold, so it will play next track from WarLow playlist.
Additionally, there are interruption thresholds for turning Peace into WarLow (Half of WarHigh Threshold), WarLow into WarHigh (Double the WarHigh threshold), and both WarLow and WarHigh into Peace (Half of WarLow threshold), which are used to determine when mid-track interruptions should happen.
Then there are two more playlists, BossFight and GameOver, both of which are interrupting currently played track straight away. Boss fight music plays during… well… obviously, boss fight in RaptorDefense and ScavengerDefense gamemodes. And GameOver music plays when game over screen pops up.
All this good stuff can be expanded by you with your own music! The engine supports MP3 and OGG Vorbis files, and the game is setting up the entire folder structure for you on first run. Just open the launcher, click Open Install Directory, then go to Music/Custom, and feel free to fill all the category folders you see with your own music!
We also have place for music mods on our Discord, however we have strict policy to not upload copyrighted music without permissions there. https://discord.com/channels/549281623154229250/1129127537763692654
Audio settings in-game also give you a few options that allow you to turn off some features of the music player. You don’t like interruptions? You can turn them off! You don’t like that there’s silence time between tracks? You can turn that off as well! You can also toggle custom and original soundtracks separately so if you like to have your music installed but want to turn if off, for example, while livestreaming, or you want to turn off original soundtrack and play your own music only, you can do that with one toggle! By default it’s mixing original soundtrack and your custom music together.
Now that’s really it. Good luck and have fun on the battlefield, Damgam out!