Expand description
BS (“bitstream”) frame decode: variable-length codes to MDEC run-length halfwords.
A BS frame starts with an 8-byte header:
| Bytes | Field |
|---|---|
| 0..2 | MDEC data size in 32-bit words (low half of the MDEC command) |
| 2..4 | 0x3800 (high half of a 15bpp decode command) |
| 4..6 | quantization scale, 1..63 |
| 6..8 | bitstream version (1, 2 or 3) |
The body is read as little-endian 16-bit words, most significant bit
first. Macroblocks come in column-major order (top to bottom, then left
to right), six 8x8 blocks each: Cr, Cb, Y0..Y3. In versions 1 and 2 every
block starts with a raw 10-bit signed DC value (0x1FF there ends the
frame), followed by the AC run/level codes of the MPEG-1 DCT
coefficient table (ISO 11172-2 table B.5c, with the sign bit after the
code), a 6-bit escape 000001 followed by a raw 16-bit MDEC halfword,
and 10 for end of block.
The MDEC wants, per block, (qscale << 10) | dc then one halfword per
non-zero AC coefficient (run << 10 | level, level 10-bit signed) and
0xFE00 to end the block. The same 0xFE00 pads the tail.
The code table is the one every BS encoder uses; the listing here was cross-checked against psxavenc’s encoder table (zlib license) and the PSX-SPX description.
Structs§
- Header
- Parsed frame header.
Enums§
- Decode
Error - Why a frame could not be decoded.
Constants§
- END_
OF_ BLOCK - MDEC end-of-block / padding halfword.
- HEADER_
BYTES - Fixed BS frame header size in bytes.
Functions§
- decode_
frame - Decode one version-1 or version-2 BS frame (header included) into MDEC halfwords. The two versions code the bitstream the same way: version 1 is what the earliest (1995) Sony encoder wrote, WipEout’s intro among them.