Tuesday, November 20, 2018

Changing background music smoothly


I've got five sounds now for a game I'm working on currently. In the game, you can fight against other civilizations in big battles, but you can also settle on planets in peace.


Some of the songs are more violent, while others are quite peaceful. The question is: what is the best practice for changing between the songs. Is it better if I just look "is it peaceful or not" when the old song ends and then play a new one or should I do that every single frame and change the songs immediately.


The first alternative would sometimes play silent songs in battles (because the song started before the battle and isn't finished yet) and the second one would switch between to different-fast songs properly at the wrong moments so the player would hear a cut.


So I'd like to know what is more natural for the player or if there is a different possibility.


PS: The songs are between 300 and 500 seconds long.



Answer



There are actually some fairly standard approaches for designing music playback in a game. When designing a music playback system, problems you face involve creating smooth transitions, ensuring there is enough variety, and creating a sense of interactivity with the music. Your question title, "changing background music smoothly" tells me your main concern is transitions so that's what I'll primarily be addressing for each method.


Method 1: Layers and Stems


One approach for creating smooth music playback systems in games, what Patrick Hughes called the "AAA way", is to build your music up in layers (also sometimes called stems) such that there's no single definitive version of the track. Instead, you might have a single base track running consistently, with melodic, rhythmic, harmonic variations that get played over it.



You usually (credit again to Patrick Hughes) build these around common motif that runs through each element layer in a piece of music, or even througout all music in the game. A good example of a non-melodic motif is Martin O'Donnell's use of the Phrygian scale in Halo games (http://www.1up.com/features/music-halo-reach). Normally, each of these component music tracks are aligned to be playing in sync on a timeline with each other. Although it is possible to create music layers that do not necessarily depend on a consistent tempo and synchronized timeline, or can work well in multiple tempo and timeline contexts.


Because each layer is designed to work together, it's entirely possible to have a single layered music track that just plays throughout the entire game, making slight transitions between layers within itself to signify game state changes.


Method 2: Branching


You say you have music tracks already produced, so this implies you've already got a specific direction in mind: branching music. With branching music, your primary concern is the transition between music tracks that have been specified to play at particular sections of the game. You can achieve variety by breaking your individual music segments down into loops that have a couple of different versions, so that the same version never plays twice in two iterations and doesn't always start out the same way.


One way to handle transitions in simple branching music is to write more music that purely acts as a transition from these existing music tracks to others. Even if it's not feasible to cover every possible music transition, you can also use the "connector tracks" to make a music track end early in the case where you're trying to avoid simple fade-in, fade-out music changes.


Method 3: CCC-Combo


It's also important to note that the two major approaches discussed here (layers and branching are what they're typically called) can coexist conceptually. "Branching" is such a simple term and description of what's happening that you could very well be branching between layered music systems. This often requires a semi sophisticated playback system, so you have to balance what's worth your time to implement.


Method 4: Pragmatism and Simpler Music Playback


And, of course, you could always just fade-in and fade-out your music as needed. No shame if that's what feels right, or it's not feasible to write connector tracks. Better this than hard cuts to completely unrelated piece of music--that would sound pretty awful.


I'd also like to address your "silent songs" idea. It's not bad, but what happens when you start playing one 300-second track for 5 seconds, then you get immediately into a state where you need to transition to another track? Waiting for the remaining 295 seconds to go by seems impractical if you really care about making that music transition.



However, if the music is purely background music, and its fundamental purpose is to provide to simply set an overall mood, then "simple background music list" is a perfectly legitimate way to think about it. At this point you are talking about a music playlist like you'd build in iTunes or Windows Media Player (is that still at thing?) so you should implement it with that in mind.


Further reading


To learn more about standard approaches for designing music playback in games, you should take a look at learning materials for two of the largest interactive audio middleware tools that see common use in the industry, FMOD and Wwise.


Wwise has good reference material on this page. The "Making Interactive Music for Games" article is especially good as it goes into further depth about the information I've written here. The FMODTV Youtube Channel has videos with Stephan Schutze that cover FMOD Studio as a whole--including the parts of it that can be used to design music playback systems. Learning how these tools approach this problem can help you think about how to address your own game's needs.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...