MTA2 (Codec)

From mgsdevwiki
Jump to: navigation, search

MTA2 is the audio codec used in Metal Gear Solid 4. It is based off of the Maxis XA ADPCM codec, which is commonly used in Playstation games.

Containers

Format

An example of a typical MTA2 block:

00 00 00 00 00 04 00 90 00 00 00 00 00 00 00 00
00 00 00 E0 00 00 00 20 00 00 00 E0 00 00 00 E0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 F0 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Header
uint8 {1} Track Number (0x0 unless multi-tracked)
uint24 {3} Frame Number (starts at 0)
uint16 {2} Channel Mask (see MTA2 (Container))
uint16 {2} Length of all blocks (0x90 * channels)
byte {8} Padding
Block Info
bit {6} Sample 2 (Second raw sample, drops the last 2 bits)
bit {6} Sample 1 (First raw sample, drops the last 2 bits)
bit {3} Mod
bit {5} Shift
Sample Nibbles
bit {4} Sample Nibble (see Decoding)

Decoding

Nibbles are decoded in columns of 8 nibbles, left-right, top-down:

HE-AD-ER-01 HE-AD-ER-02 HE-AD-ER-03 HE-AD-ER-04
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44
11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44

Nibbles are decoded using this formula:

output = (sample1 * c1[mod] + sample2 * c2[mod] + nibble * c3[shift] + 128) >> 8

The output is clamped from -32,768 to 32,767.

Constant Tables

c1

0, 240, 460, 392, 488, 460, 460, 240

c2

0, 0, -208, -220, -240, -240, -220, -104

c3

256, 335, 438, 573, 749, 979, 1281, 1675, 2190, 2864, 3746,
4898, 6406, 8377, 10955, 14327, 18736, 24503, 32043, 41905,
54802, 71668, 93724, 122568, 160290, 209620, 274133, 358500,
468831, 613119, 801811, 1048576

Tools

Credits

  • daemon1, figuring out the codec, decryption code, and help with the encoder.
  • tbg, helping figure out the MTA2 container format.
  • OrangeC, getting daemon1 to work on this, testing stuff out.
  • GHzGangster, Java implementation, MTA2 container format.