From c3f777b78936410d75f511a13c3bea4864cfea5a 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:30:56 +0300 Subject: [PATCH] Revert encode.rs to main: envelope-following refuted, peak is best --- crates/ec-vorbis/src/encode.rs | 20 +++----------------- lanes/vorbis-psy-r1.sweep.txt | 16 ++++++++-------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/crates/ec-vorbis/src/encode.rs b/crates/ec-vorbis/src/encode.rs index 466ce905..c0ebafbd 100644 --- a/crates/ec-vorbis/src/encode.rs +++ b/crates/ec-vorbis/src/encode.rs @@ -106,11 +106,6 @@ 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 = 6.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; @@ -934,13 +929,6 @@ impl VorbisEncoder { /// Each point owns the coefficients halfway to its neighbours either side, so /// the whole spectrum is covered exactly once and a peak between two points /// still raises the floor that has to carry it. -/// -/// E3 (lane-vorbis-floor r2): returns the per-region **RMS** of |bin| instead -/// of the max. RMS sits between the geometric mean (E1, dominated by -/// noise-floor bins → too low) and the peak (baseline, follows only the -/// loudest bin). Tried because E1/E2 moved the gap (in the wrong direction): -/// the trend k=0→6→12→peak was monotonically better, so RMS is expected to -/// land above geomean but still below peak. fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec]) -> Vec { let x = &floor.x_list; x.iter() @@ -951,15 +939,13 @@ fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec]) -> Vec { let hi = above.map_or(half, |a| ((a + centre) / 2) as usize + 1); let lo = lo.min(half - 1); let hi = hi.clamp(lo + 1, half); - let mut sum_sq = 0.0f64; - let mut count = 0usize; + let mut peak = 0.0f64; for spectrum in spectra { for &value in &spectrum[lo..hi] { - sum_sq += f64::from(value) * f64::from(value); - count += 1; + peak = peak.max(f64::from(value.abs())); } } - (sum_sq / count as f64).sqrt() + peak }) .collect() } diff --git a/lanes/vorbis-psy-r1.sweep.txt b/lanes/vorbis-psy-r1.sweep.txt index 19141b81..b0903d24 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.5 84.5 -1.22 0.9102 0.9903 0.0801 FAIL -nik 128 114.6 115.8 -0.96 0.9601 0.9951 0.0351 FAIL -her 96 88.8 89.9 -1.22 0.8206 0.9867 0.1661 FAIL -her 128 122.4 124.9 -2.02 0.9238 0.9927 0.0689 FAIL -reell 96 84.9 85.5 -0.70 0.9224 0.9923 0.0699 FAIL -reell 128 121.0 120.9 +0.13 0.9701 0.9968 0.0267 FAIL -dl8a 96 85.9 86.9 -1.13 0.8993 0.9916 0.0923 FAIL -dl8a 128 116.8 117.8 -0.86 0.9520 0.9957 0.0437 FAIL +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