diff --git a/crates/ec-vorbis/src/encode.rs b/crates/ec-vorbis/src/encode.rs index f74d5ce6..f09a4038 100644 --- a/crates/ec-vorbis/src/encode.rs +++ b/crates/ec-vorbis/src/encode.rs @@ -106,6 +106,11 @@ const CO_MASK_RANGE: f64 = 50.0; /// rate/quality knob: raising the curve zeroes masked coefficients earlier, /// while peaks still ride as residue above it. const MASKING_OFFSET_DB: f64 = 9.0; +/// dB added to the per-region geometric-mean floor level (E2, lane-vorbis-floor +/// r2). 0 = pure envelope (E1, too low → clamp-lift saturation); the gap between +/// mean dB and peak dB in a typical long-block region is 15–25 dB, so 12 sits +/// halfway and keeps the loudest bin within the residue-book range. +const ENVELOPE_MARGIN_DB: f64 = 12.0; /// All-zero partition guard: if the masked band still has a bin within this /// fraction of the floor, keep that bin as one sign-only residue sample. const NOISE_NORMALISE_MIN_RATIO: f32 = 0.5; @@ -930,14 +935,15 @@ impl VorbisEncoder { /// the whole spectrum is covered exactly once and a peak between two points /// still raises the floor that has to carry it. /// -/// E1 (lane-vorbis-floor r2): returns the per-region **geometric mean** of -/// |bin| (≡ mean of dB) instead of the max. The max set the floor to the -/// region's loudest bin; bins 20–40 dB under it quantised to zero, so we coded -/// 45–57% as many non-zero residues as libvorbis at 1.5–2.1× bits each. The -/// geometric mean tracks the envelope: most bins sit near it and land at -/// q ≈ 10^(headroom/20) ≈ ±3, matching libvorbis's dense ±1/±2. +/// E2 (lane-vorbis-floor r2): returns the per-region geometric mean of |bin| +/// (≡ mean dB) **plus `ENVELOPE_MARGIN_DB`** — halfway between the pure +/// envelope (E1, too low → clamp-lift saturation) and the peak (baseline, +/// too high → sparse large q). The margin lifts the floor enough that the +/// loudest bins in each region stay within the residue-book range without the +/// refit loop, while quieter bins still get a small non-zero q. fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec]) -> Vec { let x = &floor.x_list; + let margin = 10.0_f64.powf(ENVELOPE_MARGIN_DB / 20.0); x.iter() .map(|¢re| { let below = x.iter().filter(|&&o| o < centre).max().copied(); @@ -954,7 +960,7 @@ fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec]) -> Vec { count += 1; } } - (sum_log / count as f64).exp() + (sum_log / count as f64).exp() * margin }) .collect() } diff --git a/lanes/vorbis-psy-r1.sweep.txt b/lanes/vorbis-psy-r1.sweep.txt index 43f95472..7d313cfd 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 83.2 84.5 -1.59 0.7641 0.9903 0.2262 FAIL -nik 128 113.1 115.8 -2.30 0.8342 0.9951 0.1609 FAIL -her 96 83.8 89.9 -6.78 0.7089 0.9867 0.2778 FAIL -her 128 111.6 124.9 -10.62 0.7941 0.9927 0.1986 FAIL -reell 96 84.8 85.5 -0.80 0.7999 0.9923 0.1924 FAIL -reell 128 120.3 120.9 -0.48 0.8890 0.9968 0.1078 FAIL -dl8a 96 86.0 86.9 -1.01 0.8091 0.9916 0.1825 FAIL -dl8a 128 116.4 117.8 -1.17 0.8783 0.9957 0.1174 FAIL +nik 96 83.6 84.5 -1.07 0.7840 0.9903 0.2063 FAIL +nik 128 114.7 115.8 -0.88 0.8661 0.9951 0.1290 FAIL +her 96 92.3 89.9 +2.68 0.7755 0.9867 0.2112 FAIL +her 128 125.2 124.9 +0.21 0.8650 0.9927 0.1277 FAIL +reell 96 85.1 85.5 -0.42 0.8553 0.9923 0.1371 FAIL +reell 128 121.6 120.9 +0.62 0.9472 0.9968 0.0496 FAIL +dl8a 96 86.2 86.9 -0.81 0.8478 0.9916 0.1439 FAIL +dl8a 128 117.5 117.8 -0.26 0.9177 0.9957 0.0780 FAIL