A frame holds one subframe per channel, in channel order. A subframe holds the samples of one channel for the whole block. Subframes are not byte-aligned: each follows the last bit of the one before.
Subframe header
| Bits | Field | Meaning |
|---|---|---|
| 1 | Zero bit | Must be 0 |
| 6 | Type code | See below |
| 1 | Wasted bits flag | 1 when the wasted-bit count follows |
| k | Wasted bits | When the flag is set, the count minus 1 in unary: zero bits and then a one |
Wasted bits. Every sample in the block having k zero low bits, as when a 24-bit recording only has 16 bits of range, they are removed before coding. The subframe stores samples k bits shorter, and the decoder shifts each sample left by k afterwards. The count must be the minimum for the block.
The subframe bit depth is the frame’s, minus any wasted bits, plus one for a side channel.
Type codes
| Code | Type |
|---|---|
000000 | Constant |
000001 | Verbatim |
000010 to 000111 | Reserved |
001000 to 001100 | Fixed predictor, order 0 to 4 |
001101 to 011111 | Reserved |
100000 to 111111 | Linear predictor, order 1 to 32 (the code minus 31) |
Constant
One sample, in the subframe’s bit depth, as a signed big-endian number. Every sample in the block has this value: digital silence takes a few bytes.
Verbatim
Every sample of the block stored as it is, in the subframe’s bit depth. Encoders fall back on this when prediction would not make the block smaller.
Warm-up samples
A predictor of order n needs n earlier samples to start. A subframe with a predictor therefore stores its first n samples as they are, in the subframe’s bit depth, then the rest as residuals.
Fixed predictors
The predicted value comes from the previous samples, using these fixed formulas, where s1 is the sample just before:
| Order | Prediction |
|---|---|
| 0 | 0 |
| 1 | s₁ |
| 2 | 2·s₁ − s₂ |
| 3 | 3·s₁ − 3·s₂ + s₃ |
| 4 | 4·s₁ − 6·s₂ + 4·s₃ − s₄ |
The sample is the prediction plus the coded residual.
Linear predictor
After the warm-up samples, a linear-predictive subframe stores its own coefficients:
| Bits | Field | Meaning |
|---|---|---|
| 4 | Coefficient precision | The precision in bits, minus 1. 1111 is forbidden, so 1 to 15 bits |
| 5 | Shift | Signed, in bits, how far to shift the sum right. A negative value is not allowed |
| precision × order | Coefficients | Signed, the first multiplying the sample just before, the next the one before that |
The prediction is (c₁·s₁ + c₂·s₂ + … + cₙ·sₙ) >> shift, an
arithmetic shift, and the sample is that plus the residual.
Channel decorrelation
Stereo is often coded as left and right’s difference, which is smaller than either channel. The difference, the side channel, needs one more bit than the samples.
| Channel assignment | Subframes hold | To restore |
|---|---|---|
| Left and side | left; side | right = left − side |
| Side and right | side; right | left = side + right |
| Mid and side | mid; side | mid = (mid << 1) | (side & 1), then left = (mid + side) >> 1, right = (mid − side) >> 1 |
The side channel is the first subframe in “side and right” and the second in the other two. It has its own bit depth, one more than the frame’s, before any wasted bits are taken away.