diff --git a/crates/ec-opus/src/celt_enc.rs b/crates/ec-opus/src/celt_enc.rs index c045b930..db36d63f 100644 --- a/crates/ec-opus/src/celt_enc.rs +++ b/crates/ec-opus/src/celt_enc.rs @@ -69,6 +69,31 @@ fn tf_boost_params() -> (f32, f32, bool, f32) { /// `EC_OPUS_TRIM13` (the continuous 1.3 trim the term belongs to), /// `EC_OPUS_VBR_TONAL` (`compute_vbr`'s tonality boost) and /// `EC_OPUS_VBR_ACT` (`compute_vbr`'s low-activity cut). +/// +/// MEASURED (lane opustonal, four detached 12-row library-gate runs against +/// the shipped rows `lanes/opus-opustr2-r1.sweep.txt`). The analysis itself is +/// byte-neutral -- no consumer reads it unless its own switch is on -- and +/// **every consumer arm is rejected by the KEEP rule**, so all three default +/// off. err_ratio, better rows first, blocking rows named: +/// +/// | arm | better | blocking | +/// |---|---|---| +/// | 1.3 trim + tonality term (`-r1`) | nik@64 .708→.647, reelo@64 1.510→1.071, reelo@96 .940→.898, reell@96 4.499→2.458, dl8a .552/.374→.512/.336 | nik@96 .985→1.006, her@64 1.103→1.109, her@96 1.051→1.085, reell@64 2.697→2.872 | +/// | vbr tonality + activity (`-r2`) | hein@64 .853→.327, hein@96 .528→.426, nik@64 →.672, dl8a@64 →.541 | nik@96 →1.061, reelo@96 →1.165, her@64 →1.104, her@96 →1.060, dl8a@96 →.414 | +/// | vbr activity alone (`-r3`) | hein@64 →.430, hein@96 →.408, nik@64 →.657, dl8a@64 →.511 | nik@96 →.990, her@64 →1.104, her@96 →1.071, dl8a@96 →.382 | +/// | all four + `EC_OPUS_ALIGN=1` (`-r4`) | reell@64 →1.865, reell@96 →3.986, reelo@64 →1.123, reelo@96 →.891, her@64 →.952 | nik@64 →1.014, nik@96 →1.842, her@96 →1.217, dl8a →1.162/.988, hein →.971/1.514 | +/// +/// `corr_ours` is never worse by more than .0005 on any unaligned arm (it is +/// *better* on every row of `-r2`/`-r3`), so corr is not what rejects them. +/// The `alloc_trim` term is small by construction -- `tonality_slope` averages +/// -.09 (speech) to -.17 (music), so the term is ±.08 of a trim step and +/// rounds away entirely on the shipped discrete ladder, which is why no +/// discrete-ladder arm was run. The activity cut is the nearest miss ever +/// measured on this gate for a speech source (hein halves) and is blocked by +/// her@96 +.020 and nik@96 +.005 -- the same two rows that have blocked the +/// tf boost. Aligned, the analysis moves reell/reelo/her@64 a long way but leaves +/// the aligned blocking set (nik, her@96, dl8a, hein) exactly where the +/// analysis-free aligned arms left it, so the alignment default stays off. fn analysis_params() -> (bool, bool, bool, bool) { static P: std::sync::OnceLock<(bool, bool, bool, bool)> = std::sync::OnceLock::new(); *P.get_or_init(|| { @@ -1021,7 +1046,9 @@ impl CeltEncoder { if c == 2 { coded_bins += E_BANDS[self.intensity.min(coded_bands)] << lm; } - // Low-activity cut (C:1632-1633). + // Low-activity cut (C:1632-1633). REJECTED on the 12-row gate + // (lane opustonal r2/r3): halves hein's err_ratio but costs + // her@96 +.020 and nik@96 +.005 -- see `analysis_params`. if vbr_act && self.info.valid && self.info.activity < 0.4 { target -= ((coded_bins << BITRES) as f32 * (0.4 - self.info.activity)) as i32; } @@ -1080,6 +1107,8 @@ impl CeltEncoder { target += (k_eff * (tf_estimate - off) * target as f32) as i32; } // Tonality boost (C:1658-1669), compensating for the average. + // REJECTED on the 12-row gate (lane opustonal r2): it is what + // pushes reelo@96 .940->1.165 -- see `analysis_params`. // `pitch_change` is 0 here (no prefilter), so its term is absent. if vbr_tonal && self.info.valid { let tonal = (self.info.tonality - 0.15).max(0.0) - 0.12; @@ -1734,7 +1763,9 @@ impl CeltEncoder { } // libopus's `analysis->valid` term (celt_encoder.c:935-939): a tonal // spectrum wants a lower trim. It is only defined on the continuous - // 1.3 trim; on the discrete ladder it can only be applied rounded. + // 1.3 trim; on the discrete ladder it can only be applied rounded, + // where it is inert (|term| <= .08). REJECTED with the 1.3 trim it + // belongs to -- see `analysis_params`, lane opustonal r1. let tonal_trim = if analysis_params().1 && self.info.valid { (2.0 * (self.info.tonality_slope + 0.05)).clamp(-2.0, 2.0) } else { diff --git a/crates/ec-opus/src/encoder.rs b/crates/ec-opus/src/encoder.rs index 59312009..3530f5d7 100644 --- a/crates/ec-opus/src/encoder.rs +++ b/crates/ec-opus/src/encoder.rs @@ -273,11 +273,20 @@ impl Encoder { /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 | /// | + tf boost k=1.5 (`-r5`) | 5 | same 7 | /// | + two-pass *and* k=1.25, the combined best (`-r7`) | 5 | same 7: nik@64 .773, nik@96 1.801, her@96 1.114, dl8a@64 1.181, dl8a@96 1.014, hein@64 .977, hein@96 1.398 | + /// | + the whole libopus tonality analysis and its `alloc_trim`/`compute_vbr` consumers (`opus-opustonal-r4`) | 5 | same 7: nik@64 1.014, nik@96 1.842, her@96 1.217, dl8a@64 1.162, dl8a@96 .988, hein@64 .971, hein@96 1.514 | /// /// The best aligned arm on the KEEP rule is the delay alone without /// `dc_reject` (5 rows worse); every arm that adds `dc_reject` puts dl8a /// in the blocking set too. /// + /// The last row is the one that was expected to rescue this: libopus's + /// actual operating point is the aligned spectrum *with* `analysis->valid` + /// true, and running the real analysis (`crates/ec-opus/src/analysis.rs`, + /// `music_prob` matching a patched-libopus trace to .001) moves reell@64 + /// 2.697→1.865, reell@96 4.499→3.986, reelo@64 1.510→1.123 and her@64 + /// 1.103→.952 — the largest movement any arm has produced on those rows — + /// and still leaves the same seven rows worse. + /// /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and /// no arm moves any of those rows back towards its shipped value, so the /// misfit is not one of the swept constants. Turning this on also costs diff --git a/lanes/opus-opustonal-r4.sweep.txt b/lanes/opus-opustonal-r4.sweep.txt new file mode 100644 index 00000000..d93784a9 --- /dev/null +++ b/lanes/opus-opustonal-r4.sweep.txt @@ -0,0 +1,15 @@ +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap Q_ours Q_ref err_ratio minsec_ours minsec_ref drop_ours drop_ref +nik 64 69.0 69.2 -0.3 0.9875 0.9864 -0.0012 -157.46 -154.78 1.014 0.9763 0.9745 0 0 +nik 96 100.8 101.0 -0.2 0.9939 0.9940 +0.0002 -116.75 -31.55 1.842 0.9883 0.9888 0 0 +reelo 64 63.3 63.6 -0.4 0.9883 0.9866 -0.0017 -143.92 -123.36 1.123 0.9695 0.9686 0 0 +reelo 96 92.8 93.9 -1.1 0.9940 0.9937 -0.0002 -105.85 -125.18 0.891 0.9858 0.9854 0 0 +her 64 67.4 67.9 -0.8 0.9821 0.9794 -0.0026 -325.83 -339.00 0.952 0.9464 0.9406 0 0 +her 96 100.3 101.5 -1.2 0.9910 0.9902 -0.0007 -234.41 -191.50 1.217 0.9754 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9898 0.9880 -0.0019 -257.24 -128.39 1.865 0.9697 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9948 0.9948 -0.0001 -271.56 -29.16 3.986 0.9842 0.9804 0 0 +dl8a 64 65.6 65.8 -0.3 0.9876 0.9865 -0.0011 -422.17 -378.84 1.162 0.9778 0.9723 0 0 +dl8a 96 96.5 96.8 -0.4 0.9932 0.9934 +0.0002 -420.05 -423.47 0.988 0.9870 0.9864 0 0 +hein 64 64.6 64.9 -0.4 0.9886 0.9874 -0.0012 -380.03 -388.31 0.971 0.9307 0.9148 0 0 +hein 96 86.7 86.9 -0.2 0.9945 0.9930 -0.0015 -351.77 -246.46 1.514 0.9683 0.9499 0 0