Record the four opustonal gate arms and their rejections
Browse files at this commit467beea2c4157d7aea9ab760efdae83a40ad0c9bParent: 8d3a184- docs
- record the four opustonal gate arms and their rejections
3 changed files +57 -2
- crates/ec-opus/src/celt_enc.rs +33 -2
- crates/ec-opus/src/encoder.rs +9 -0
- lanes/opus-opustonal-r4.sweep.txt +15 -0
crates/ec-opus/src/celt_enc.rsmodified+33 -2
| @@ -69,6 +69,31 @@ fn tf_boost_params() -> (f32, f32, bool, f32) { | ||
| 69 | 69 | /// `EC_OPUS_TRIM13` (the continuous 1.3 trim the term belongs to), |
| 70 | 70 | /// `EC_OPUS_VBR_TONAL` (`compute_vbr`'s tonality boost) and |
| 71 | 71 | /// `EC_OPUS_VBR_ACT` (`compute_vbr`'s low-activity cut). |
| 72 | +/// | |
| 73 | +/// MEASURED (lane opustonal, four detached 12-row library-gate runs against | |
| 74 | +/// the shipped rows `lanes/opus-opustr2-r1.sweep.txt`). The analysis itself is | |
| 75 | +/// byte-neutral -- no consumer reads it unless its own switch is on -- and | |
| 76 | +/// **every consumer arm is rejected by the KEEP rule**, so all three default | |
| 77 | +/// off. err_ratio, better rows first, blocking rows named: | |
| 78 | +/// | |
| 79 | +/// | arm | better | blocking | | |
| 80 | +/// |---|---|---| | |
| 81 | +/// | 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 | | |
| 82 | +/// | 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 | | |
| 83 | +/// | 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 | | |
| 84 | +/// | 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 | | |
| 85 | +/// | |
| 86 | +/// `corr_ours` is never worse by more than .0005 on any unaligned arm (it is | |
| 87 | +/// *better* on every row of `-r2`/`-r3`), so corr is not what rejects them. | |
| 88 | +/// The `alloc_trim` term is small by construction -- `tonality_slope` averages | |
| 89 | +/// -.09 (speech) to -.17 (music), so the term is ±.08 of a trim step and | |
| 90 | +/// rounds away entirely on the shipped discrete ladder, which is why no | |
| 91 | +/// discrete-ladder arm was run. The activity cut is the nearest miss ever | |
| 92 | +/// measured on this gate for a speech source (hein halves) and is blocked by | |
| 93 | +/// her@96 +.020 and nik@96 +.005 -- the same two rows that have blocked the | |
| 94 | +/// tf boost. Aligned, the analysis moves reell/reelo/her@64 a long way but leaves | |
| 95 | +/// the aligned blocking set (nik, her@96, dl8a, hein) exactly where the | |
| 96 | +/// analysis-free aligned arms left it, so the alignment default stays off. | |
| 72 | 97 | fn analysis_params() -> (bool, bool, bool, bool) { |
| 73 | 98 | static P: std::sync::OnceLock<(bool, bool, bool, bool)> = std::sync::OnceLock::new(); |
| 74 | 99 | *P.get_or_init(|| { |
| @@ -1021,7 +1046,9 @@ impl CeltEncoder { | ||
| 1021 | 1046 | if c == 2 { |
| 1022 | 1047 | coded_bins += E_BANDS[self.intensity.min(coded_bands)] << lm; |
| 1023 | 1048 | } |
| 1024 | - // Low-activity cut (C:1632-1633). | |
| 1049 | + // Low-activity cut (C:1632-1633). REJECTED on the 12-row gate | |
| 1050 | + // (lane opustonal r2/r3): halves hein's err_ratio but costs | |
| 1051 | + // her@96 +.020 and nik@96 +.005 -- see `analysis_params`. | |
| 1025 | 1052 | if vbr_act && self.info.valid && self.info.activity < 0.4 { |
| 1026 | 1053 | target -= ((coded_bins << BITRES) as f32 * (0.4 - self.info.activity)) as i32; |
| 1027 | 1054 | } |
| @@ -1080,6 +1107,8 @@ impl CeltEncoder { | ||
| 1080 | 1107 | target += (k_eff * (tf_estimate - off) * target as f32) as i32; |
| 1081 | 1108 | } |
| 1082 | 1109 | // Tonality boost (C:1658-1669), compensating for the average. |
| 1110 | + // REJECTED on the 12-row gate (lane opustonal r2): it is what | |
| 1111 | + // pushes reelo@96 .940->1.165 -- see `analysis_params`. | |
| 1083 | 1112 | // `pitch_change` is 0 here (no prefilter), so its term is absent. |
| 1084 | 1113 | if vbr_tonal && self.info.valid { |
| 1085 | 1114 | let tonal = (self.info.tonality - 0.15).max(0.0) - 0.12; |
| @@ -1734,7 +1763,9 @@ impl CeltEncoder { | ||
| 1734 | 1763 | } |
| 1735 | 1764 | // libopus's `analysis->valid` term (celt_encoder.c:935-939): a tonal |
| 1736 | 1765 | // spectrum wants a lower trim. It is only defined on the continuous |
| 1737 | - // 1.3 trim; on the discrete ladder it can only be applied rounded. | |
| 1766 | + // 1.3 trim; on the discrete ladder it can only be applied rounded, | |
| 1767 | + // where it is inert (|term| <= .08). REJECTED with the 1.3 trim it | |
| 1768 | + // belongs to -- see `analysis_params`, lane opustonal r1. | |
| 1738 | 1769 | let tonal_trim = if analysis_params().1 && self.info.valid { |
| 1739 | 1770 | (2.0 * (self.info.tonality_slope + 0.05)).clamp(-2.0, 2.0) |
| 1740 | 1771 | } else { |
crates/ec-opus/src/encoder.rsmodified+9 -0
| @@ -273,11 +273,20 @@ impl Encoder { | ||
| 273 | 273 | /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 | |
| 274 | 274 | /// | + tf boost k=1.5 (`-r5`) | 5 | same 7 | |
| 275 | 275 | /// | + 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 | |
| 276 | + /// | + 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 | | |
| 276 | 277 | /// |
| 277 | 278 | /// The best aligned arm on the KEEP rule is the delay alone without |
| 278 | 279 | /// `dc_reject` (5 rows worse); every arm that adds `dc_reject` puts dl8a |
| 279 | 280 | /// in the blocking set too. |
| 280 | 281 | /// |
| 282 | + /// The last row is the one that was expected to rescue this: libopus's | |
| 283 | + /// actual operating point is the aligned spectrum *with* `analysis->valid` | |
| 284 | + /// true, and running the real analysis (`crates/ec-opus/src/analysis.rs`, | |
| 285 | + /// `music_prob` matching a patched-libopus trace to .001) moves reell@64 | |
| 286 | + /// 2.697→1.865, reell@96 4.499→3.986, reelo@64 1.510→1.123 and her@64 | |
| 287 | + /// 1.103→.952 — the largest movement any arm has produced on those rows — | |
| 288 | + /// and still leaves the same seven rows worse. | |
| 289 | + /// | |
| 281 | 290 | /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and |
| 282 | 291 | /// no arm moves any of those rows back towards its shipped value, so the |
| 283 | 292 | /// misfit is not one of the swept constants. Turning this on also costs |
lanes/opus-opustonal-r4.sweep.txtadded+15 -0
| @@ -0,0 +1,15 @@ | ||
| 1 | +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) | |
| 2 | +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo | |
| 3 | +# 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 | |
| 4 | +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 | |
| 5 | +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 | |
| 6 | +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 | |
| 7 | +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 | |
| 8 | +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 | |
| 9 | +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 | |
| 10 | +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 | |
| 11 | +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 | |
| 12 | +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 | |
| 13 | +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 | |
| 14 | +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 | |
| 15 | +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 |