Rebuilding XACT files for FNA/Monogame

When trying to use the original XACT files for an XNA project, sometimes they just won't work. Now why is this? Generally, I've seen that the issue is that the files are big-endian instead of little-endian.

How do you know if a file is big-endian or little-endian? Open them in a text editor. Wave banks start with "WBND", sound banks start with "SDBK", and settings files start with "XGSF". If any of these strings are reversed, then your file is big-endian.

An Introduction to XACT

XACT is an audio framework used by the DirectX SDK and many XNA projects. There are a variety of different file types for this.

  • Project Files (XAP)
    These are used by the XACT editing utility to pull up the resources of an individual project and their various links and settings.
  • Wave Banks (XWB)
    A collection of waves.
  • Sound Banks (XSB)
    A collection of sounds (waves with properties like volume and pitch) and cues (triggers for one or more sounds).
  • Global Settings (XGS)
    Sets the rules and settings for sounds. Includes categories (groups a set of sounds so they have the same settings), variables (the programmer can reference these in their code to control sound parameters at runtime), DSP presets (for effects like reverb), and compression presets (which can be applied to waves or wave banks).

Building an XACT project creates the XWB, XSB, and XGS files for that project for whatever platform you specified (Windows is little-endian, Xbox 360 is big-endian). Please note that you cannot load these files back into the XACT editor. You will need to have the original XAP project file.

This is where the issue is. When extracting these files from an XNA project, you usually don't have the XAP that enables easy editing. Which means we have to make it ourselves.

How to Tear Apart XACT Files

Wave banks are the easiest to start with. These are just collections of raw wave data that we need to separate out into the individual files. There is a utility for this called unxwb.

Once you have the individual files, you may notice that they aren't named. We'll come back to that later. They may also not play in VLC or Windows Media Player. This is a format problem that's solved by opening the files in Audacity and exporting them as WAV files.

Sound banks require digging into the file to find certain values. Thankfully someone wrote a file specification on this. Note the plain text cue names at the end of the file. It's incredibly common to have a cue for each wave file and to name them after that file. Basically, these are your wave names.

For global settings files, category and variable names are written in plain text.


Putting Them Back Together

You will need the XACT editor for this. Here's a guide on one of the ways to get it. You can also download it as standalone here.

  • Open the editor and create a new project. It doesn't matter what you name this.
  • Create a wave bank under "Wave Banks" and name it after your original one. Put all of your WAV files in here.
  • Add a sound bank under "Sound Banks" and name this after your original one too. Drag all of your wave bank files here to create sounds. 
  • To make a cue, right click and select "New Cue". You can add sounds to a cue by dragging them to that cue. If you click on the cue itself, you will see a panel with all of the sound names and their play probability. If you have multiple sounds here, you can move them around to change the play order. On the far left, there is another panel that contains playlist settings so you can have it shuffle or play in order.
  • To change the category of a sound, drag it to the relevant category in the main left side panel.
  • To edit variables, double click on the variable to open a window that has settings for intial value, min, max, and visibility. Other XACT settings such as DSP and compression presets are accessible in the side panel.
  • Go to "View" at the top and select your platform from the dropdown menu. For example, clicking "View Windows Properties" will build it for Windows. Then go to "File > Build" to actually build it.

Output files will be located in the same directory as the project. Replace your existing XACT files with these new ones.

No comments:

Post a Comment