From 982ef467cae8c6bb215765d56157850f34097114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 23 Aug 2026 04:36:31 +0300 Subject: [PATCH] =?UTF-8?q?E1:=20LF=20headroom=20tilt=20+6=20dB=20(1.1-2?= =?UTF-8?q?=20kHz)=20=E2=80=94=20mean=20gap=200.00536=20(was=200.01525)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ec-vorbis/src/encode.rs | 58 +++++++++++++++++++++++++++++++--- lanes/vorbis-psy-r1.sweep.txt | 16 +++++----- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/crates/ec-vorbis/src/encode.rs b/crates/ec-vorbis/src/encode.rs index c0ebafbd..1c1e4575 100644 --- a/crates/ec-vorbis/src/encode.rs +++ b/crates/ec-vorbis/src/encode.rs @@ -123,6 +123,38 @@ const CO_MASK_RANGE_SHORT: f64 = f64::INFINITY; const POINT_STEREO_HZ: f64 = 4_000.0; /// Least headroom a short block is quantised with, whatever the rate loop's. const HEADROOM_SHORT_MIN: f64 = 42.0; +/// Per-post headroom tilt (dB): extra headroom below `TILT_LF_LO_HZ` so the +/// floor sits lower at low frequencies — finer step, more bits where the ear +/// is sensitive and the reference spends. Tapers to 0 by `TILT_LF_HI_HZ`. +/// `TILT_HF_DB` (negative) trims step resolution above `TILT_HF_HI_HZ`, +/// routing those bits to LF. The rate loop's global headroom rebalances the +/// total. Tuned by lanes/vorbis-floor-r3.report.md (8-row sweep). +const TILT_LF_DB: f64 = 6.0; +const TILT_LF_LO_HZ: f64 = 1_100.0; +const TILT_LF_HI_HZ: f64 = 2_000.0; +const TILT_HF_DB: f64 = 0.0; +const TILT_HF_LO_HZ: f64 = 4_000.0; +const TILT_HF_HI_HZ: f64 = 6_000.0; + +/// Extra headroom (dB) for one floor post at `hz`: LF boost tapering to 0, +/// plus an HF cut (negative) tapering in. Zero outside both bands. +fn headroom_tilt(hz: f64) -> f64 { + let lf = if hz <= TILT_LF_LO_HZ { + TILT_LF_DB + } else if hz < TILT_LF_HI_HZ { + TILT_LF_DB * (TILT_LF_HI_HZ - hz) / (TILT_LF_HI_HZ - TILT_LF_LO_HZ) + } else { + 0.0 + }; + let hf = if hz <= TILT_HF_LO_HZ { + 0.0 + } else if hz < TILT_HF_HI_HZ { + TILT_HF_DB * (hz - TILT_HF_LO_HZ) / (TILT_HF_HI_HZ - TILT_HF_LO_HZ) + } else { + TILT_HF_DB + }; + lf + hf +} /// Samples per transient-detection tick — the short block's own hop, so a /// tick lines up with the finest time resolution the encoder has. const TICK: usize = BLOCK_SHORT / 4; @@ -687,6 +719,17 @@ impl VorbisEncoder { } else { MASKING_OFFSET_DB }; + // Per-post headroom tilt: LF boost, HF cut, long blocks only — the + // rate loop's global headroom rebalances the total bitrate. + let tilt: Vec = if plan.is_long { + bc.floor + .x_list + .iter() + .map(|&x| headroom_tilt(x as f64 * f64::from(self.config.sample_rate) / (2.0 * half as f64))) + .collect() + } else { + vec![0.0; bc.floor.x_list.len()] + }; let (floor_values, quantised) = loop { let mut curves: Vec> = vec![Vec::new(); channels]; let mut floor_values: Vec> = vec![Vec::new(); channels]; @@ -707,6 +750,7 @@ impl VorbisEncoder { bc.co_mask, masking_offset, &peaks, + &tilt, ); let mut curve = vec![0.0f32; half]; render_floor1(&bc.floor, &y, &step2, &mut curve); @@ -955,7 +999,8 @@ fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec]) -> Vec { /// Spread first (a masker covers its neighbours, with an extra Bark-local /// near-band pass), then subtract the rate loop's headroom, then hold the /// absolute threshold of hearing as a lower bound: below it the residue -/// quantises to zero and costs a class-0 partition. +/// quantises to zero and costs a class-0 partition. `headroom` is tilted per +/// post by [`headroom_tilt`]: more at LF for a finer step, less at HF. fn fit_floor( floor: &Floor1, ath: &[f64], @@ -965,6 +1010,7 @@ fn fit_floor( co_mask: f64, masking_offset: f64, peaks: &[f64], + tilt: &[f64], ) -> (Vec, Vec) { let db: Vec = peaks .iter() @@ -998,11 +1044,13 @@ fn fit_floor( let target: Vec = spread .iter() .zip(ath.iter()) - .map(|(&level, &threshold)| { + .enumerate() + .map(|(i, (&level, &threshold))| { + let h = headroom + tilt[i]; let threshold = threshold.max(loudest - co_mask); - let offset = (masking_offset - (headroom - range).max(0.0)).max(0.0); - (level - headroom.min(range) + offset) - .max(threshold - (headroom - range).max(0.0)) + let offset = (masking_offset - (h - range).max(0.0)).max(0.0); + (level - h.min(range) + offset) + .max(threshold - (h - range).max(0.0)) }) .collect(); let y: Vec = target diff --git a/lanes/vorbis-psy-r1.sweep.txt b/lanes/vorbis-psy-r1.sweep.txt index b0903d24..ce98411f 100644 --- a/lanes/vorbis-psy-r1.sweep.txt +++ b/lanes/vorbis-psy-r1.sweep.txt @@ -1,9 +1,9 @@ source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict -nik 96 84.0 84.5 -0.61 0.9690 0.9903 0.0213 FAIL -nik 128 115.5 115.8 -0.24 0.9838 0.9951 0.0113 FAIL -her 96 89.9 89.9 +0.04 0.9668 0.9867 0.0199 FAIL -her 128 123.5 124.9 -1.13 0.9810 0.9927 0.0117 FAIL -reell 96 85.4 85.5 -0.12 0.9792 0.9923 0.0131 FAIL -reell 128 121.3 120.9 +0.39 0.9914 0.9968 0.0054 FAIL -dl8a 96 86.9 86.9 -0.01 0.9655 0.9916 0.0261 FAIL -dl8a 128 118.7 117.8 +0.80 0.9826 0.9957 0.0132 FAIL +nik 96 83.8 84.5 -0.84 0.9809 0.9903 0.0094 FAIL +nik 128 115.3 115.8 -0.37 0.9899 0.9951 0.0053 FAIL +her 96 89.3 89.9 -0.65 0.9827 0.9867 0.0040 PASS +her 128 123.1 124.9 -1.47 0.9889 0.9927 0.0039 PASS +reell 96 85.1 85.5 -0.48 0.9890 0.9923 0.0034 PASS +reell 128 121.1 120.9 +0.22 0.9952 0.9968 0.0016 PASS +dl8a 96 86.6 86.9 -0.38 0.9814 0.9916 0.0102 FAIL +dl8a 128 118.5 117.8 +0.58 0.9906 0.9957 0.0051 FAIL