From MultimediaWiki
Jump to navigation Jump to search

Some computer and console games use 4xm multimedia files that are encoded with 4X Technologies' proprietary video codec and either linear PCM audio or a modified IMA ADPCM. The file format also supports multiple audio tracks intended for multi-lingual multimedia files.

4xm is a chunked file format where each chunk is marked with a fourcc. A 4xm file header contains a 'strk' audio header for each audio track in the file. Byte 12 of the 'strk' audio chunk apparently is set to 1 if the track is encoded as ADPCM.

All multi-byte numbers are encoded in little-endian format. Each chunk is encoded with a preamble to describe the initial predictors and step indices. If the audio data is monaural, the preamble is laid out as:

bytes 0-1:    initial predictor
bytes 2-3:    initial index 

The rest of the bytes in the chunk are IMA nibbles. Each byte is decoded bottom nibble first (bits 3-0), then top nibble:

byte0 byte1 byte2 byte3 ...
 n1n0  n3n2  n5n4  n7n6 ... 

If the audio data is stereo, the initial predictors and step indices are interleaved in the chunk preamble:

bytes 0-1:    initial predictor for left channel
bytes 2-3:    initial predictor for right channel
bytes 4-5:    initial index for left channel
bytes 6-7:    initial index for right channel 

The first half of the remaining bytes of the chunk are the left IMA nibbles and the second half are the right IMA nibbles. For example, if an entire chunk of stereo 4X audio is 108 bytes (decimal), the first 8 bytes are the preamble, the next 50 bytes are left channel nibbles and the final 50 bytes are right channel nibbles. As in monaural data, bytes are decoded bottom nibble first (bits 3-0), then top nibble.

(NOTE: Is the IMA algorithm slightly modified for this variation?)