The ASF container is publicly specified, but the WMA codecs inside it are not: Microsoft
has never published their bit streams. What follows the format tag comes from
Microsoft’s WAVEFORMATEX definitions and from open-source reverse-engineered
decoders, chiefly FFmpeg. The audio data of each codec is otherwise not documented
here.
Format tags
The tag is the first field of the WAVEFORMATEX in a stream’s properties.
| Tag | Codec | Status |
|---|---|---|
0x000A | Windows Media Audio Voice | speech codec; decoded by FFmpeg |
0x0160 | Windows Media Audio 1 | decoded by FFmpeg |
0x0161 | Windows Media Audio 2 (“standard”), the usual codec | decoded by FFmpeg |
0x0162 | Windows Media Audio 9 Professional | decoded by FFmpeg |
0x0163 | Windows Media Audio 9 Lossless | decoded by FFmpeg |
Codec-specific data
The extra bytes that follow WAVEFORMATEX:
| Codec | Bytes | Layout |
|---|---|---|
WMA 1 (0x0160) | 4 | 2-byte samples per block, 2-byte encode options |
WMA 2 (0x0161) | 10 | 4-byte samples per block, 2-byte encode options, 4-byte super block alignment |
WMA Pro (0x0162) and Lossless (0x0163) | 18 | 2-byte valid bits per sample, 4-byte channel mask, 8 bytes reserved, 2-byte encode options (offset 14), 2 bytes reserved |
| Encode option bit | Meaning (WMA 1 and 2) |
|---|---|
0 (0x0001) | exponents coded with variable-length codes; otherwise as line spectral pairs |
1 (0x0002) | bit reservoir in use, so frames span packets |
2 (0x0004) | variable block length |
| 3–4 | the number of block sizes used, in the encoded form FFmpeg reads as ((bits 3–4) + 1), with 2 added when the bit rate per channel is 32,000 or more |
Superframes
A WMA payload is a superframe that holds one or more frames of audio. When the bit reservoir is in use, a superframe starts with these fields, as FFmpeg reads them:
| Width in bits | Field | Meaning |
|---|---|---|
| 4 | superframe index | |
| 4 | frame count | frames that finish in this superframe |
| byte offset bits + 3 | bit offset | where the first complete frame starts, used to finish a frame begun in the last superframe |
Without a reservoir, a superframe is exactly one frame. Each frame is a run of blocks: with variable block lengths, each block begins with size indices; each then has an M/S bit, a coded bit per channel, a total gain, and the exponents and coefficients. The size of a frame depends on the sample rate. Beyond this point the codec’s Huffman tables and syntax are only described by decoder source code.
Frame lengths
WMA frames are 2n samples per channel; the exponent n by sample rate, as FFmpeg chooses it:
| Sample rate | n | Samples |
|---|---|---|
| up to 16,000 Hz | 9 | 512 |
| up to 22,050 Hz (32,000 Hz for WMA 1) | 10 | 1,024 |
| up to 48,000 Hz (all rates for WMA 1 and 2) | 11 | 2,048 |
| up to 96,000 Hz | 12 | 4,096 |
| above that | 13 | 8,192 |