You will be glad to know that we all survived a) the Gaslamp Games Christmas Party, and b) the Snowpocalypse in Vancouver, with only minor cases of frostbite and damage to clothing. However, this has made today’s blogpost a bit on the late side and we apologize. People have wanted to hear about this for awhile, so as a special treat – let’s look at Clockwork Empires’ dynamic music system.
The motivation for trying something different with Clockwork Empires and music stems from Dredmor. Dredmor had a great soundtrack, but we heard a lot of people comment that, after a certain point, there was only so much of the soundtrack that you wanted to hear in a game that has over a hundred hours of playtime. To fix this, we got inspired by a piece of technology that the Introversion guys developed for their cancelled spy-thriller, Subversion. Specifically, this video. The other inspiration was the Director from Left 4 Dead 2, which tracks player “mood” to adjust the flow of gameplay. Why not just build something that tracks the “mood” of the story, but simply uses it to change the music to suit your narrative? After all, we are a game that is all about narrative.
Clockwork Empires tracks six indicators internally. Ambience, Battling, Discovery, Producitivity, Tragedy and Insanity:
- Battling goes up when you’re fighting,
- Discovery goes up when you’re discovering things (exploring the map, doing research, SCIENCE, etc.),
- Productivity goes up when you are performing acts like industrial construction and goods production,
- Tragedy goes up when people die or are hurt, stuff is destroyed, and people are upset.
- Insanity goes up when… well, the madness spirals and all know the rule of the Invisible Geometers’ invisible fist-analogues.
- Ambience is just always on, but it can be pushed out by other tracks.
As somebody sussed out, internally this is just loading six (or however many) tracks of music from the disc and mixing them. Individually, Matthew Steele (who you may remember from Dungeons of Dredmor) creates six tracks for one “song”. In this case, these six tracks are little snippets of Chromium (All our musical tracks seem to be named after metals this time around, which is interesting.)
We put all the scoring information that is generated by the game, with weights to sort of make it work correctly, into a histogram. We let information that is older than a certain number of game ticks fall out of the histogram, and we put new information into it as it arrives. The result is that you don’t get harsh changes and transitions between new modes. Then, based on a set of rules (“don’t mix track P with D”, “if Insanity is over 50 start playing the insanity music”) that is customizable for each track, we get a dynamic mix that adapts to your gameplay. The magic, due to Ryan, is that we are able to efficiently load, decode, and mix a lot of streaming OGG files together very, very quickly. Mixing six tracks of music takes a little over 2% of the CPU available on my laptop, which is last year’s Macbook Pro. What you get might sound a bit like this:
although this is chopped together very rapidly to show you two different sorts of “musical textures” you might get; in the real game, everything has smoother and longer transitions.
For those interested in the specifics of music, Mr. Steele has been going back and forth on the question of “what is steampunk, anyway?” While building the game, we have been trying to allow for a variety of different instrumentation for different moods. Prepared piano, a la John Cage, shows up at various points, and various tracks are peppered with recordings made from the Mellotron, an old tape-based keyboard from the 60’s that you may remember from such hits as the Beatles’ “Strawberry Fields Forever”. It provides the distinctive Dredmor strings that you hear on tracks like “Diggle Hell is a Real Swingin’ Place”, and so far I believe it is mainly used for flutes and choir. Some other old synthesizers are used as well, such as the Polymoog (famous for its use by Gary Numan on his hit “Cars”) and the Hammond Novachord, an antique tube-based instrument from the early 30’s and the first true synthesizer ever invented. The whatever-the-heck-you-hear on the Insanity Tracks is created by a more modern instrument, the Poly Evolver by Dave Smith Instruments. And, on top of that, we have the usual assortment of strings, brass, kalimbas, woodblock, and cowbell.