Decoding audio XNBs (WAV and XMA)

 When extracting sound effects from XNB containers, I've found they can exist in one of two formats:

  • WAV files
  • XMA files (which are WAV files with a certain codec)
Let's take a look at two different uncompressed .XNBs and break them down according to WAV file specs:

XNB1.xnb

XNB Header
58 4e 42 78 05 01 8b 88 00 00 01 31 4d 69 63 72 6f 73 6f 66 74 2e 58 6e 61 2e 46 72 61 6d 65 77 6f 72 6b 2e 43 6f 6e 74 65 6e 74 2e 53 6f 75 6e 64 45 66 66 65 63 74 52 65 61 64 65 72 00 00 00 00 00 01 
34 00 00 00 01 66 00 01 00 00 ac 5e 00 00 4a 66 00 02 00 10 00 22 00 01 00 00 00 01 00 01 58 00 00 00 80 00 00 00 00 00 00 01 56 4c 00 00 01 80 00 01 56 80 00 04
00 02 00 88 00 00 30 00 01 00 08 8f fc 03 80 00 17 d4 73 17 49 bd 24 61 44 c2 8c 27 0c 4f 7c 2a af d7 d5 
Song Starts
    • 34 00 00 00 -- Subheader size, 16 + extra data size (36 bytes)
    • 01 66 -- Audio format (XMA)
    • 00 01 -- Number of channels (1 = mono)
    • 00 00 ac 5e -- Sample rate
    • 00 00 4a 66 -- Byte rate
    • 00 02 -- Number of bytes in sample (2 bytes)
    • 00 10 -- Bits per sample (16 bits)
    • 00 22 -- Extra data size (34 bytes)
    • 34 00 00 00 01 66 00 01 00 00 ac 5e 00 00 4a 66 00 02 00 10 00 22 00 01 00 00 00 01 00 01 58 00 00 00 80 00 00 00 00 00 00 01 56 4c 00 00 01 80 00 01 56 80 00 04  -- Extra data


XNB2.xnb

XNB Header
58 4e 42 77 05 00 43 e1 00 00 01 31 4d 69 63 72 6f 73 6f 66 74 2e 58 6e 61 2e 46 72 61 6d 65 77 6f 72 6b 2e 43 6f 6e 74 65 6e 74 2e 53 6f 75 6e 64 45 66 66 65 63 74 52 65 61 64 65 72 00 00 00 00 00 01  
12 00 00 00 01 00 01 00 44 ac 00 00 88 58 01 00 02 00 10 00  
00 00 da e0 00 00 73 23 43 35 25 15 d5 26 b4 1b 24 18 09 1b d0 13 e7 14 62 12 26 10 c3 0f 95 0d c4 0c a0 0b 75 0a b7 09 c0 08 03 08 57 07 a8 06 1a 06 8d 05 0f 05 a7 03 f1 ad 55 a4 1e d8 82 b4 22 d0  
Song Starts
    • 12 00 00 00 -- Subheader size (16 bytes)
    • 01 00 -- Audio format (PCM)
    • 01 00 -- Number of channels (1 = mono)
    • 44 ac 00 00 -- Sample rate
    • 88 58 01 00 -- Byte rate
    • 02 00 -- Number of bytes in sample (2 bytes)
    • 10 00 -- Bits per sample (16 bits)
    • 00 00 -- Extra data size (0 bytes) Not used with PCM


To extract a playable file out of an XNB, you will need to convert the XMA within to a more widely known codec. I used vgmstream, which can convert any kind of audio XNB to common WAV. You can then convert them back to XNB for use in your games.

No comments:

Post a Comment