A predictor leaves a residual for each sample: how far off the prediction was. Most residuals are small, so they are coded to take few bits, in partitions with their own Rice parameter.
Coding method and partition order
| Bits | Field | Meaning |
|---|---|---|
| 2 | Method | 00 Rice with 4-bit parameters; 01 Rice with 5-bit parameters; 10 and 11 reserved |
| 4 | Partition order | The block is split into 2order partitions |
The block size must divide evenly by the number of partitions. An odd block size therefore allows only order 0.
Partitions
A partition holds block size >> order residuals, except the first,
which holds that minus the predictor order, because the warm-up samples take its
place. block size >> order must be larger than the predictor order.
Each partition starts with its Rice parameter, 4 or 5 bits by the method. The highest
value, 1111 or 11111, is the escape: the
next 5 bits give a width, and the residuals are stored as plain signed numbers of that
many bits. A width of 0 means every residual in the partition is 0 and no further
bits follow.
Otherwise, for parameter k, each residual is a unary number (that many zero bits, then a one) followed by k low bits. Together they give a non-negative value, which is then unfolded into a signed one:
value = (zeros << k) | low bits
if value is even: residual = value / 2
if value is odd: residual = −(value + 1) / 2
A residual must fit a signed 32-bit number and must not be −231.