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 bits left must be more than zero: k is less than the subframe’s bit depth (RFC 9639 section 9.2.2). The number may differ between subframes and between frames, and if it would change halfway through a subframe, the subframe uses the lowest. The RFC does not say which k an encoder must choose; it only has to be one for which the samples really have k zero low bits.
The shift left is done before any stereo channels are restored: with left-side, side-right or mid-side, each subframe is first padded back with its k zero bits, and only then are left and right rebuilt (section 9.2.2).
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.
Only two-channel streams may use these three. Every stream with any other number of channels must use independent channels, one subframe per channel (RFC 9639 section 4.2; the channel assignment codes 8 to 10 are for two channels only).
Numeric ranges
Appendix A of RFC 9639 gives the integer sizes that cannot overflow. All sample arithmetic must be integer. A side channel has one more bit than the frame’s depth (17 bits for 16-bit audio, 33 for 32-bit), so 32-bit storage covers decoded subframe samples only up to a frame depth of 31 bits (A.2). A fixed predictor of order 0 to 4 adds 0, 1, 2, 3 or 4 bits to the sample depth. A linear predictor’s sum needs the sample depth, plus the coefficient precision, plus the base-2 logarithm of the order rounded up: a 24-bit side channel, order 12 and precision 15 give (24 + 1) + 15 + 4 = 44 bits (A.3). The prediction itself is not limited to 32 bits even though residuals are: the addition of residual and prediction needs a wide enough type (A.4).