Revert encode.rs to main: envelope-following refuted, peak is best
Browse files at this commitc3f777b78936410d75f511a13c3bea4864cfea5aParent: 32bafc82 changed files +11 -25
crates/ec-vorbis/src/encode.rsmodified+3 -17
| @@ -106,11 +106,6 @@ const CO_MASK_RANGE: f64 = 50.0; | |||
| 106 | /// rate/quality knob: raising the curve zeroes masked coefficients earlier, | 106 | /// rate/quality knob: raising the curve zeroes masked coefficients earlier, |
| 107 | /// while peaks still ride as residue above it. | 107 | /// while peaks still ride as residue above it. |
| 108 | const MASKING_OFFSET_DB: f64 = 9.0; | 108 | const MASKING_OFFSET_DB: f64 = 9.0; |
| 109 | -/// dB added to the per-region geometric-mean floor level (E2, lane-vorbis-floor | ||
| 110 | -/// r2). 0 = pure envelope (E1, too low → clamp-lift saturation); the gap between | ||
| 111 | -/// mean dB and peak dB in a typical long-block region is 15–25 dB, so 12 sits | ||
| 112 | -/// halfway and keeps the loudest bin within the residue-book range. | ||
| 113 | -const ENVELOPE_MARGIN_DB: f64 = 6.0; | ||
| 114 | /// All-zero partition guard: if the masked band still has a bin within this | 109 | /// All-zero partition guard: if the masked band still has a bin within this |
| 115 | /// fraction of the floor, keep that bin as one sign-only residue sample. | 110 | /// fraction of the floor, keep that bin as one sign-only residue sample. |
| 116 | const NOISE_NORMALISE_MIN_RATIO: f32 = 0.5; | 111 | const NOISE_NORMALISE_MIN_RATIO: f32 = 0.5; |
| @@ -934,13 +929,6 @@ impl VorbisEncoder { | |||
| 934 | /// Each point owns the coefficients halfway to its neighbours either side, so | 929 | /// Each point owns the coefficients halfway to its neighbours either side, so |
| 935 | /// the whole spectrum is covered exactly once and a peak between two points | 930 | /// the whole spectrum is covered exactly once and a peak between two points |
| 936 | /// still raises the floor that has to carry it. | 931 | /// still raises the floor that has to carry it. |
| 937 | -/// | ||
| 938 | -/// E3 (lane-vorbis-floor r2): returns the per-region **RMS** of |bin| instead | ||
| 939 | -/// of the max. RMS sits between the geometric mean (E1, dominated by | ||
| 940 | -/// noise-floor bins → too low) and the peak (baseline, follows only the | ||
| 941 | -/// loudest bin). Tried because E1/E2 moved the gap (in the wrong direction): | ||
| 942 | -/// the trend k=0→6→12→peak was monotonically better, so RMS is expected to | ||
| 943 | -/// land above geomean but still below peak. | ||
| 944 | fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec<f32>]) -> Vec<f64> { | 932 | fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec<f32>]) -> Vec<f64> { |
| 945 | let x = &floor.x_list; | 933 | let x = &floor.x_list; |
| 946 | x.iter() | 934 | x.iter() |
| @@ -951,15 +939,13 @@ fn peaks_of(floor: &Floor1, half: usize, spectra: &[&Vec<f32>]) -> Vec<f64> { | |||
| 951 | let hi = above.map_or(half, |a| ((a + centre) / 2) as usize + 1); | 939 | let hi = above.map_or(half, |a| ((a + centre) / 2) as usize + 1); |
| 952 | let lo = lo.min(half - 1); | 940 | let lo = lo.min(half - 1); |
| 953 | let hi = hi.clamp(lo + 1, half); | 941 | let hi = hi.clamp(lo + 1, half); |
| 954 | - let mut sum_sq = 0.0f64; | 942 | + let mut peak = 0.0f64; |
| 955 | - let mut count = 0usize; | ||
| 956 | for spectrum in spectra { | 943 | for spectrum in spectra { |
| 957 | for &value in &spectrum[lo..hi] { | 944 | for &value in &spectrum[lo..hi] { |
| 958 | - sum_sq += f64::from(value) * f64::from(value); | 945 | + peak = peak.max(f64::from(value.abs())); |
| 959 | - count += 1; | ||
| 960 | } | 946 | } |
| 961 | } | 947 | } |
| 962 | - (sum_sq / count as f64).sqrt() | 948 | + peak |
| 963 | }) | 949 | }) |
| 964 | .collect() | 950 | .collect() |
| 965 | } | 951 | } |
lanes/vorbis-psy-r1.sweep.txtmodified+8 -8
| @@ -1,9 +1,9 @@ | |||
| 1 | source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict | 1 | source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict |
| 2 | -nik 96 83.5 84.5 -1.22 0.9102 0.9903 0.0801 FAIL | 2 | +nik 96 84.0 84.5 -0.61 0.9690 0.9903 0.0213 FAIL |
| 3 | -nik 128 114.6 115.8 -0.96 0.9601 0.9951 0.0351 FAIL | 3 | +nik 128 115.5 115.8 -0.24 0.9838 0.9951 0.0113 FAIL |
| 4 | -her 96 88.8 89.9 -1.22 0.8206 0.9867 0.1661 FAIL | 4 | +her 96 89.9 89.9 +0.04 0.9668 0.9867 0.0199 FAIL |
| 5 | -her 128 122.4 124.9 -2.02 0.9238 0.9927 0.0689 FAIL | 5 | +her 128 123.5 124.9 -1.13 0.9810 0.9927 0.0117 FAIL |
| 6 | -reell 96 84.9 85.5 -0.70 0.9224 0.9923 0.0699 FAIL | 6 | +reell 96 85.4 85.5 -0.12 0.9792 0.9923 0.0131 FAIL |
| 7 | -reell 128 121.0 120.9 +0.13 0.9701 0.9968 0.0267 FAIL | 7 | +reell 128 121.3 120.9 +0.39 0.9914 0.9968 0.0054 FAIL |
| 8 | -dl8a 96 85.9 86.9 -1.13 0.8993 0.9916 0.0923 FAIL | 8 | +dl8a 96 86.9 86.9 -0.01 0.9655 0.9916 0.0261 FAIL |
| 9 | -dl8a 128 116.8 117.8 -0.86 0.9520 0.9957 0.0437 FAIL | 9 | +dl8a 128 118.7 117.8 +0.80 0.9826 0.9957 0.0132 FAIL |