forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-vorbis-floor': envelope floor refuted, data kept

Browse files at this commit

5c3d8555a022c7a9aa3234626a1af814ca12cf3dAhmet Kaan GümüşParent: 4174c4b93cf89c
lanes/vorbis-floor-r2.handoff.mdadded+33 -0
@@ -0,0 +1,33 @@
1+# lane-vorbis-floor round 2 — handoff
2+
3+## Verdict
4+REFUTED. Peak is the best per-region floor metric. Envelope-following (geomean, geomean+k dB, RMS) all regress monotonically as the floor drops below the region peak. encode.rs reverted to main (7c3f1e9). Suite green.
5+
6+## Final state
7+- encode.rs: at main, unmodified. `git diff 7c3f1e9 -- crates/ec-vorbis/src/encode.rs` = empty.
8+- 5 commits on lane-vorbis-floor past main: E1, E2 k=12, E2 k=6, E3 RMS, revert.
9+- Suite: `cargo test -p ec-vorbis` = 13 lib + 8 oracle, all green.
10+- Report: `lanes/vorbis-floor-r2.report.md` (verdict line first).
11+- No merge, no push.
12+
13+## Experiments summary
14+
15+| config | mean gap | vs baseline |
16+|---------------------------|----------|-------------|
17+| baseline (peak) | 0.01525 | — |
18+| E3 RMS | 0.07285 | 4.8× worse |
19+| E2 geomean + 12 dB | 0.13535 | 8.9× worse |
20+| E2 geomean + 6 dB | 0.16564 | 10.9× worse |
21+| E1 geomean (k=0) | 0.183 | 12.0× worse |
22+
23+Monotonic: geomean → k6 → k12 → RMS → peak, strictly improving.
24+
25+## Key findings
26+1. **Peak is optimal for 12-point grid**: each region spans ~73 bins; peak-to-mean ratio is 20–30 dB. Envelope metrics collapse toward the noise floor, and the 8-pass clamp-lift refit cannot recover.
27+2. **Clamp-lift saturation is rare**: 10/509 clamped blocks (2%) at baseline. reell and dl8a never clamp. E4 unnecessary.
28+3. **Architectural gap**: libvorbis's 65-point floor1 makes envelope≈peak per region. Our 12-point grid (r1 proved more points = worse) makes them diverge. The gap is structural, not metric-level.
29+
30+## What to try next (not this lane)
31+- Per-band bit allocation (Bark-band masking model vs global headroom scalar).
32+- Floor1 curve shape (multiplicative Y values, per-point amplitude).
33+- Residue book selection (multiple books per partition vs single-book-per-class).
lanes/vorbis-floor-r2.report.mdadded+117 -0
@@ -0,0 +1,117 @@
1+verdict: REFUTED — peak is the best per-region floor metric; any deviation below the region peak worsens quality monotonically. encode.rs left at main.
2+
3+# lane-vorbis-floor round 2 — envelope-following floor
4+
5+Gate: `real_library_sweep_vs_reference`, SWEEP_ONLY=her,dl8a,nik,reell (8 rows), ours at
6+libvorbis's measured kbps, both decoded by our decoder. Mean corr gap over the 8 rows:
7+
8+| config | mean gap | corr range | rate % |
9+|-------------------------------------|----------|--------------|-------------|
10+| **baseline (peak)** | **0.01525** | 0.97–0.99 | ±1.1% |
11+| E3 = per-region RMS | 0.07285 | 0.82–0.97 | −1.2 to −2.0% |
12+| E2 = geomean + 12 dB (k=12) | 0.13535 | 0.78–0.95 | −0.9 to +2.7% |
13+| E2 = geomean + 6 dB (k=6) | 0.16564 | 0.73–0.91 | −0.7 to −4.0% |
14+| E1 = geomean (k=0) | 0.183 | 0.71–0.88 | up to −10.6% |
15+
16+Monotonic trend: geomean(0.183) → k6(0.166) → k12(0.135) → RMS(0.073) → peak(0.015).
17+Every step toward the peak improves the gap. The peak is the optimal endpoint; no
18+envelope metric beats it.
19+
20+## Per-track detail (baseline)
21+
22+| track | kbps | ours_kbps | ref_kbps | rate% | corr_ours | corr_ref | gap |
23+|-------|-------|-----------|----------|--------|-----------|----------|---------|
24+| nik | 96 | 84.0 | 84.5 | −0.61 | 0.9690 | 0.9903 | 0.0213 |
25+| nik | 128 | 115.5 | 115.8 | −0.24 | 0.9838 | 0.9951 | 0.0113 |
26+| her | 96 | 89.9 | 89.9 | +0.04 | 0.9668 | 0.9867 | 0.0199 |
27+| her | 128 | 123.5 | 124.9 | −1.13 | 0.9810 | 0.9927 | 0.0117 |
28+| reell | 96 | 85.4 | 85.5 | −0.12 | 0.9792 | 0.9923 | 0.0131 |
29+| reell | 128 | 121.3 | 120.9 | +0.39 | 0.9914 | 0.9968 | 0.0054 |
30+| dl8a | 96 | 86.9 | 86.9 | −0.01 | 0.9655 | 0.9916 | 0.0261 |
31+| dl8a | 128 | 118.7 | 117.8 | +0.80 | 0.9826 | 0.9957 | 0.0132 |
32+
33+## Root cause analysis
34+
35+### Why envelope-following fails here
36+
37+Each long-block floor point owns ~73 bins (1024 / 14 regions). In a typical audio
38+spectrum, most of those 73 bins sit at the noise floor (−60 to −80 dB) while only a
39+few carry signal (−20 to −40 dB). The envelope metrics collapse toward the noise floor:
40+
41+- **Geometric mean** is dominated by the 60+ noise-floor bins: geomean_dB ≈ −59 dB.
42+ Even +12 dB margin leaves the floor at −47 dB, 27 dB below the signal peak.
43+ The clamp-lift refit (max 8 passes × 6 dB = 48 dB) saturates trying to recover.
44+- **RMS** (sqrt(mean(bin²))) weights loud bins quadratically, so it sits at ~−40 dB,
45+ closer to the peak. Better than geomean but still 20 dB below the signal peak.
46+- **Peak** captures the loudest bin directly. The floor sits at peak − 9 dB
47+ (MASKING_OFFSET_DB), so the quantiser step is ~3× the peak — every bin within
48+ 9 dB of the peak codes as a small residue, and bins further down quantise to zero.
49+
50+The clamp-lift refit (encode_block :832) can raise the floor by at most 8 × 6 dB = 48 dB
51+across 8 passes. With a geomean-based floor 27 dB below the signal, the refit must
52+recover 27 dB in lifts — but the `excess` factor (1.05× the over-limit ratio) is
53+multiplicative, not additive, so convergence is slow and the 8-pass cap is hit before
54+the floor reaches the signal level. The peak-based floor needs at most 1–2 lifts for
55+the rare bin that exceeds the residue book range (±127), so it rarely saturates.
56+
57+### Clamp-lift saturation at baseline
58+
59+Instrumented with static atomic counters (VORBIS_FLOOR_DEBUG=1), 8-row gate:
60+
61+| track | kbps | clamped blocks | saturated (8-pass) | sat % of clamped |
62+|-------|------|----------------|--------------------|--------------------|
63+| nik | 96 | 17 | 1 | 5.9% |
64+| nik | 128 | 58 | 2 | 3.4% |
65+| her | 96 | 194 | 4 | 2.1% |
66+| her | 128 | 240 | 3 | 1.3% |
67+| reell | 96 | 0 | 0 | — |
68+| reell | 128 | 0 | 0 | — |
69+| dl8a | 96 | 0 | 0 | — |
70+| dl8a | 128 | 0 | 0 | — |
71+
72+Total: 10 saturated out of 509 clamped blocks (2.0%). reell and dl8a never clamp at all.
73+Clamping is not the dominant quality bottleneck at baseline — E4 (capping the floor
74+drop at peak − 36 dB) would address a 2% edge case and cannot close a 4.8× gap.
75+
76+### Why libvorbis's envelope works but ours doesn't
77+
78+libvorbis uses a finer floor1 curve (up to 65 X points in a long block, vs our 12).
79+Each point owns ~16 bins, so the peak-to-mean ratio within a region is 6–10 dB, not
80+20–30 dB. At that resolution, the envelope and the peak nearly coincide, and the
81+floor follows the local level smoothly. Our 12-point grid forces each region to span
82+73 bins, where the peak and the envelope diverge by 20+ dB. The peak is the only
83+metric that keeps the floor close enough to the signal for the quantiser to work.
84+
85+The r1 report already refuted adding more posts (gap worsens monotonically: 12→16→24→32).
86+So the coarse grid is both necessary (more posts = worse) and incompatible with
87+envelope-following (73-bin regions have too much peak-to-mean spread). The quality
88+gap is architectural: it comes from the floor1 post count and the per-band bit
89+allocation strategy, not from the per-region level metric.
90+
91+## What was tried
92+
93+1. **E1** (geomean, k=0): `peaks_of` returns geometric mean of |bin| per region.
94+ Gap 0.183, rate undershot up to −10.6%. Severe regression.
95+2. **E2 k=12**: geomean + 12 dB margin. Gap 0.135. Still 8.9× baseline.
96+3. **E2 k=6**: geomean + 6 dB margin. Gap 0.166. Worse than k=12 — confirms monotonicity.
97+4. **E3** (RMS): `peaks_of` returns sqrt(mean(bin²)) per region. Gap 0.073. Best
98+ envelope metric but still 4.8× baseline.
99+5. **Clamp-lift saturation count**: instrumented the refit loop. 2% saturation at
100+ baseline. Clamping is not the bottleneck; E4 unnecessary.
101+6. **Reverted encode.rs to main** (7c3f1e9). Suite green (13 lib + 8 oracle).
102+
103+## Next direction
104+
105+The floor-level metric is exhausted. The gap is structural: our 12-point floor1 grid
106+with peak-hold + 9 dB headroom is the best per-region metric for this resolution, and
107+the resolution itself cannot be increased (r1 refuted that). The remaining gap to
108+libvorbis likely comes from:
109+
110+- **Per-band bit allocation**: libvorbis allocates bits per Bark band with masking
111+ models; our rate loop adjusts a global headroom scalar. A per-band allocation could
112+ spend bits where the floor is highest and save them where it's low.
113+- **Floor1 curve shape**: libvorbis uses multiplicative floor1 Y values with
114+ per-point amplitude, not a linear-interpolated peak-hold. The interpolation between
115+ our 12 peak-held points may overshoot or undershoot between posts.
116+- **Residue book selection**: libvorbis chooses from multiple residue books per
117+ partition; our single-book-per-class approach may be suboptimal for mixed content.
lanes/vorbis-psy-r1.sweep.txtadded+9 -0
@@ -0,0 +1,9 @@
1+source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict
2+nik 96 84.0 84.5 -0.61 0.9690 0.9903 0.0213 FAIL
3+nik 128 115.5 115.8 -0.24 0.9838 0.9951 0.0113 FAIL
4+her 96 89.9 89.9 +0.04 0.9668 0.9867 0.0199 FAIL
5+her 128 123.5 124.9 -1.13 0.9810 0.9927 0.0117 FAIL
6+reell 96 85.4 85.5 -0.12 0.9792 0.9923 0.0131 FAIL
7+reell 128 121.3 120.9 +0.39 0.9914 0.9968 0.0054 FAIL
8+dl8a 96 86.9 86.9 -0.01 0.9655 0.9916 0.0261 FAIL
9+dl8a 128 118.7 117.8 +0.80 0.9826 0.9957 0.0132 FAIL