Making a Xenoblade Chronicles Wave Bank for Terraria 1.4.1

 

Update: The music pack is now available from the Steam Workshop.

Recently, curiosity and nostalgia got the better of me, and I wanted to see if I could create a wave bank for Terraria using music from the definitive edition of Xenoblade (that is to say, a file that overrides the in-game music).

Fortunately, this is something that many people have done already, and there even exists a tool for passing in a list of .wav files, that generates a wave bank file to .wxb output.

Here is my attempt, available for download should you be interested. It features music primarily from the Xenoblade Chronicles Definitive Edition sound track, with some guest tracks from 2 and X.

 

Xenoblade Chronicles Wave Bank.zip

Installation instructions, tracklist and more are in the README.txt.


However, when going to make my own version, I stumbled across a few interesting problems... read on if you wish.

Creating the Wave Bank

Using Audacity, I identified loop points in the tracks and set a crossfade to allow for a single seamless track when looped. Once compiled, I tested the music in game and found that there was small audio gap whenever the track reached the end of the file.

At first I thought this was an issue with the way the files were saved as I believed the original Terraria music tracks looped seamlessly. So I re-installed the vanilla wave bank and listened to a few tracks and... lo and behold - Terraria's music tracks also feature the small gap before looping!

Confusing to be sure! The tracks I had mixed featured no such gaps, and were saved as lossless wav files. However, it was upon comparison to the original tracks that I began to discover what the real issue was. All of the extracted tracks from the Terraria wave bank had a small amount of silence at the start.

Top row: Original .wav file
Bottom row: Compressed audio file with 46ms artifact

This is a common artifact that stems from the compression algorithm used when saving files in a lossy format, such as mp3. In short, these compressed audio files had ~50ms of silence at the start of the track. What made no sense was how my wav files, and indeed Terraria's own music, were being affected by this. The next step was to examine how the files were transformed into the wave bank.

Looking into Quick Wave Bank, I noticed that the build process used the executable "XactBld3". A little research yielded that it is responsible for building wave banks for XNA - and it does this by converting the provided audio files from .wav to .wma. Like mp3, wmas are often lossy*, which introduces the compression artifact once more. Oh no.

It seems that regardless of the way the music is saved, the compiler will compress and introduce an artifact into the tracks. No getting around that. Of course, the sensible thing to do at this point would be to admit defeat, and just accept that there would be a small delay whenever the track loops. 

...you can see where this is going.

Working with silence

As anyone who listens to music knows, a slight gap in a piece of music can really throw you off the beat, arguably the most essential part of background music. In all of my wisdom I made the executive decision to revisit every track (about 60) and reduce the lengths of each of them by 50ms, carefully selecting where the loop point would be.

To do this, I would locate where in the loop a track's volume lowers the most and carefully cut out 50ms of audio, adding a small amount of fading either side of the track to make it as nautral sounding as possible.

After listening a few times to verify that the moment's silence was barely noticeable, I recompiled all the tracks and rebuilt the wave bank. In doing so, all the files would need to be compressed and stored in the wma file format. This meant that I could preview exactly how it the track would sound in game, and lo and behold...

It the preserves the beat of the song! Mission accomplished, or close enough.

Messing around in Audacity and mixing together these sounds has helped me develop an eye for spotting patterns in wave forms. This has been especially useful for creating instruments from audio samples. I even recently created a sound font comprised entirely of goose honks! But that's a story for another time...