XMA2 Encoder Tool

The XMA2 command-line encoder converts a set of PCM files to XMA2 format, or an XMA2 file to PCM format.

This tool can be used both for Xbox 360 and Xbox One. For Xbox 360 the output of the tool can be used without any changes. For Xbox One the seek table might need to be byte swapped; code to do this is shown in the Xbox One Format section.

Using XMA2Encode

XMA2Encode file [/TargetFile xmafile][/PCMOutputFile pcmfile][/DecodeToPCM pcmfile][/BlockSize][/Quality value][/FilterHighFrequencies][/LoopWholeFile][/UseLoopPoints][/Speaker pos][/MeasureTime][/Verbose][/Help]
Option Description
file Specifies the file name of the file to convert. You can specify multiple file/speaker position pairs: XMA2ENCODE pcmfile [/Speaker pos ...] [pcmfile [/Speaker pos ...] ...] [options] When you encode multiple files, the XMA2Encode tool requires that the input files either be all single channel, or all stereo with the last stream being mono or stereo depending on the number of channels being encoded.
Note
The XMA2 Command-Line Encoder only supports audio files in PCM format or the XMA2 format (with /DecodeToPCM).
/TargetFile xmafile Encodes to <xmafile> (only one target file is allowed).
/PCMOutputFile pcmfile Decodes the generated XMA2 file back to <pcmfile>. When you use this option, the tool generates two output files, an XMA2 encoded audio file and a PCM file, which is the result of decoding the just created XMA2 file. The resulting PCM file will have the same audio quality as the new XMA2 file. It allows for previewing of the XMA2 file's quality on Windows.
/DecodeToPCM pcmfile Decodes an existing XMA2 file to <pcmfile>.
/BlockSize Specifies the XMA2 compression block size to use (2 KB to 8,190 KB). The default block size is 64 KB.
/Quality value Specifies the XMA2 compression quality level to use (1 to 100). The default value for quality is 60.
/FilterHighFrequencies Filters out high frequencies in the source file.
/LoopWholeFile Loops the entire file, even if loop points are already present. LoopWholeFile and UseLoopPoints are mutually exclusive. If neither the LoopWholeFile nor the UseLoopPoints argument has been specified, the file will not loop even if loop points are present.
/UseLoopPoints Uses existing loop points, if present; otherwise, don't loop. LoopWholeFile and UseLoopPoints are mutually exclusive. If neither the LoopWholeFile nor the UseLoopPoints argument has been specified, the file will not loop even if loop points are present.
/Speaker pos Specifies the speaker assignment for a channel of the source file. This option must immediately follow the file name. <pos> can be [L | R | C | LFE | LS | RS | LB | RB], where: L = Front left R = Front right C = Front center LFE = Low frequency LS = Left surround RS = Right surround LB = Left back RB = Right back
Note
If an input file does not have a channel mask, or if it has a channel mask with a number of bits set that does not match the file's channel count and no speaker assignments are specified with the Speaker option, the resulting XMA file will have a channel mask of 0.
/MeasureTime Shows the time spent encoding.
/Verbose Enables verbose output.
/Help Shows this usage information.

Remarks

All options can be abbreviated to their first letters.

The following table lists error codes XMA2 Command-Line Encoder may print out to indicate problems encoding.

Error Code Description
0x88890001 The specified loop points are invalid.
0x88890002 The specified format is invalid.
0x88890003 A parameter is out of range.
0x88890004 A read operation failed.
0x88890005 There was an invalid XMA frame.
0x88890006 There was an incomplete XMA frame.
0x88890007 The stuffing bit was zero.
0x88890008 A data fetch failed.

Xbox One Format

Output of this tool needs to be ULONG byte-swapped for Xbox One. If the input is a WAVE file the output can be used without alteration.

To byte-swap the seek table use the following lines of code.

for(UINT32 i = 0;(i < xmaformat->BlockCount);i++)
    {
       rgpXMASeekTable[i] = _byteswap_ulong(rgpXMASeekTable[i]);
    }  

Consider adding the lines of code to your app to test the funcionality, then perhaps writing a separate tool to perform the swap so no pre-processing is required of your app.

Writing your own XMA encoder tool

It is possible to write your own coding tool using the methods defined in xmaencoder.h and implemented in xmaencoder.lib. The xmaencoder.h file is locatd by default in the C:\Program Files (x86)\Microsoft Durango XDK\PC\include folder, and the xmaencoder.lib file is located by default in the C:\Program Files (x86)\Microsoft Durango XDK\PC\lib\amd64 folder.

The single method available in the header and library is XAudio2XMAEncoder.

The XMA2InMemoryEncoder and XMAInMemoryEncoder methods defined in the header are legacy and should not be used.

In this section

XMA2 Encoder Reference
Describes the functions available in xmaencoder.lib.

See also

XMA2 Overview