> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XMA2 encoder tool

> XMA2 encoder tool

The XMA2 command-line encoder tool (XMA2Encode) converts a set of Pulse Code Modulation (PCM) files to XMA2 format or an XMA2 file to PCM format.

This tool can be used for both XBOX 360 and XBOX One. For XBOX 360, you can use the output of the tool without any changes. For XBOX One, the `seek` table might need to be byte swapped. The code to do this is in the [XBOX One format](#ID4E2DAC) section of this topic.

* [Using XMA2Encode](#ID4E1)
* [XBOX One format](#ID4E2DAC)
* [Writing your own XMA encoder tool](#ID4EPEAC)

<a id="ID4E1" />

## Using XMA2Encode

The following code and table describe how to use XMA2Encode.

| Column 1                                                                                                                                                                                                               |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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, XMA2Encode requires that the input files are either all single channel or all stereo with the last stream being mono or stereo, depending on the number of channels being encoded.<br /><br />**Note:** XMA2Encode supports audio files in PCM format or the XMA2 format (with `/DecodeToPCM`) only.                                                                                                                           |
| `/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 XMA2 file that was just created. The resulting PCM file has the same audio quality as the new XMA2 file. You can preview 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 is specified, the file doesn't loop, even if loop points are present.                                                                                                                                                                                                                                                                                                                                                                                        |
| `/UseLoopPoints`         | Uses existing loop points, if present; otherwise, it doesn't loop. `LoopWholeFile` and `UseLoopPoints` are mutually exclusive. If neither the `LoopWholeFile` nor the `UseLoopPoints` argument is specified, the file doesn't 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`, or `RB`, where `L` = Front left, `R` = Front right, `C` = Front center, `LFE` = Low frequency, `LS` = Left surround, `RS` = Right surround, `LB` = Left back, and `RB` = Right back.<br /><br />**Note:** If an input file doesn't have a channel mask, or if it has a channel mask with a number of bits set that doesn't match the file's channel count and no speaker assignments are specified with the `Speaker` option, the resulting XMA file has a channel mask of 0. |
| `/MeasureTime`           | Shows the time spent encoding.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `/Verbose`               | Enables verbose output.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `/Help`                  | Shows this usage information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

<a id="remarks" />

### Remarks

All options can be abbreviated to their first letters.

The following table lists the error codes that XMA2Encode can print to indicate problems with 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.                   |

<a id="ID4E2DAC" />

## XBOX One format

The output of XMA2Encode must 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.

```cpp theme={null}
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 functionality, and then perhaps write a separate tool to perform the swap so that no preprocessing is required of your app.

<a id="ID4EPEAC" />

## Writing your own XMA encoder tool

It's possible to write your own encoder tool by using the methods defined in *xmaencoder.h* and implemented in *xmaencoder.lib*. The *xmaencoder.h* file is located by default in the *C:\Program Files (x86)\Microsoft GDK\191100\GXDK\toolKit\include* folder. The *xmaencoder.lib* file is located by default in the *C:\Program Files (x86)\Microsoft GDK\191100\GXDK\toolKit\lib\amd64* folder.

The single method that's available in the header and library is [XAudio2XMAEncoder](/build/console-features/audio/tools/xma2encoder/methods/xaudio2xmaencoder-xmaencoder-xbox-microsoft-m).

Don't use the `XMA2InMemoryEncoder` and `XMAInMemoryEncoder` methods (legacy) that are defined in the header.

<a id="ID4EDFAC" />

## In this section

[XMA2 encoder reference](/build/console-features/audio/tools/xma2encoder/atoc-xmaencoder)
Describes the functions that are available in *xmaencoder.lib*.

<a id="ID4EJFAC" />

## See also

[XMA2 overview](/build/console-features/audio/overviews/xma2-overview)


## Related topics

- [Overview of XMA2](/build/console-features/audio/overviews/xma2-overview.md)
- [XAudio2XMAEncoder](/build/console-features/audio/tools/xma2encoder/methods/xaudio2xmaencoder-xmaencoder-xbox-microsoft-m.md)
- [XMA2 encoder library and command line tool](/build/console-features/audio/tools/xma2encoder/index.md)
- [XMA2 Encoder reference information](/build/console-features/audio/tools/xma2encoder/atoc-xmaencoder.md)
- [Tools](/build/console-features/audio/tools/index.md)
