forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-vorbis-floor': headroom tilt closes vorbis equal-size gap on 11/14 rows

Browse files at this commit

53efef071733ede3ae46f42f1fc65b95dc786d0eAhmet Kaan GümüşParent: 5c3d855fbafcda
crates/ec-vorbis/src/encode.rsmodified+60 -6
@@ -123,6 +123,37 @@ const CO_MASK_RANGE_SHORT: f64 = f64::INFINITY;
123 const POINT_STEREO_HZ: f64 = 4_000.0;123 const POINT_STEREO_HZ: f64 = 4_000.0;
124 /// Least headroom a short block is quantised with, whatever the rate loop's.124 /// Least headroom a short block is quantised with, whatever the rate loop's.
125 const HEADROOM_SHORT_MIN: f64 = 42.0;125 const HEADROOM_SHORT_MIN: f64 = 42.0;
126+/// Per-post headroom tilt (dB): extra headroom below `TILT_LF_LO_HZ` so the
127+/// floor sits lower at low frequencies — finer step, more bits where the ear
128+/// is sensitive and the reference spends. Tapers to 0 by `TILT_LF_HI_HZ`.
129+/// `TILT_HF_DB` (negative) trims step resolution above `TILT_HF_HI_HZ`,
130+/// routing those bits to LF. The rate loop's global headroom rebalances the
131+/// total. Tuned by lanes/vorbis-floor-r3.report.md (8-row sweep).
132+const TILT_LF_LO_HZ: f64 = 1_100.0;
133+const TILT_LF_HI_HZ: f64 = 2_000.0;
134+const TILT_HF_DB: f64 = -3.0;
135+const TILT_HF_LO_HZ: f64 = 4_000.0;
136+const TILT_HF_HI_HZ: f64 = 6_000.0;
137+const TILT_LF_DB: f64 = 12.0;
138+/// Extra headroom (dB) for one floor post at `hz`: LF boost tapering to 0,
139+/// plus an HF cut (negative) tapering in. Zero outside both bands.
140+fn headroom_tilt(hz: f64) -> f64 {
141+ let lf = if hz <= TILT_LF_LO_HZ {
142+ TILT_LF_DB
143+ } else if hz < TILT_LF_HI_HZ {
144+ TILT_LF_DB * (TILT_LF_HI_HZ - hz) / (TILT_LF_HI_HZ - TILT_LF_LO_HZ)
145+ } else {
146+ 0.0
147+ };
148+ let hf = if hz <= TILT_HF_LO_HZ {
149+ 0.0
150+ } else if hz < TILT_HF_HI_HZ {
151+ TILT_HF_DB * (hz - TILT_HF_LO_HZ) / (TILT_HF_HI_HZ - TILT_HF_LO_HZ)
152+ } else {
153+ TILT_HF_DB
154+ };
155+ lf + hf
156+}
126 /// Samples per transient-detection tick — the short block's own hop, so a157 /// Samples per transient-detection tick — the short block's own hop, so a
127 /// tick lines up with the finest time resolution the encoder has.158 /// tick lines up with the finest time resolution the encoder has.
128 const TICK: usize = BLOCK_SHORT / 4;159 const TICK: usize = BLOCK_SHORT / 4;
@@ -687,6 +718,20 @@ impl VorbisEncoder {
687 } else {718 } else {
688 MASKING_OFFSET_DB719 MASKING_OFFSET_DB
689 };720 };
721+ // Per-post frequency, headroom tilt, and (for HF) the RMS-vs-peak
722+ // choice: long blocks only — the rate loop's global headroom
723+ // rebalances the total bitrate. Short blocks get a flat zero tilt and
724+ // pure peak-hold (hz set to 0 so no post crosses the HF threshold).
725+ let post_hz: Vec<f64> = if plan.is_long {
726+ bc.floor
727+ .x_list
728+ .iter()
729+ .map(|&x| x as f64 * f64::from(self.config.sample_rate) / (2.0 * half as f64))
730+ .collect()
731+ } else {
732+ vec![0.0; bc.floor.x_list.len()]
733+ };
734+ let tilt: Vec<f64> = post_hz.iter().map(|&hz| headroom_tilt(hz)).collect();
690 let (floor_values, quantised) = loop {735 let (floor_values, quantised) = loop {
691 let mut curves: Vec<Vec<f32>> = vec![Vec::new(); channels];736 let mut curves: Vec<Vec<f32>> = vec![Vec::new(); channels];
692 let mut floor_values: Vec<Vec<i32>> = vec![Vec::new(); channels];737 let mut floor_values: Vec<Vec<i32>> = vec![Vec::new(); channels];
@@ -707,6 +752,7 @@ impl VorbisEncoder {
707 bc.co_mask,752 bc.co_mask,
708 masking_offset,753 masking_offset,
709 &peaks,754 &peaks,
755+ &tilt,
710 );756 );
711 let mut curve = vec![0.0f32; half];757 let mut curve = vec![0.0f32; half];
712 render_floor1(&bc.floor, &y, &step2, &mut curve);758 render_floor1(&bc.floor, &y, &step2, &mut curve);
@@ -928,7 +974,11 @@ impl VorbisEncoder {
928 ///974 ///
929 /// Each point owns the coefficients halfway to its neighbours either side, so975 /// Each point owns the coefficients halfway to its neighbours either side, so
930 /// the whole spectrum is covered exactly once and a peak between two points976 /// the whole spectrum is covered exactly once and a peak between two points
931-/// still raises the floor that has to carry it.977+/// still raises the floor that has to carry it. Peak-hold is used at every
978+/// frequency: per-region RMS was tried at HF (>6 kHz, r3 E3) but it lowers the
979+/// floor estimate, promoting noise-like HF bins to residue and regressing
980+/// correlation — peak-hold plus the HF headroom tilt zeros them instead, which
981+/// matches the reference. See lanes/vorbis-floor-r3.report.md.
932 fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec<f32>]) -> Vec<f64> {982 fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec<f32>]) -> Vec<f64> {
933 let x = &floor.x_list;983 let x = &floor.x_list;
934 x.iter()984 x.iter()
@@ -955,7 +1005,8 @@ fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec<f32>]) -> Vec<f64> {
955 /// Spread first (a masker covers its neighbours, with an extra Bark-local1005 /// Spread first (a masker covers its neighbours, with an extra Bark-local
956 /// near-band pass), then subtract the rate loop's headroom, then hold the1006 /// near-band pass), then subtract the rate loop's headroom, then hold the
957 /// absolute threshold of hearing as a lower bound: below it the residue1007 /// absolute threshold of hearing as a lower bound: below it the residue
958-/// quantises to zero and costs a class-0 partition.1008+/// quantises to zero and costs a class-0 partition. `headroom` is tilted per
1009+/// post by [`headroom_tilt`]: more at LF for a finer step, less at HF.
959 fn fit_floor(1010 fn fit_floor(
960 floor: &Floor1,1011 floor: &Floor1,
961 ath: &[f64],1012 ath: &[f64],
@@ -965,6 +1016,7 @@ fn fit_floor(
965 co_mask: f64,1016 co_mask: f64,
966 masking_offset: f64,1017 masking_offset: f64,
967 peaks: &[f64],1018 peaks: &[f64],
1019+ tilt: &[f64],
968 ) -> (Vec<i32>, Vec<bool>) {1020 ) -> (Vec<i32>, Vec<bool>) {
969 let db: Vec<f64> = peaks1021 let db: Vec<f64> = peaks
970 .iter()1022 .iter()
@@ -998,11 +1050,13 @@ fn fit_floor(
998 let target: Vec<f64> = spread1050 let target: Vec<f64> = spread
999 .iter()1051 .iter()
1000 .zip(ath.iter())1052 .zip(ath.iter())
1001- .map(|(&level, &threshold)| {1053+ .enumerate()
1054+ .map(|(i, (&level, &threshold))| {
1055+ let h = headroom + tilt[i];
1002 let threshold = threshold.max(loudest - co_mask);1056 let threshold = threshold.max(loudest - co_mask);
1003- let offset = (masking_offset - (headroom - range).max(0.0)).max(0.0);1057+ let offset = (masking_offset - (h - range).max(0.0)).max(0.0);
1004- (level - headroom.min(range) + offset)1058+ (level - h.min(range) + offset)
1005- .max(threshold - (headroom - range).max(0.0))1059+ .max(threshold - (h - range).max(0.0))
1006 })1060 })
1007 .collect();1061 .collect();
1008 let y: Vec<i32> = target1062 let y: Vec<i32> = target
lanes/vorbis-floor-r3.full.txtadded+16 -0
@@ -0,0 +1,16 @@
1+source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict
2+nik 96 83.5 84.5 -1.20 0.9863 0.9903 0.0040 PASS
3+nik 128 115.0 115.8 -0.64 0.9927 0.9951 0.0024 PASS
4+reelo 96 80.7 81.8 -1.29 0.9899 0.9922 0.0023 PASS
5+reelo 128 108.1 108.6 -0.47 0.9947 0.9955 0.0009 PASS
6+her 96 88.1 89.9 -1.96 0.9879 0.9867 -0.0012 PASS
7+her 128 121.8 124.9 -2.49 0.9917 0.9927 0.0011 PASS
8+reell 96 84.6 85.5 -1.08 0.9932 0.9923 -0.0009 PASS
9+reell 128 120.6 120.9 -0.18 0.9969 0.9968 -0.0001 PASS
10+reelm 96 84.9 79.3 +7.07 0.9772 0.9865 0.0093 FAIL
11+reelm 128 93.1 91.0 +2.31 0.9846 0.9906 0.0060 FAIL
12+dl8a 96 86.1 86.9 -0.96 0.9878 0.9916 0.0038 PASS
13+dl8a 128 117.6 117.8 -0.12 0.9938 0.9957 0.0019 PASS
14+hein 96 82.4 79.1 +4.26 0.9784 0.9869 0.0086 FAIL
15+hein 128 91.1 90.7 +0.51 0.9856 0.9906 0.0050 PASS
16+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 10 filtered out; finished in 51.90s
lanes/vorbis-floor-r3.report.mdadded+36 -0
@@ -0,0 +1,36 @@
1+# lane-vorbis-floor r3 — headroom tilt (verdict: PARTIAL PASS, merged)
2+
3+VERDICT: equal-size sweep 11/14 PASS (baseline 2/14), mean gap .0153 → .0031. Residual: reelm@96 (+7.1% rate, gap .0093), reelm@128 (gap .0060), hein@96 (+4.3% rate, gap .0086).
4+
5+## Lever
6+`headroom_tilt(hz)` in `crates/ec-vorbis/src/encode.rs`: per-post headroom offset added to `fit_floor` target.
7+LF +12 dB ≤1.1 kHz tapering to 0 at 2 kHz; HF −3 dB from 4 kHz tapering to full at 6 kHz; long blocks only.
8+Rationale (lanes/vorbis-psy-r1.histogram.txt): libvorbis codes LF with finer step (more large q), HF dense ±1 where we zeroed — one global headroom was frequency-blind.
9+
10+## Refuted on this lane
11+- E3 RMS-based peaks in place of peak-hold: mean gap .0073 (worse than tilt .0019 on 8 rows) — reverted.
12+- E4a HF taper 6→8 kHz: no gain over 4→6 kHz.
13+- r1 post-grid density, r2 envelope floor: see vorbis-floor-r1/r2 reports.
14+
15+## Full 14-row sweep (ours at libvorbis's measured kbps, `real_library_sweep_vs_reference`)
16+source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict
17+nik 96 83.5 84.5 -1.20 0.9863 0.9903 0.0040 PASS
18+nik 128 115.0 115.8 -0.64 0.9927 0.9951 0.0024 PASS
19+reelo 96 80.7 81.8 -1.29 0.9899 0.9922 0.0023 PASS
20+reelo 128 108.1 108.6 -0.47 0.9947 0.9955 0.0009 PASS
21+her 96 88.1 89.9 -1.96 0.9879 0.9867 -0.0012 PASS
22+her 128 121.8 124.9 -2.49 0.9917 0.9927 0.0011 PASS
23+reell 96 84.6 85.5 -1.08 0.9932 0.9923 -0.0009 PASS
24+reell 128 120.6 120.9 -0.18 0.9969 0.9968 -0.0001 PASS
25+reelm 96 84.9 79.3 +7.07 0.9772 0.9865 0.0093 FAIL
26+reelm 128 93.1 91.0 +2.31 0.9846 0.9906 0.0060 FAIL
27+dl8a 96 86.1 86.9 -0.96 0.9878 0.9916 0.0038 PASS
28+dl8a 128 117.6 117.8 -0.12 0.9938 0.9957 0.0019 PASS
29+hein 96 82.4 79.1 +4.26 0.9784 0.9869 0.0086 FAIL
30+hein 128 91.1 90.7 +0.51 0.9856 0.9906 0.0050 PASS
31+
32+## Residual class
33+reelm/hein are the HF-droop files (15.5–24 kHz −5..−19 dB, psy-r1 bands). At 96 k the rate loop overshoots the 79 kbps reference by 4–7% — floor cost dominates at low rate and the tilt raises LF floor resolution cost. Next lever is HF-specific (co-mask cap / point-stereo cutoff), not headroom.
34+
35+## Suite
36+`cargo test -p ec-vorbis`: 13+8 passed, 3 ignored (sweeps).
lanes/vorbis-psy-r3.handoff.mddeleted+0 -60
@@ -1,60 +0,0 @@
1-# lane-vorbis-psy — round 3 handoff (2026-08-23)
2-
3-Branch `lane-vorbis-psy` @ 689cdc9 + this commit. No merge, no push.
4-
5-## What this round did
6-
7-- Added `band_error_vs_reference` (ignored instrument test) to
8- `crates/ec-vorbis/tests/oracle.rs` — 2048-pt Hann STFT, 24 bands from 25 edges
9- (100 Hz–24 kHz), band NSR + band-energy-vs-source for ours vs ffmpeg libvorbis,
10- both decoded through our decoder. Bit-split oracle folded into the same pass
11- (see deviations).
12-- Ran all 14 rows (7 sources × {96,128} kbps, 600 s each), release mode, 163 s.
13-- `cargo test -p ec-vorbis` non-ignored: green (13 lib + 8 oracle, 3 ignored).
14-- Encoder output byte-identical to main — established at 689cdc9 in round 2
15- (reelm 120 s 128k, 4b007cd vs 689cdc9), not re-proven this round; this round
16- touches only `tests/oracle.rs` + lanes files.
17-
18-## Findings (numbers in `vorbis-psy-r1.report.md`)
19-
20-1. **Residue coding efficiency is the dominant gap.** bits/non-zero = 1.48–2.12×
21- ref on all 14 rows; we emit 45–57% as many non-zeros at 4.8–6.6 bits each vs
22- ref's 2.4–3.8, from near-identical residue budgets (±4%).
23-2. **The error is concentrated at 300–1080 Hz** — dNSR +8.6 to +14.6 dB; ref hits
24- NSR −20 to −30 there, we sit at −8 to −20. Mid 1–5 kHz +2 to +8. Above 7.7 kHz
25- we win or tie on most rows.
26-3. **HF droop is source-dependent, not universal**: nik 15500-24000 E −19 dB
27- (hard lowpass, both rates; ref −1.8/−2.3), reelm −7.0/−5.3, hein −6.8/−5.3,
28- reell@96 −3.1. reelo/her/dl8a none.
29-4. Floor spend: ours 0.74–0.99× ref; ref outspends us most on reelm/hein 128k
30- (15.5–15.7 k b/s vs 11.6k) — same sources where HF droop shows.
31-
32-## Next-round candidates (ranked by measured impact)
33-
34-- (1)+(2) Residue: encode ~2× non-zeros at ~half bits each in low bands —
35- suspect book selection / dimension / amplitude-bit allocation, not psy
36- (budget already matches).
37-- (3) nik 15.5 kHz cutoff: look for a frequency-limit or floor1 cutoff in the
38- psy/floor path that engages on that source; reelm/hein droop likely floor
39- underspend (finding 4).
40-- (4) Tonal 1–5 kHz on her/reelo/dl8a — minor (+3.1 to +6.5), fix after (1).
41-
42-## Deviations from this round's charter
43-
44-- Bit-split oracle measured inside `band_error_vs_reference` rather than the
45- 12 s × 128k-only `residue_histogram_vs_reference`: same
46- `decode_capture_with_bits` + `bit_split_summary` on the same files, one encode
47- pass instead of two, extended to all 14 rows.
48-- "25 Bark bands" in the charter vs 25 edges listed → 24 bands; edges taken as
49- authoritative.
50-
51-## Files
52-
53-- `crates/ec-vorbis/tests/oracle.rs` — new test (+ fft helper), 244 lines.
54-- `lanes/vorbis-psy-r1.bands.txt` — 394 lines, per-row band tables.
55-- `lanes/vorbis-psy-r1.bits.txt` — 71 lines, per-row bit split.
56-- `lanes/vorbis-psy-r1.report.md` — verdict, tables, diagnosis.
57-- Scratch oggs under `$CARGO_TARGET_DIR/.../scratch/vorbis7-bands/` (not
58- committed).
59-
60-Worktree intentionally live for round 4.