A FLAC file can carry the extension data of LAE Lossy (LAEY), the lossy tier of the Layered
Audio Extension, in APPLICATION blocks whose ID is
LAE1 (4C 41 45 31, in the IANA registry). The FLAC audio frames are the
CD layer, an ordinary 16-bit stereo stream; the extension adds a higher-rate master on top. A reader
that does not know the extension plays the CD layer.
Source. LAE Lossy
specification, spec/lossy/SPEC.md, repository tag v5-2026-11-19, sections
3.3 (the LAE chunk), 3.4 (FLAC form), 4 (main header), 5 (stream records and
order) and 6 to 13 (range decoder, partition syntax, dequantisation, inverse MDCT, half-band filters, reconstruction with the output file in 11.8, error handling in 12, self-test), with Appendix B. Licence CC BY 4.0, author mtq0605. The earlier tag v5-2026-10-30 had no layout for
the FLAC form, which is why this page was written only now. Layouts are little-endian throughout.
Check names in brackets (V1 to V13) are the specification’s own.
The FLAC form
- The stream is
fLaC, STREAMINFO, optionally one VORBIS_COMMENT and any number of PICTURE blocks, then one or moreLAE1APPLICATION blocks, optionally other metadata, then the audio frames. - STREAMINFO says 2 channels, 16 bits and a base rate of 44,100 or 48,000 Hz. The sample count must not be 0, and the MD5 must be present and correct (over the interleaved 16-bit little-endian samples); with no MD5 or a wrong one the extension must not be used.
- The extension is the body of the
LAEchunk of the single-file WAV form, byte for byte: it begins with the magicLAE1and ends with a CRC-32. It is cut into slices of at most 224 − 5 bytes, and each slice is the data of oneLAE1block. A reader joins the data of allLAE1blocks in file order; a writer puts them consecutively after STREAMINFO and after any tag or picture blocks. - No SEEKTABLE and no CUESHEET block is written.
- Every audio frame uses channel assignment 1 (independent left and right, no stereo decorrelation); any valid FLAC coding is otherwise allowed.
- A FLAC file with no
LAE1blocks is plain FLAC; one withLAE2blocks is an LAES file. A reader of one of the two formats that finds the other must say which format it found and must not decode it as its own (section 3.4). - A reader decides by the content, never by the file name: the first 4 bytes are
fLaC(FLAC form) orRIFF…WAVE(WAV form)..flacnames the FLAC form,.wavthe WAV form, and.laemay hold either.
Validation, in this order (section 3.4)
- The FLAC structure: STREAMINFO first, 2 channels, 16 bits, a sample count, at least one
LAE1block. - Every audio frame: header CRC-8, frame CRC-16, block sizes within the limits of STREAMINFO, and a total equal to the sample count.
- The MD5.
- The checks V1 to V13 on the extension and the CD layer (below).
A file that fails item 2, 3 or 4 is damaged, and the decoder must not decode the extension (exit status 3 in the reference
decoder). The decoded FLAC audio is the CD layer and the joined blocks are the body of the LAE chunk, so every route gives the
same output samples as the WAV form of the same encoding.
The CRC-32
The last four bytes of the joined payload are a CRC-32 of every byte before them (IEEE 802.3:
reflected polynomial 0xEDB88320, initial value and final XOR 0xFFFFFFFF;
CRC-32 of “123456789” is 0xCBF43926), stored little-endian. A reader checks it before it
interprets any other byte, except the four-byte magic that identifies the format. A body of fewer
than 8 bytes, or a wrong CRC, is refused (V1).
Main header
Thirteen little-endian int32 fields at the start of the payload, 52 bytes.
| Offset | Field | Meaning | Valid values |
|---|---|---|---|
| 0 | magic | Chunk magic | 0x3145414C, “LAE1” (V2) |
| 4 | version | Container version | 5 (V2) |
| 8 | rate | Master sample rate in Hz | base × 2stages (V5) |
| 12 | base | Base (CD layer) rate in Hz | 44100 or 48000 (V3) |
| 16 | stages | Octave stages from base to master | 1 to 3 (V4) |
| 20 | Lm | Master length per channel | 1 to 2,000,000,000 − 2P (V8) |
| 24 | P | Padding at the master rate, each side | 1 to 65,536, a multiple of 2stages (V6) |
| 28 | fc | Detected CD cut-off in Hz | Informational |
| 32 | mi | Partition mode index | 0 to 5 (V10) |
| 36 | eq | Cut type the encoder used | 0 unequal, otherwise equal; informational |
| 40 | wm | Share measure the encoder used | 0 cells, 1 energy, 2 cells and energy; informational |
| 44 | nb | Padded base-rate length per channel | (Lm + 2P) >> stages (V9) |
| 48 | pb | Base-rate padding, each side | P >> stages (V7) |
V13: the number of samples of the CD layer (the FLAC sample count) equals nb − 2·pb.
The checks the decoder must make (section 4.3)
A decoder checks these conditions in this order, before it uses any field to address data. If one fails it refuses
to decode the extension (section 12 table). ncd is the number of samples of the CD layer.
| # | Condition |
|---|---|
| V1 | The body is at least 8 bytes and its CRC-32 matches |
| V2 | magic = 0x3145414C and version = 5 |
| V3 | base is 44100 or 48000 |
| V4 | 1 ≤ stages ≤ 3 |
| V5 | rate = base << stages |
| V6 | 0 < P ≤ 65536 and P mod 2stages = 0 |
| V7 | pb = P >> stages |
| V8 | 0 < Lm ≤ 2000000000 − 2P |
| V9 | nb = (Lm + 2P) >> stages |
| V10 | 0 ≤ mi < 6 |
| V11 | At least 8pb bytes remain after offset 52 |
| V12 | ndf = 2 × ceil(nb / 4096), and ndf bytes remain after the ndf field |
| V13 | ncd = nb − 2pb |
V6, V7 and V9 imply nb − 2pb = ⌊Lm / 2stages⌋, so with V13 also
ncd = ⌊Lm / 2stages⌋. Derived: Lp = Lm + 2P
(the padded master length), N = 512, nbk = ndf / 2.
Edge samples
Next, at offset 52, come 4 × pb little-endian int16 values (8 × pb
bytes): the leading padding’s stereo pairs, then the trailing padding’s, interleaved left and right.
Fewer bytes left than that is an error (V11).
Dither flags
At offset 52 + 8·pb an int32 ndf, then ndf bytes (one
uint8 each): the flags of every 4,096-sample block of the base-rate signal, all of
channel 0’s blocks first, then channel 1’s. ndf must equal 2 × ceil(nb / 4096),
and that many bytes must remain (V12). With nbk = ndf / 2 the flag of channel c and block b
is byte dfl[c · nbk + b], and block b covers the padded base-rate indices 4096b to
4096b + 4095. A zero byte means no dither was added in that block; any non-zero byte means TPDF dither was added
(section 11.2 below). Encoders should write 0 or 1 (section 4.2).
Stream records
The stream records start where the dither flags end, in this fixed order. Each record is an
int32 nbytes (at least 40, and the record must lie inside the payload) and
then nbytes bytes of stream data: a 40-byte stream header and a range-coded payload of
nbytes − 40 bytes.
| # | Content | Count |
|---|---|---|
| 1 | Depth stream, channel L | 1 record |
| 2 | Depth stream, channel R | 1 record |
| 3 | nseg, an int32, 1 to 8 | 1 field |
| 4 | Frequency records of plane M, segments 0 to nseg − 1 | nseg records |
| 5 | Frequency records of plane S, segments 0 to nseg − 1 | nseg records |
Every record is walked in order whether or not a decoder uses it, because the position of each
depends on the end of the one before. After the last S record come the optional pack records and name
record (below); with neither, the CRC-32 follows the last S record directly, and encoders must write
nothing else there. Which streams a decoder uses depends on the output route (24-bit, 16-bit or
cd24): the depth streams are skipped for 16-bit output, the frequency streams for the cd24 route,
and a frequency stream whose first bin k0 is at or above the cut kcut =
512 >> d for an output rate of rate >> d is skipped. Without any selected
M stream the whole frequency layer is left out, selected S streams included.
The selection rules (section 5.4) in full:
- Depth streams are decoded in the 24-bit and cd24 routes and skipped in the 16-bit route.
- Frequency streams are skipped in the cd24 route. In the 24-bit and 16-bit routes, with the output rate
rate>> d (rateis the master rate of the main header), a frequency stream is decoded if and only if itsk0is less thankcut= 512 >> d. The reference decoder computes the same value as lround(512 × (orate/ 2) / (rate/ 2)). - The reference decoder reads
k0from the stream header before it consumes the record. If fewer than 16 bytes remain at the record position,k0is taken as 0; such a record is then necessarily rejected by the record checks above. - The selected M streams form the M signal and the selected S streams the S signal (their planes are added, see the inverse MDCT).
- A decoder that does not support packs ignores any bytes between the end of the last S record and the CRC (section 5.2); an encoder must not write anything there except pack records and the name record.
- The checks marked “valid values” in the stream header table below (
K> 0,N= 512,k0≥ 0,k0<k1≤ 512,plen=nbytes− 40) are made for every stream that is decoded. A stream that is skipped is checked only fornbytes≥ 40 and for lying within the payload (section 5.3).
The stream header
Ten little-endian int32 fields, 40 bytes.
| Offset | Field | Meaning | Valid values |
|---|---|---|---|
| 0 | K | Frames in the plane | > 0 |
| 4 | N | Coefficients per frame | 512 |
| 8 | k0 | First coded bin | ≥ 0 |
| 12 | k1 | One past the last coded bin | k0 < k1 ≤ 512 |
| 16 | rate | The plane’s sample rate | Not used by a decoder |
| 20 | L | The plane’s signal length | Not used by a decoder |
| 24 | cw | CW + 256 × rule | The low byte is the coder width (encoders write 8; a decoder always uses 8); the next byte selects the precision rule of section 8.2 |
| 28 | lv | Partition mode index | Not used by a decoder |
| 32 | eq | Cut type: 0 unequal, otherwise equal | Used by the partition syntax |
| 36 | plen | Length of the range-coded payload | nbytes − 40 |
The plane is X[m][k], m from 0 to K − 1 and k from 0 to 511, with bins outside
[k0, k1) zero. The bins form ceil((k1 − k0) / 8) cells of 8 bins, and the cells are
grouped into root blocks of 16 cells by 8 frames (smaller at the high-frequency edge or the end).
K should be the number of frames of the plane’s signal: a smaller K leaves the missing frames
zero, a larger one is never used.
The range-coded data
The coefficient data inside each stream is the output of an adaptive range coder with a partition
syntax; the sections below describe the coder, the syntax, the dequantisation, the inverse MDCT and the
reconstruction pipeline (the specification’s sections 6 to 11). A stream must be consumed exactly: when
its last symbol has been decoded, all plen bytes have been read once and none beyond them.
The four bytes the encoder flushes at the end are not checked.
The range decoder
Every stream has a decoder of its own, started at the first byte of its coded payload, and its adaptive
models live for the whole stream (there are no random-access points). State: range and
code, both uint32; range starts at 0xFFFFFFFF and code at 0.
next() gives the next payload byte, and 0 once all plen bytes are used. The decoder starts by
taking five bytes: code = (code << 8) | next(), five times, so the first byte
(a 0x00 the encoder writes) is shifted out.
- Adaptive bit. A probability p is a
uint16, the chance of a 0 in units of 1/2048, started at 1024.bound= (range>> 11) × p. Ifcode<boundthe bit is 0,range=boundand p += (2048 − p) >> 5; otherwise the bit is 1,code−=bound,range−=boundand p −= p >> 5. Then, whilerange< 224:range<<= 8 andcode= (code<< 8) |next(). - Bypass bits,
direct(n), most significant first: for each bitrange>>= 1, the bit is 1 whencode≥range(and thencode−=range), followed by the same renormalisation. - Binary tree,
tree(pr, nbits): node = 1, then nbits times node = 2node + bit(pr[node]); the value is node − 2nbits. - Integer model U (two arrays of 64 probabilities,
treeandmant): len = tree(tree, 5) (0 to 31); if len ≤ 1 the value is len; otherwise top = bit(mant[len]), nr = len − 2, rest =direct(nr)(0 when nr = 0), and the value is 2len−1 + top · 2nr + rest.
The partition syntax
Models per stream (all probabilities start at 1024): TierP (4 contexts of a 2-bit tree), ExpZero[t],
ExpSign[t] and ExpU[t] for tiers 1 to 3, ZlP (4 contexts of a 3-bit tree), and
CoefU (3 × 13 U models). State: prevTier = 0 and prevE = 12.
Rows of 8 frames are visited in increasing time, and within a row the root blocks in increasing frequency. For every root
block, node(f0, f1, t0, t1) works on a rectangle of cells and frames. The admissible cuts of an extent w are none when
w < 2, the single cut at ⌊w/2⌋ when the stream’s eq is not 0, and otherwise every position 1 to w − 1.
- If a frequency cut or a time cut is possible, one bypass bit says whether to split. Without it the node is a leaf.
- On a split: with only one direction possible that is the direction, otherwise a bypass bit gives it (0 frequency, 1 time). The
position index is
direct(b)with b the smallest number such that 2b is at least the number of cuts (no bits when b = 0). An index beyond the list is CORRUPT and clamped to the last cut. Both parts are then walked, the first part first.
Leaves
Each leaf carries its own tier, exponent and zero level.
- Tier: tree(
TierP[4 ·prevTier…], 2): 0 = A, 1 = B, 2 = C, 3 = D;prevTierbecomes it. Tier A means every coefficient of the leaf is 0 and nothing more is coded. - Exponent E: if bit(
ExpZero[tier]) is 1 the change d is 0; otherwise neg = bit(ExpSign[tier]), a = U(ExpU[tier]) and d = −(a + 1) or a + 1. E =prevE+ d must lie in 0 to 34 (otherwise CORRUPT, clamped);prevEbecomes E. - Zero level z = tree(
ZlP[8 · tier …], 3), 0 to 7. - The step is 2s with s from the precision rule below, and the coefficient model is
CoefU[(tier − 1) · 13 + min(12, ⌊E/2⌋)].
Coefficients and dequantisation
For each frame of the leaf, and each cell in increasing frequency, and each bin of the cell (the last cell may have fewer than 8):
a = U(model); if a > 0 a bypass bit gives the sign and q = ±a, otherwise q = 0; and when q = 0 and z > 0 one more
bypass bit zs follows (the true sign of the zero). The value, in binary64 with every operation rounded in turn, is
(q + 0.20) × step for q > 0 and (q − 0.20) × step for q < 0; for q = 0 it is 0, or
(zs ? −1 : 1) × ZC[z] × step with ZC = 0, 1/32, 1/16, 3/32, 1/8, 3/16, 1/4, 3/8. A value beyond ±1,073,741,823 is CORRUPT and clamped. The plane
entry is the value rounded to the nearest integer, ties away from zero (llround).
Tiers B, C and D mean 2, 4 and 8 bits below the leaf exponent (TB = 0, 2, 4, 8). The step exponent s depends on the
stream’s rule, the second byte of cw:
rule | Step exponent s |
|---|---|
| 1 | max(0, min(E, 8) − TB[tier]) |
| 2 | max(0, min(E − TB[tier], 8 − TB16[tier])), TB16 = 0, 0, 4, 8 |
| 3 | max(0, min(E, 6) − TB[tier]) |
| 0 or any other | min(8, max(0, E − TB[tier])) (the formula of container version 4) |
Every rule gives 0 ≤ s ≤ 8, so no step is coarser than one CD-layer step. A CORRUPT condition marks the stream damaged: a decoder clamps and goes on without overrunning memory, but must not deliver the output.
Inverse MDCT
An MDCT with a sine window, N = 512 coefficients per frame and 50% overlap. A signal of Ls samples has ceil(Ls / 512) + 1 frames; frame m
covers positions 512m to 512m + 1023 of a sequence that has 512 zeros before the signal, and signal sample i is at position i + 512. The depth
signal of a channel has Ls = nb; M and S have Ls = Lm + 2P (the master rate). The planes of the selected segments of M (or S) are added coefficient by coefficient
(exactly, in a double) before the transform.
Constants (M = 256): WIN[n] = sin(π(n + ½) / 1024); the pre- and post-twiddles are cos and sin of −2π(n + ⅛) / 1024; the FFT
twiddles cos and sin of −2πk / 256; BITREV reverses 8 bits; SCALE = 2−4. The specification says the values of its reference header MUST be used, because a maths library may differ
in the last bit: 56 of the 2,304 values of the three table pairs differ between the JavaScript engine used here and that header, so the viewer does not compute them: its 1,792 listed values (1,560 of them distinct bit patterns) are the header’s own literals, written out
unchanged (as C %a hexadecimal doubles) and turned into doubles with exact integer arithmetic, and the decoder gives the same output on every JavaScript engine. A checksum of the tables is part of the self-test, as a check of the embedded text.
The table values. All 2,304 values of the header (WIN 1,024; PRE_C, PRE_S, POST_C and POST_S 256 each; FFT_C and
FFT_S 128 each) are on two pages, in the header’s own %a notation: the window table WIN and
the twiddle tables (POST_C and POST_S are the same lists as PRE_C and PRE_S, so they are listed once: 1,792 values are listed, of which 1,560 are distinct bit patterns, 842 in WIN and 718 in the four twiddle lists together).
They were compared as text with the header at tag v5-2026-11-19 and with the viewer’s embedded text, 0 differences each; and 56 of the 2,304 header values differ from Math.sin and Math.cos of the
generating formulas on the JavaScript engine used here (counted: WIN 22, PRE_C 8, PRE_S 7, POST_C 8, POST_S 7, FFT_C 1, FFT_S 3).
BITREV[i] is i with its 8 bits reversed, and SCALE = 0x1p-4.
The DCT-IV is done as in FFmpeg’s old mdct.c: re[n] = a · PRE_C − b · PRE_S and im[n] = a · PRE_S + b · PRE_C with
a = c[2n] and b = c[511 − 2n]; a 256-point radix-2 decimation-in-time FFT (written out below) after the bit-reversal permutation; then
yr = (re · POST_C − im · POST_S) · SCALE, yi = (re · POST_S + im · POST_C) · SCALE, u[2k] = yr,
u[511 − 2k] = −yi. Each product and each sum is rounded in turn, in the order written; a fused multiply-add or any other factorisation changes the output bits. The frame is then
unfolded and windowed into the accumulator y in frame order (for n < 256:y[s+n] += u[256+n]·WIN[n];
y[s+256+n] += −u[511−n]·WIN[256+n]; y[s+512+n] += −u[255−n]·WIN[512+n];
y[s+768+n] += −u[n]·WIN[768+n], with s = 512m). Output sample i is llround(y[i + 512]), and a value beyond ±1,073,741,823 is CORRUPT.
A frame whose coefficients are all zero may be skipped.
The FFT, exactly (section 9.3)
With M = 256 and N = 512, DCT4 takes c[0 … N − 1] and gives u[0 … N − 1]. It must be computed exactly as follows;
each product is rounded, then each sum or difference is rounded, in the order written.
DCT4(c[0 ... N-1]) -> u[0 ... N-1]:
for n = 0 ... M-1:
a = c[2n]; b = c[N-1-2n]
re[n] = a*PRE_C[n] - b*PRE_S[n]
im[n] = a*PRE_S[n] + b*PRE_C[n]
FFT(re, im)
for k = 0 ... M-1:
yr = (re[k]*POST_C[k] - im[k]*POST_S[k]) * SCALE
yi = (re[k]*POST_S[k] + im[k]*POST_C[k]) * SCALE
u[2k] = yr
u[N-1-2k] = -yi
FFT(re, im): // radix-2, decimation in time, M = 256
for i = 0 ... M-1: // bit-reversal permutation
j = BITREV[i]
if i < j: swap(re[i], re[j]); swap(im[i], im[j])
for len = 2, 4, ..., M:
step = M / len; h = len / 2
for i = 0; i < M; i += len:
for k = 0 ... h-1:
wr = FFT_C[k*step]; wi = FFT_S[k*step] // twiddle index k*step
xr = re[i+k+h]; xi = im[i+k+h]
tr = xr*wr - xi*wi
ti = xr*wi + xi*wr
re[i+k+h] = re[i+k] - tr; im[i+k+h] = im[i+k] - ti
re[i+k] = re[i+k] + tr; im[i+k] = im[i+k] + ti
DCT4 is the orthonormal DCT-IV, which is its own inverse: X[k] = √(2/N) Σ u[n] cos(π/N · (n + ½)(k + ½)).
The transform must be computed with exactly the structure of this section and of the next one; another factorisation generally changes the output bits, and an implementation that gives bit-identical results
in another way (for example by skipping all-zero frames) meets the requirement.
Overlap-add and output rounding (section 9.4)
y: double array over the padded positions, initialised to +0.0
for m = 0 ... frames(Ls)-1: // increasing m; each position accumulates in frame order
c[k] = sum over planes of (double) X_plane[m][k] // exact; 0 if no plane has frame m
u = DCT4(c); s = m*N
for n = 0 ... N/2-1: // unfold, window, add
y[s + n] += u[N/2 + n] * WIN[n]
y[s + N/2 + n] += (-u[N-1-n]) * WIN[N/2 + n]
y[s + N + n] += (-u[N/2-1-n]) * WIN[N + n]
y[s + 3N/2 + n] += (-u[n]) * WIN[3N/2 + n]
output sample i in [0, Ls):
v = y[i + N]
if v > 1073741823.0 or v < -1073741823.0: CORRUPT; v = clamp(v, -1073741823.0, 1073741823.0)
o[i] = (int32) llround(v)
The samples at positions s to s + N − 1 are final once frame m has been added.
Summing planes (section 9.5)
- A depth channel has its single depth plane; M and S each sum their selected segments’ planes.
- The segments of one signal may overlap in frequency (an encoder may code the same bins twice, for example to cancel the up-converted CD layer in silent cells); the planes are added coefficient by coefficient.
- Each plane value is an
int32of magnitude at most 1,073,741,823 and there are at most 8 planes per signal, so the double sum is exact and its order is irrelevant. - A plane whose stream has fewer than m + 1 frames contributes zero to frame m. The transform of an all-zero frame gives only zeros, so it may be skipped.
Half-band filters and the reconstruction pipeline
Units: one fine unit (FU) is 1/16 of a 24-bit step; one CD-layer step is 4096 FU. The four half-band tables hold the odd taps ht[t] = h[2t + 1] in Q31 (the centre tap is 230):
table 0 (base ↔ 2 × base) has 40 taps, table 1 has 8, table 2 has 6 and table 3 (not used in version 5) has 5; the values are in the table below (section 10.1). Table k connects the rates base × 2k and base × 2k+1, and the same table serves the interpolator and the decimator of that pair.
In every table the stored taps sum to exactly 229, so the DC gain of each interpolator and decimator is exactly 1.
| t | Table 0 (40 taps) | Table 1 (8 taps) | Table 2 (6 taps) | Table 3 (5 taps, not used in version 5) |
|---|---|---|---|---|
| 0 | 682938002 | 668035431 | 656183834 | 644456397 |
| 1 | −225979149 | −184994700 | −156920197 | −132671512 |
| 2 | 133607419 | 75935913 | 47052629 | 28454516 |
| 3 | −93347908 | −29954182 | −10858972 | −3484033 |
| 4 | 70491357 | 10005932 | 1477097 | 115544 |
| 5 | −55579122 | −2547898 | −63479 | |
| 6 | 44978765 | 417025 | ||
| 7 | −36999032 | −26609 | ||
| 8 | 30747123 | |||
| 9 | −25707634 | |||
| 10 | 21562088 | |||
| 11 | −18102637 | |||
| 12 | 15187220 | |||
| 13 | −12714693 | |||
| 14 | 10610315 | |||
| 15 | −8816912 | |||
| 16 | 7289329 | |||
| 17 | −5990851 | |||
| 18 | 4890848 | |||
| 19 | −3963205 | |||
| 20 | 3185274 | |||
| 21 | −2537151 | |||
| 22 | 2001191 | |||
| 23 | −1561677 | |||
| 24 | 1204578 | |||
| 25 | −917388 | |||
| 26 | 688994 | |||
| 27 | −509581 | |||
| 28 | 370536 | |||
| 29 | −264370 | |||
| 30 | 184638 | |||
| 31 | −125854 | |||
| 32 | 83405 | |||
| 33 | −53473 | |||
| 34 | 32940 | |||
| 35 | −19306 | |||
| 36 | 10605 | |||
| 37 | −5322 | |||
| 38 | 2321 | |||
| 39 | −771 |
The values are those of section 10.1 of the specification and of the reference header src/halfband.h (kHalf0 to kHalf3), which agree, and they are identical to the
values embedded in the viewer’s decoder (HALFBAND in laey.js). Table 0 has half-length 79 (159 taps), table 1 15 (31 taps), table 2 11 (23 taps), table 3 9 (19 taps).
Edge extension (section 10.2). Input indices outside [0, n), where n is the input length, are reflected about the end samples (whole-sample symmetric) and then clamped:
mirror(i, n): if i < 0 then i = −i; if i ≥ n then i = 2 (n − 1) − i; the result is clamp(i, 0, n − 1).
Interpolation by 2 (section 10.3; input length n, output length 2n; T stored taps): y[2m] = x[m] and y[2m+1] = rq31(2 · A) with A = Σt=0…T−1 ht[t] (x[mirror(m−t, n)] + x[mirror(m+1+t, n)]) in int64, rq31(a) = (a + 230) >> 31.
Decimation by 2 (section 10.4; input length n, output length ⌊n / 2⌋): y[i] = rq31(x[2i] · 230 + Σt=0…T−1 ht[t] (x[mirror(2i−1−2t, n)] + x[mirror(2i+1+2t, n)])), with one rounding per output sample; because integer accumulation is exact the order of summation is irrelevant.
All of these sums are 64-bit two’s complement and wrap.
64-bit wrap (since 2026-11-15). The value bounds of sections 8.3 and 9.4 do not exclude int64 overflow in the accumulators (|B| can exceed 234 FU for |D| ≤ 1,073,741,823; the absolute values of the taps of table 0 sum to more than 230; the worst case of interpolation exceeds 263).
All sums and products in the interpolation, the mix with the frequency layer, the decimation and the final rounding are therefore computed modulo 264, with arithmetic right shifts, so that for a damaged stream that no other check detects every decoder gives the same wrapped value. The reference decoder does not detect such a wrap, and a bound below which valid streams cannot wrap is not yet stated (Appendix C, item 5).
- Base signal per channel: B[i] = 4096 · x[i] − δ[i] + 16 · D[i] for the padded index i in 0 to
nb− 1, where x is the edge sample, the CD sample or the trailing edge sample, D is the depth signal (omitted in the 16-bit route) and δ is regenerated dither: two xorshift32 generators (g ^= g << 13, ^= g >> 17, ^= g << 5), seeded 0x12345678 for the left and 0xB06BD031 for the right, advance twice for every index; with u1 and u2 the top 12 bits of the two results, δ = u1 + u2 − 4096 when the block’s dither flag (4096 samples a block) is not 0, else 0. - Interpolate
stagestimes with tables 0, 1, … to the master rate. - Frequency layer: from the M and S signals m and s (in 24-bit steps) r = m − (s >> 1), left = 16 (r + s), right = 16 r, added to the interpolated signal for the indices i from 0 to
Lp− 1,Lp=Lm+ 2P(section 11.4 and 11.5). With no S plane selected s[i] = 0. With no M stream selected the frequency layer F is 0. The interpolated signal U has lengthnU=nb· 2stagesand the mix is Z[i] = (i <nU? U[i] : 0) + F[i]: U counts as 0 beyondnU. The frequency layer is added in the time domain. - For an output rate of master / 2d, decimate d times with tables
stages− 1 − k; the cd24 route outputs B itself. - Output: sample i of the output is clamp((Y[
Po+ i] + 8) >> 4, −8,388,608, 8,388,607), withPo=P>> d and Lm >> d samples (cd24:pbandnb− 2pb).
Base signal details (section 11.2). The dither generators advance by two steps for every index, the padding and the blocks whose flag is 0 included; the result δ is triangular-PDF dither in [−4096, 4094] FU (about ±1 LSB16). The CD sample xc[i] is edge[2i + c] for i < pb;
cd[2(i − pb) + c] for pb ≤ i < pb + ncd; and edge[2pb + 2(i − pb − ncd) + c] otherwise, where cd is the interleaved int16 data of the CD layer. In the 16-bit route the term 16 · D is omitted and the dither is still subtracted.
Decimation step k = 0 … d − 1 uses table stages − 1 − k; interpolation stage k uses table k. All signals are per channel (0 = L, 1 = R), in FU and in int64.
| Route | d | Output rate | Offset Po | Length Lo |
|---|---|---|---|---|
| 24-bit, 16-bit | 0 ≤ d < stages | rate >> d | P >> d | Lm >> d |
| cd24 | — | base | pb | nb − 2pb (= ncd) |
For the 24-bit and 16-bit routes a requested output rate that is not of the form rate >> d with 0 ≤ d < stages must be rejected (section 11.1).
Routes. 24-bit: CD + depth + frequency layers at master / 2d, 0 ≤ d < stages; 16-bit: without the depth layer (the output is still 24-bit samples); cd24: CD + depth layer at the base rate.
In the 24-bit and 16-bit routes the frequency streams with k0 ≥ 512 >> d are not decoded.
The output file (section 11.8)
The output of a route is a canonical WAV file: a 44-byte header followed by Lo stereo frames. Each frame holds o0[i] then o1[i], and each value is written as
3 little-endian bytes, the low 24 bits of its two’s-complement representation. With D = 6 · Lo (the conformance hashes of Appendix B cover this file, byte for byte):
| Offset | Content |
|---|---|
| 0 | RIFF |
| 4 | uint32 36 + D |
| 8 | WAVE |
| 12 | fmt |
| 16 | uint32 16 |
| 20 | uint16 1 (PCM) |
| 22 | uint16 2 (channels) |
| 24 | uint32 output rate |
| 28 | uint32 6 × output rate |
| 32 | uint16 6 (block align) |
| 34 | uint16 24 (bits) |
| 36 | data |
| 40 | uint32 D |
| 44 | sample data, D bytes |
D is always even, so no pad byte follows. If 37 + D > 0xFFFFFFFF the output cannot be represented as WAV and must be refused (this is the size check of the reference writer, which allows for one pad byte). The 16-bit route also produces a 24-bit file.
Error handling (section 12)
The CD layer is ordinary PCM and is never affected by an error in the extension. When a decoder refuses to decode the extension, a player should fall back to playing the CD layer as 16-bit audio. A decoder must remain memory-safe for every input: the reference decoder validates every header field before using it to address data and clamps out-of-range decoded values.
| Condition | Required behaviour | Reference exit status (informative) |
|---|---|---|
| Self-test failure (section 13; the reference decoder runs it before reading the input) | Must not decode | 4 |
Not a RIFF/WAVE file; no data chunk; not 16-bit two-channel integer PCM (WAV form) | Not an LAE Lossy file; must not decode | 1 |
No LAE chunk, or one with an empty body | Plain CD audio; no extension to decode | 1 |
| Body shorter than 8 bytes, or CRC mismatch (V1) | Must refuse before parsing any field (other than the format identifier) | 3 |
First 4 bytes of the body are LAE2 (an LAES file; read before the CRC check) | Must not decode; reports an LAES file | 1 |
Magic or version not LAE1 / 5 (V2) | Must not decode (unknown version) | 1 |
| Any of V3 to V11 fails | Must refuse | 3 |
| V12 fails (dither flags) | Must refuse | 3 |
| V13 fails (CD length differs: edited or misaligned CD layer) | Must refuse | 3 |
| Output rate invalid for the route (section 11.1); checked after V13, before the stream records | Must refuse | 1 |
| A pack number k ≥ 1 for which the file has no pack record (section 5.6) | Must refuse the request | 1 |
| FLAC form: a failed frame check or a missing or wrong MD5 (section 3.4) | Must not decode the extension | 3 |
A stream record outside the payload; a decoded stream header invalid (section 5.3); nseg outside 1 to 8 | Must refuse | 3 |
| A stream that does not end exactly at its last byte (section 6.7) | May refuse; liblae refuses (since v5-2026-11-07), as do lae_dec and the Java decoder (since 2026-11-15) | 3 |
| Output exceeds the WAV size limit (section 11.8) | Must refuse | 1 |
CORRUPT raised during decoding (sections 7.4, 7.5, 8.3, 9.4) | Must report the stream as corrupt and must not deliver the output (the reference decoder deletes the file it has written) | 3 |
The reference decoder also contains two encoder-only hooks, LEAKOUT and CLIPMAP, compiled in only when the encoder builds the decoder; they are not part of the format.
Self-test and conformance vectors
Section 13 gives a self-test that catches a build that does not follow the arithmetic: the 3,584 coefficients X[i] = (⌊(i · 2654435761 mod 232) / 128⌋ mod 2,000,001) − 1,000,000 go through the inverse MDCT with Ls = 3072 (7 frames), and the 64-bit FNV-1a-style hash of the 3,072 outputs (initial value 0x14650FB0739D0383, prime 1099511628211, over the little-endian bytes) must be 0x729B547FBDBFE203. A decoder that gets another value must not decode.
Appendix B lists 16 conformance vectors (four synthetic signals at 88.2, 96, 176.4 and 352.8 kHz, each in four modes) with the SHA-256 of the output WAV file of every route (24-bit, 16-bit, cd24, and 24-bit at half the master rate where there are two or more stages). The viewer’s decoder
reproduces all 56 listed outputs and the 16 encoded files’ hashes exactly (see below). Items the specification itself marks as open (Appendix C: the tables as an annex, the fmt rate check, whether CORRUPT must be found in unused parts, reserved rule values, an overflow bound) do not change what decodes.
Extension packs and the name record
Pack 0 is the main body above. Up to eight further packs may follow the last S record; each is a full
container payload built from a different master against the same CD layer, with its own
rate, stages, Lm and streams but the same base, and
must not itself contain packs.
| Offset | Bytes | Type | Content |
|---|---|---|---|
| 0 | 4 | bytes | The tag LPAK |
| 4 | 4 | uint32 | n ≥ 1: the bytes that follow this field |
| 8 | 1 | uint8 | nl, the name length |
| 9 | nl | UTF-8 | The pack’s name, for display only |
9 + nl | n − 1 − nl | bytes | The pack payload: a container payload from its magic to the end of its last S record, with no CRC of its own (at least 52 bytes) |
A reader reads pack records while at least 9 bytes remain, the tag is LPAK, the record fits,
1 + nl + 52 ≤ n, the payload starts with magic LAE1 and version 5, and its
base equals pack 0’s; the first failure ends the list without an error, and at most 8 are read.
After the last pack (or the last S record if there is none) an optional name record may follow:
the tag LNAM, a uint8 nl and that many UTF-8 bytes naming pack 0. Nothing may
follow it. The single CRC-32 covers everything, packs included.
Pack rules (section 5.6)
- The packs are mutually independent: nothing in one pack refers to, predicts from or shares a parameter with another, and removing a pack record leaves every other pack decodable and unchanged. A decoder decodes the CD layer with exactly one pack.
- A pack payload must satisfy every rule of the main header and stream sections by itself. Its
basemust equal pack 0’s; itsrate,stages,Lm,fc, modes and streams are its own. V13 applies to it with the CD layer of the file:ncd=nb− 2pb. - A pack payload must not contain pack records. An encoder must not write anything between pack records and must not write more than 8. A pack record carries nothing else: no offsets, delays, gains, time stamps, hashes, position tables or type codes, and every record has the same tag.
- The name record, like every name, is for display only: it selects nothing and no meaning is attached to it. A pack name is stored only in the payload and must not be repeated in tags or in any other container-level structure.
A decoder reads the name record after the pack list: the next four bytes are
LNAMand at least 1 +nlbytes follow them before the CRC. A decoder that does not know it ends its pack list at the same place and ignores it. - Decoding with a pack number k (the caller’s; the default is 0): (1) verify the CRC (V1) and locate the end of the last S record of pack 0 by walking the 52-byte header, the
8·pbedge bytes,ndfand the dither flags, the two depth records,nsegand the 2 ·nsegfrequency records, checking each length against the payload; (2) from there read pack records under the rules above, the first failing record ending the list without an error, at most 8; (3) k = 0 decodes pack 0 as specified; k ≥ 1 with fewer than k records in the list rejects the request, otherwise the pack payload is decoded unchanged with the CD layer of the file. - A decoder must not combine streams of different packs and must not choose a pack by itself: not by device capability, network, load, loudness, content or any field of a record. The user chooses (a menu, a setting or an argument); the name never drives any processing; and a decoder must not write the choice back into the file.
A player should list each pack with its
rateand its name. The output rate by octave and the three routes apply within the chosen pack. - A decoder that does not support packs is a conforming version 5 decoder: it decodes pack 0 and ignores the bytes after its last S record. In the FLAC form the pack records are part of the extension split over the
LAE1blocks; nothing else changes.
What the viewer shows
The FLAC viewer reads the LAE1 blocks as one payload (for the layout and the sound it is read from the file by range and never joined in memory, so its size has no limit; only saving it as a file, the “lae1 payload” entry, joins it), checks the CRC-32, and lays the main header, edge
samples, dither flags, every stream record with its stream header, every pack (with its own header and
streams) and the name record over the block slices as tree nodes. It checks V1 to V13 and the rules of
the FLAC form (STREAMINFO, no SEEKTABLE or CUESHEET, consecutive blocks, independent channels in
every frame), and its report compares STREAMINFO’s MD5 with the decoded CD layer.
The range-coded data of every stream is decoded. Inside a stream’s Range-coded data node the tree lays out the syntax: the decoder’s start, then each row, root block, split flag, cut and leaf with its tier, exponent, zero level and coefficient summary (how many coefficients, how many are not zero, the largest magnitude). A range coder gives a symbol no whole bytes of its own, so a node covers the coded bytes the decoder fetched while it decoded that element; most small elements therefore cover 0 bytes and the bytes appear at the element that caused the decoder to read them. Nothing is left out and nothing is cut off at a size: the whole of every stream is read once, in order, when the file is opened, which gives the exact totals and keeps the state of the range decoder (its registers, the adaptive probabilities and the previous tier and exponent) at a checkpoint every 256 rows or megabyte of coded data. The tree is made from the checkpoints as it is opened: a stream with more than 256 rows shows runs of rows (and, for a very long stream, runs of runs), a run lists its rows, and a row shows its root blocks, cuts and leaves; opening one of them reads only the stretch between the nearest checkpoint and that row. The tables LAE Lossy streams (rows, leaves, share of the four tiers, exponent range, non-zero coefficients, and whether the stream ends at its last byte) and LAE Lossy bands (per root-block column: tier shares, mean exponent, non-zero share) come from the one pass and are exact, and LAE Lossy partitions (every leaf of every stream in decoding order, with no cap) is paged: the leaves are counted in the pass, and a page of rows is worked out when it is asked for, from the checkpoint before it. A payload of several gigabytes is therefore opened with the memory of one window of coded bytes and the checkpoints (about 12 KB each), and the time of reading it once.
The viewer makes the sound from the payload and the FLAC audio, both read as it goes: the 24-bit route at the master rate, the 16-bit route, the cd24 route, the 24-bit route at each lower octave, and the 24-bit master-rate sound of each extension pack. It does so only when the specification allows it (CRC-32 right, STREAMINFO’s MD5 present and equal to the MD5 of the decoded CD layer, independent channels in every frame, every FLAC frame CRC right); otherwise the section says why it does not. The sound has no length limit: the decoder works in order, a piece at a time (the dither generator, the inverse MDCT and its overlap, the half-band filters with their mirrored ends, the mix and the limiter all go forward), so the memory it holds does not grow with the length of the signal, and the waveform, the levels and playback read it as a stream; a read back before the place the decoder has reached starts it again from the beginning. The arithmetic is the specification’s (see above); the self-test of section 13 runs before every decode. CORRUPT conditions and a stream that does not end exactly at its last byte are reported as problems on the stream, and in the report. Section 12 says the output of a stream with a CORRUPT condition must not be delivered, so before any sound of a route is handed out the route is read once to its end (the result is kept and the report uses it): a route with a CORRUPT condition in any stream it uses makes no sound at all, in every route, and its sound section shows the reason; a route that does not use the damaged stream (the 16-bit route does not use the depth streams, the cd24 route not the frequency streams) is not affected.
What else it reports. K has no upper bound in the specification (it should equal the number of frames of the plane’s signal; a larger one is never used, a smaller one leaves the missing frames zero), so the viewer applies none: a K that differs from that number is reported on the field, and a stream whose coded payload runs out before the last row is reported as one that does not end at its last byte (section 6.7).
An LAE1 block with no data adds nothing to the joined payload and is reported on its block; if every LAE1 block is empty the payload is 0 bytes, shorter than 8 (V1), and the extension is not used. A file whose LAE1 blocks carry a payload that begins with the magic LAE2 is an LAES payload under the wrong block ID: the viewer says so, reads it as LAES and does not decode it as LAE Lossy (section 3.4).
The end check and the CORRUPT check of every stream come from the same one pass that makes the checkpoints, whatever the size of the payload. The 16-bit FLAC layer is not decoded whole into memory either: its frames are decoded one at a time with the FLAC frame decoder as the sound asks for samples.
Verification. The decoder reproduces the SHA-256 of all 56 output files of the 16 conformance vectors of the specification’s Appendix B, and the SHA-256 of each of the 16 encoded files; the 24-bit, 16-bit and cd24 sounds of one vector carried in a FLAC file are equal to the manifest’s through the viewer. The MDCT constants above were compared value by value with the reference header.
Sources
- LAE Lossy specification –
spec/lossy/SPEC.md, tagv5-2026-11-19, sections 3.3 to 13 and Appendix B (conformance vectors,tests/vectors/MANIFEST.md); the table values come from the reference headersrc/mdct_tables.handsrc/halfband.hof the same tag - RFC 9639 section 8.4, APPLICATION