This page lists what the LAE Lossy reference encoder does that the decoder never needs. It is informative: none of it affects decoding, and a decoder written from the
LAE Lossy payload page does not need it. It explains why the bitstream is shaped as it is. Unless another source is named, the statements come from the
reference encoder sources (src/lae_enc.cpp, src/partition.h, tools/reference/pad_mirror.cpp, src/base_layer.cpp, tools/reference/routes.cpp).
Source: LAE Lossy specification, spec/lossy/SPEC.md, tag v5-2026-11-19, section 14 (informative). “FU” is the fine unit, 1/16 LSB24, of section 2.4; stages and base are main-header fields.
Layer targets
The decoder adds the three parts (CD path, depth layer, frequency layer) in the time domain (section 11). The encoder derives the CD layer from the master and adds TPDF dither in the blocks flagged in the dither flags.
- CD layer derivation (
src/base_layer.cpp). The padded master is converted to FU and decimatedstagestimes to the base rate with the integer half-band decimators, highest-rate stage first; intermediate values are limited only to theint32range. With x the decimated value in FU and delta the regenerated dither (0 in blocks whose flag is 0), each CD sample isclamp((x + delta + 2048) >> 12, −32768, 32767). - Dither decision (
src/base_layer.cpp). For each channel and each block of 4096 base-rate samples the encoder fits a 16th-order linear predictor to the decimated signal and computes the RMS of the prediction residual in LSB24. The block is dithered if this RMS is below 128 LSB24 (0.5 LSB16) and the block is not digital silence. All-zero blocks are never dithered, so the CD layer keeps true zeros. - Depth target (
tools/reference/routes.cpp). Let v = 256 · CD − delta / 16 be the CD path in LSB24 and B24 = (x + 8) >> 4 the decimated master in LSB24, which is not limited to full scale. The depth target is T = llround(lowpass(B24 − v)), limited to [−8,388,608, 8,388,607]. The lowpass is a zero-phase windowed-sinc FIR filter at the base rate (511 taps, Kaiser window β = 9) with cut-off fc; it is omitted when fc ≥base/2 − 1 Hz. The depth layer covers the base-rate band. - Frequency target (
tools/reference/routes.cpp). In LSB24 at the master rate, F = master − up(v + T), limited to [−8,388,608, 8,388,607].upinterpolates by 2,stagestimes, with the half-band tables; the encoder computes it in double precision. The frequency layer starts below the detected CD cut-off: the encoder passes a start frequency of fc − 1000 Hz to the layer coder (src/lae_enc.cpp), andfcrecords the cut-off. - Cut-off detection (
tools/reference/routes.cpp). From averaged cross-spectra of the master and the interpolated CD path, the encoder scans downwards from the base-rate Nyquist frequency to 15 kHz. It sets fc just above the highest frequency at which the transfer of the CD path is at least −0.1 dB. Bins in which the master has almost no energy are skipped. If no such frequency is found, fc = 15,000 Hz.
Independent CD input
The encoder option cd=<file> accepts a separately supplied 16-bit two-channel CD at the base rate.
- The supplied CD becomes the CD layer bit for bit. The encoder places the master on the time axis of the CD and moves the master by whole master samples and by a fraction of a master sample; the CD is never moved. Nothing about the alignment is stored in the file, and decoding is unchanged.
- All dither flags are then 0.
- The CD cut-off is found by a coherence test (threshold 0.98) instead of the transfer test; the coherence test does not depend on the gain of the CD.
- The extension codes the master minus the CD path.
- The edge samples are still taken from the CD layer that the encoder derives from the master.
Extension packs
The reference encoder takes further masters as master2=<file> … master9=<file>, each with master<n>align=<offset> (its position on the time line of the CD layer, written like cdalign=) and, optionally, master<n>name=, master<n>accept and master<n>edge=pad|cut. The container side is on the payload page.
- The CD layer is derived from the first master or, with
cd=, is the given CD (the first master is then aligned to it as before). Every further master is aligned to this CD layer by the alignment of the independent CD input, each one separately. Where an alignment needs digital silence before or after the CD layer, the largest need of any master is added to the CD layer once, and the same silence is added to every master. The samples of the CD layer itself are never changed. - Each aligned master is then encoded against the final CD layer in a run of its own. Its pack payload is byte for byte the payload that
lae_enc <that master> cd=<the CD layer> cdalign=0writes. Pack 0 and the CD layer are what the encoder writes without further masters for the same CD layer. master1name=<name>(at most 255 bytes) names the main body: the encoder writes the main-body name record after the last pack record. Without this option nothing is written and the output is unchanged. It may be used without further masters.master<n>part2=…master<n>part5=(n = 1 … 9; since 2026-11-18) are optional positions 2 to 5 of a name: free text without a fixed meaning. The encoder joins the filled ones after the name as<name> - <part2>, <part3>, <part4>, <part5>(empty ones left out; without a name, the rest alone, joined by,) and writes the result as the name of that pack (n = 1: the main body). Name and positions together are at most 255 bytes. The file holds only the joined text: nothing in the pack layout changes, no position is marked, and a decoder shows the name as it is and never splits it. The output is byte for byte the file written with the joined text given asmaster<n>name=.- In the present version, further masters cannot be combined with
noise=,resumeorcdcheck.
Form
The reference encoder writes the FLAC form for an output name ending in .flac or with the option --form=flac, and the WAV form otherwise (also for .lae). --form=wav or --form=flac must agree with a .wav or .flac name; only .lae leaves the choice open. The WAV form is byte-identical to the output of the encoder before the FLAC form was added. lae_enc tag writes new tags without re-encoding and keeps the form.
Partition search
From src/partition.h.
- The search runs per root block, in parallel. The number of threads does not affect the encoded stream.
- The search aims at the D and C share targets of the selected mode (
src/partition_format.h). The share targets exist only in the encoder. The decoder needs no mode table: apart from the range check ofmi(V10),mi,lv,wmand the main-headereqare informational. - For given penalties λD and λC, a dynamic program over all sub-rectangles of each root block chooses the cut tree and the tier of each leaf. It minimises the estimated number of bits plus λD per demoted D unit (a D cell in a leaf below tier D) and λC per demoted C unit (a C cell in a leaf below tier C). A unit is one cell (share by cells), the cell’s energy relative to the mean energy of all D (or C) cells of the plane (share by energy), or the mean of both (cells + energy). A leaf is tier A only if all its cells are A.
- The penalties are found by bisection on a logarithmic scale between 10−3 and 104, in 7 steps: first λC with λD = 0, until the C share target is met, then λD. For modes with a C share of 100 % (keep, keep20), λC is fixed at 109. With the share measure “cells + energy”, the smaller of the two shares must meet the target.
Modes
There are six modes per scheme (src/partition_format.h). The main header’s mi field holds the index.
| Index | Name | D share | C share | Note |
|---|---|---|---|---|
| 0 | max | 10 % | 30 % | |
| 1 | 1 | 30 % | 50 % | |
| 2 | 3 | 50 % | 70 % | |
| 3 | 5 | 70 % | 90 % | |
| 4 | keep | 90 % | 100 % | |
| 5 | keep20 | 90 % | 100 % | Depth layer with rule 3 (opt-in, larger file) |
Scheme 1 uses rule 1 for both layers. Scheme 2 uses rule 2 for the frequency layer and rule 1 for the depth layer.
Quantiser
The encoder uses scalar quantisation with a dead zone. A coefficient x of a leaf with step 2s is quantised to q = sign(x) · ⌊|x| / step + 0.5 − 0.30⌋. The dead zone 0.30 is used by the encoder only and is not signalled. The decoder reconstructs (|q| + 0.20) · step with the sign of q; the reconstruction offset 0.20 is a format constant (section 8.3).
Leakage compensation
The encoder obtains the decoded frequency layer, brought down to the base rate with the decimators of section 10 (the LEAKOUT hook of src/lae_dec.cpp), and uses it to compensate the depth target.
- After a first complete encode, the encoder decodes the written file and obtains the frequency layer alone at the base rate.
- It filters this leakage with a zero-phase windowed-sinc lowpass (2047 taps, Kaiser window β = 9) with cut-off fc − 1150 Hz, 150 Hz below the start of the frequency layer, and subtracts the result from B24 − v before the depth target is formed. The cut-off fc of the first pass is kept.
- Only the depth layer is then re-encoded, and the file is written again. The frequency layer of the first pass is kept.
- Leakage compensation is always on in container version 5.
Clipping and analysis
- Clipping. The only output protection is the decoder’s final hard limiter. The reference encoder runs one diagnostic decode with the
CLIPMAPhook and reports how many samples the limiter affects. This report is not stored in the file. - Signal analysis. The encoder’s analysis uses the FFT module
src/fft.h. The inverse MDCT of section 9.3 is implemented separately, insrc/mdct_tb.h.