Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Module bitstream

Module bitstream 

Source
Expand description

BS (“bitstream”) frame decode: variable-length codes to MDEC run-length halfwords.

A BS frame starts with an 8-byte header:

BytesField
0..2MDEC data size in 32-bit words (low half of the MDEC command)
2..40x3800 (high half of a 15bpp decode command)
4..6quantization scale, 1..63
6..8bitstream 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§

DecodeError
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.