XA

Maxis XA (named after CD-ROM Extended Architecture) is a variant of the EA ADPCM lossy audio compression format. Maxis XA is used by all Maxis games from Sim City 3000 onwards.

Francois Revol is credited for reverse engineering the original EA ADPCM audio format. Dmitry Kirnocenskij is credited for reverse engineering Maxis XA.

All content on this page is public domain. A complete working Maxis XA file reading implementation can be found in the FileHandler interface of Niotso under the ISC license.

XA file header

 * szID - A null-terminated string identifier, which may be equal to "XAI" (sound, speech) or "XAJ" (music) or "XA" (untagged) ("XAS" appeared in Command & Conquer 3)
 * dwOutSize - The decompressed size of the audio stream
 * wFormatTag - The decoded audio format; set to WAVE_FORMAT_PCM (0x0001)
 * nChannels - Number of channels in the decoded audio data
 * nSamplesPerSec - Sampling rate used in the decoded audio data
 * nAvgBytesPerSec - Bytes per second consumed by the decoded audio data; equal to nChannels*nSamplesPerSec*wBitsPerSample/8 or nSamplesPerSec*nBlockAlign
 * nBlockAlign - The number of bytes consumed by an audio frame (one sample for each channel) in the decoded audio data; equal to nChannels*wBitsPerSample/8
 * wBitsPerSample - The bits per sample for one audio channel in the decoded audio data; 8-, 16-, or 24-bit, etc.

Note that the part of the header from wFormatTag below is a Microsoft WAVEFORMATEX structure, albeit without the cbSize parameter.

szID is just a hint. XAI is stored stereo signed 16-bit 22,050Hz. XAJ is stored mono signed 16-bit 22,050Hz. If szID is untagged ("XA"), it can be determined from the WAVEFORMATEX structure.

Decoding
The goal is to pack 16 bits per sample per channel into 4 without sacrificing as much quality as we would through basic scalar quantization.

Lossy Differential/Delta PCM ("DPCM") works on the principle of predicting the difference between the last sample and the current sample and storing the residual in a constricted range. The decompressor must therefore retain the last audio frame when it reads a new one. Before decompression begins, all previous-sample variables must be initialized to zero.

Prediction is applied in blocks of 15 bytes (1 control byte providing the prediction model for 28 samples) for each channel. Here is decompression code in C89 to decode a sequence of complete XA blocks.

A complete working Maxis XA file reading implementation can be found in the FileHandler interface of Niotso under the ISC license.

Other versions
There are several variants of EA ADPCM with decode support in FFmpeg. These are:


 * EA ADPCM
 * EA ADPCM / Maxis XA
 * EA ADPCM R1
 * EA ADPCM R2
 * EA ADPCM R3
 * EA ADPCM / XAS
 * EA IMA ADPCM / EACS
 * EA IMA ADPCM / SEAD

Source code for these can be found in libavcodec/adpcm.c.