XAudio2 should be the simplest approach, but XMA2 can be coded directly to the hardware by using the Audio Control Processor (ACP) commands.
Both xWMA and XMA2 have their origins in the codecs developed for Windows Media Audio (WMA) and both have been developed specifically for XBOX games. The subset of the available codecs and parameters used by XMA2 is smaller than the subset used by xWMA. While both xWMA and XMA2 were developed for XBOX, they’re not interchangeable: the headers for each file format differ, and the formats are incompatible with PC versions of Windows. The codecs used for XMA2 and xWMA are slightly different, too, so each will have its own artifacts from the compression system that’s used.
XMA2 encoding
Encode audio data to XMA2 by using the XMA2 encoder tool, supplied as part of the Microsoft Game Development Kit (GDK). XMA2 files are .wav files that have the XMA2WAVEFORMATEX format header and an additionalseek chunk within the Seek location table.
The XMA2 format is compatible with XBOX 360, and the Seek table is to be ULONG byte-swapped for XBOX One. If the input is a .wav file, the output can be used without alteration.
To byte-swap the Seek table, use the following lines of code.
SHAPE_XMA_INPUT_BUFFER_ALIGNMENT flag to help ensure that the blocks are aligned correctly.
XMA2 AXI bus error
A long-standing bug in the XMA hardware decoder (and in XBOX 360) requires that titles provide a workaround if they useAcpHal directly. XAudio2 already provides the workaround. However, until the XMA2 encoder tool is updated, make note of the following information.
When decoding XMA bit streams and using only a single XMA input buffer, you can trigger an AXI bus error if the last 64 bytes of the XMA buffer contain encoded data. An XMA bit stream rarely contains encoded data within the last 64 bytes. Nevertheless, this must be handled to prevent the AXI bus error. Until the XMA2 encoder tool is updated to ensure that no encoded files contain encoded data in the last 64 bytes of the bit stream, you can avoid this issue by using one of the following methods.
- Always use both XMA input buffers, and never set the pointer of either input buffer to an invalid value.
- Set the pointer of the unused input buffer to equal the pointer of the other input buffer, even though you won’t enable the other buffer. An example is as follows.
- While generating content, use an offline tool to scan your XMA files. If any one of the last 64 bytes of the encoded XMA bit stream is a value other than 0xFF, re-encode the file.
Reference API documentation
- APU (API contents)
- XMA2Defs (API contents)
- Structures
