forge
Explore
Log in

Don't you dare go Hollow

CVBR transient boost measured whole

Browse files at this commit

31589bd2f7f0df779b7bd42bc11297e7d505b258Ahmet Kaan GümüşParent: fddb8d4
  • perf
    • CVBR transient boost measured whole
    • both halves rejected, reell lever named
Show full message
perf(opus): CVBR transient boost measured whole; both halves rejected, reell lever named

The per-frame census says our transient frames underspend libopus's at the same
realised rate -- reelo@64 202 vs 229 bytes, her@64 216 vs 233 -- while the steady
frames match to 2%. Two documented deviations sit in that mechanism, and both
were re-measured on the 12-row library gate:

  r2 (`lanes/opus-opustr-r2.sweep.txt`) restores libopus CVBR whole: the x2 tf
  boost `2*(tf_estimate-.04)*target` plus the uncapped one-frame reservoir
  release. reell@64 2.697 -> 1.764 and reell@96 4.499 -> 2.114, the largest move any
  lane has made on those rows; against that, 5 rows regress and hein@64 loses
  .0030 corr. That corr loss is the same one that rejected the x2 on the old
  14-row gate -- the rejection was recorded against reelm, whose rows no longer
  exist, so hein reproducing it exactly is what keeps the finding alive.

  r3 (`lanes/opus-opustr-r3.sweep.txt`) isolates the reservoir release: 3 rows
  better, 5 worse (dl8a@96 .374->.415, hein@96 .528->.555), reell unmoved. So the
  whole reell win in r2 belongs to the x2 term.

Both reverted; the encoder is byte-identical to its parent apart from the
env-gated tf debug print. The numbers and the upgrade path -- gate the x2 on
content, since it pays on music transients and starves hein's speech -- are at
the decision site in celt_enc.rs.
crates/ec-opus/src/celt_enc.rsmodified+15 -4
@@ -891,10 +891,16 @@ impl CeltEncoder {
891891 // dynalloc boost minus calibration average (C:1651)
892892 target += total_boost - (19 << lm);
893893 // TF boost (C:1653-1654): MULT16_32_Q15 is identity in float mode,
894- // SHL32(.., 1) is the x2: 2 * (tf_estimate - 0.044) * target.
895- // Measured deviation: C applies SHL32(.., 1) (x2). On the 14-row
896- // library gate x2 loses .003 corr on reelm/hein@64 vs x1 (lane
897- // opus-vbr r2 vs r3); our tf_estimate is not scaled like libopus's.
894+ // SHL32(.., 1) is the x2 and tf_calibration is .04 at a fixed frame
895+ // size. MEASURED TWICE (lane opus-vbr r2/r3 on the old 14-row gate,
896+ // lane opustr r2 on the 12-row one): the x2 costs .0030 corr on
897+ // hein@64 and .0014 on hein@96 and pushes 5 err_ratio rows the
898+ // wrong way, so the x1 stand-in stays. The reelm rows that carried
899+ // the first rejection are gone; hein reproduced it exactly.
900+ // It is nonetheless the only lever measured to move the reell rows:
901+ // with it, reell@64 goes 2.697 -> 1.764 and reell@96 4.499 -> 2.114
902+ // (`lanes/opus-opustr-r2.sweep.txt`). Upgrade path: gate the x2 on
903+ // content -- it pays on music transients and starves hein's speech.
898904 target += ((tf_estimate - 0.044) * target as f32) as i32;
899905 // floor depth cap (C:1683-1695): SHR32/MULT16_32_Q15 are identity.
900906 {
@@ -941,6 +947,11 @@ impl CeltEncoder {
941947 // Release banked credit slowly (8 bytes per frame) so it stays
942948 // available for transient boosts; libopus CVBR re-adds all of
943949 // it to the next frame, which would defeat banking entirely.
950+ // MEASURED (lane opustr r3, `lanes/opus-opustr-r3.sweep.txt`):
951+ // restoring the libopus uncapped one-frame release on its own
952+ // is neutral-to-worse -- 3 rows better, 5 worse (dl8a@96
953+ // .374->.415, hein@96 .528->.555, her@96 1.051->1.064) and
954+ // hein@64 corr -.0008. The drip stays.
944955 let adjust = ((-self.vbr_reservoir) / (8 << BITRES)).min(8);
945956 if !silence {
946957 nb_avail += adjust;
crates/ec-opus/tests/conformance.rsmodified+7 -1
@@ -5586,8 +5586,14 @@ fn frame_decisions_vs_libopus() {
55865586 ref_rows.push(if ok { Some((p.len(), d.last_celt_diag().clone())) } else { None });
55875587 }
55885588
5589+ // Encode at the reference's REALISED rate, like the library gate does:
5590+ // ffmpeg's libopus overshoots its -b:a target by up to 12% on these
5591+ // sources, and a flat target makes every byte column meaningless.
5592+ let ref_bytes: usize = ref_pkts.iter().take(to).map(Vec::len).sum();
5593+ let ref_kbps = ref_bytes as f64 * 8.0 / (ref_pkts.len().min(to) as f64 * 0.02) / 1000.0;
5594+ println!("ffmpeg target {kbps} kbps, realised {ref_kbps:.1} kbps");
55895595 let mut enc = Encoder::new(48000, CH, Application::Audio).unwrap();
5590- enc.set_bitrate(kbps * 1000);
5596+ enc.set_bitrate((ref_kbps * 1000.0).round() as u32);
55915597 enc.set_vbr_constrained(true);
55925598 let mut dec = Decoder::new(48000, CH).unwrap();
55935599 let mut out = vec![0u8; 1500];
lanes/opus-opustr-r2.sweep.txtadded+14 -0
@@ -0,0 +1,14 @@
1+# lane-opustr r2 REVERTED: libopus CVBR restored whole -- tf boost 2*(tf_estimate-.04) AND
2+# the uncapped one-frame reservoir release. vs lanes/opus-opus64-r3.sweep.txt. 12 rows.
3+nik@64k: ref 69.2 ours 68.9 kbps (-0.3%), corr o=0.9885 r=0.9864 gap=-0.0022, Q o=-78.35 r=-154.78, err_ratio 0.632, minsec o=0.9764 r=0.9745, drop o=0 r=0
4+nik@96k: ref 101.0 ours 100.9 kbps (-0.1%), corr o=0.9947 r=0.9940 gap=-0.0006, Q o=-17.96 r=-31.55, err_ratio 0.881, minsec o=0.9883 r=0.9888, drop o=0 r=0
5+reelo@64k: ref 63.6 ours 63.4 kbps (-0.2%), corr o=0.9888 r=0.9866 gap=-0.0021, Q o=-202.91 r=-123.36, err_ratio 1.510, minsec o=0.9649 r=0.9686, drop o=0 r=0
6+reelo@96k: ref 93.9 ours 93.7 kbps (-0.1%), corr o=0.9945 r=0.9937 gap=-0.0008, Q o=-129.08 r=-125.18, err_ratio 1.023, minsec o=0.9847 r=0.9854, drop o=0 r=0
7+her@64k: ref 67.9 ours 67.8 kbps (-0.2%), corr o=0.9831 r=0.9794 gap=-0.0036, Q o=-367.21 r=-339.00, err_ratio 1.109, minsec o=0.9457 r=0.9406, drop o=0 r=0
8+her@96k: ref 101.5 ours 101.3 kbps (-0.2%), corr o=0.9912 r=0.9902 gap=-0.0010, Q o=-205.38 r=-191.50, err_ratio 1.068, minsec o=0.9715 r=0.9728, drop o=0 r=0
9+reell@64k: ref 71.3 ours 71.2 kbps (-0.1%), corr o=0.9907 r=0.9880 gap=-0.0027, Q o=-244.05 r=-128.39, err_ratio 1.764, minsec o=0.9709 r=0.9644, drop o=0 r=0
10+reell@96k: ref 105.4 ours 105.2 kbps (-0.1%), corr o=0.9956 r=0.9948 gap=-0.0008, Q o=-137.01 r=-29.16, err_ratio 2.114, minsec o=0.9853 r=0.9804, drop o=0 r=0
11+dl8a@64k: ref 65.8 ours 65.7 kbps (-0.1%), corr o=0.9884 r=0.9865 gap=-0.0019, Q o=-233.24 r=-378.84, err_ratio 0.566, minsec o=0.9778 r=0.9723, drop o=0 r=0
12+dl8a@96k: ref 96.8 ours 96.8 kbps (-0.0%), corr o=0.9941 r=0.9934 gap=-0.0007, Q o=-192.92 r=-423.47, err_ratio 0.403, minsec o=0.9877 r=0.9864, drop o=0 r=0
13+hein@64k: ref 64.9 ours 64.9 kbps (-0.0%), corr o=0.9858 r=0.9874 gap=+0.0016, Q o=-195.97 r=-388.31, err_ratio 0.462, minsec o=0.9139 r=0.9148, drop o=0 r=0
14+hein@96k: ref 86.9 ours 86.9 kbps (-0.0%), corr o=0.9932 r=0.9930 gap=-0.0002, Q o=-92.58 r=-246.46, err_ratio 0.451, minsec o=0.9620 r=0.9499, drop o=0 r=0
lanes/opus-opustr-r3.sweep.txtadded+14 -0
@@ -0,0 +1,14 @@
1+# lane-opustr r3 REVERTED: only the uncapped one-frame CVBR reservoir release (tf boost left at x1).
2+# vs lanes/opus-opus64-r3.sweep.txt. 12 rows (reelm.wav gone, its 2 rows SKIP).
3+nik@64k: ref 69.2 ours 69.0 kbps (-0.3%), corr o=0.9886 r=0.9864 gap=-0.0022, Q o=-81.38 r=-154.78, err_ratio 0.646, minsec o=0.9766 r=0.9745, drop o=0 r=0
4+nik@96k: ref 101.0 ours 100.9 kbps (-0.1%), corr o=0.9948 r=0.9940 gap=-0.0007, Q o=-30.21 r=-31.55, err_ratio 0.988, minsec o=0.9889 r=0.9888, drop o=0 r=0
5+reelo@64k: ref 63.6 ours 63.4 kbps (-0.2%), corr o=0.9891 r=0.9866 gap=-0.0024, Q o=-202.79 r=-123.36, err_ratio 1.509, minsec o=0.9673 r=0.9686, drop o=0 r=0
6+reelo@96k: ref 93.9 ours 93.7 kbps (-0.1%), corr o=0.9947 r=0.9937 gap=-0.0010, Q o=-108.03 r=-125.18, err_ratio 0.903, minsec o=0.9857 r=0.9854, drop o=0 r=0
7+her@64k: ref 67.9 ours 67.8 kbps (-0.2%), corr o=0.9834 r=0.9794 gap=-0.0039, Q o=-367.31 r=-339.00, err_ratio 1.109, minsec o=0.9475 r=0.9406, drop o=0 r=0
8+her@96k: ref 101.5 ours 101.3 kbps (-0.2%), corr o=0.9914 r=0.9902 gap=-0.0012, Q o=-204.58 r=-191.50, err_ratio 1.064, minsec o=0.9727 r=0.9728, drop o=0 r=0
9+reell@64k: ref 71.3 ours 71.3 kbps (-0.1%), corr o=0.9908 r=0.9880 gap=-0.0028, Q o=-351.70 r=-128.39, err_ratio 2.697, minsec o=0.9710 r=0.9644, drop o=0 r=0
10+reell@96k: ref 105.4 ours 105.2 kbps (-0.1%), corr o=0.9956 r=0.9948 gap=-0.0008, Q o=-301.83 r=-29.16, err_ratio 4.499, minsec o=0.9856 r=0.9804, drop o=0 r=0
11+dl8a@64k: ref 65.8 ours 65.7 kbps (-0.1%), corr o=0.9887 r=0.9865 gap=-0.0022, Q o=-227.27 r=-378.84, err_ratio 0.551, minsec o=0.9785 r=0.9723, drop o=0 r=0
12+dl8a@96k: ref 96.8 ours 96.8 kbps (-0.0%), corr o=0.9943 r=0.9934 gap=-0.0009, Q o=-199.03 r=-423.47, err_ratio 0.415, minsec o=0.9886 r=0.9864, drop o=0 r=0
13+hein@64k: ref 64.9 ours 64.9 kbps (-0.0%), corr o=0.9880 r=0.9874 gap=-0.0006, Q o=-344.06 r=-388.31, err_ratio 0.853, minsec o=0.9277 r=0.9148, drop o=0 r=0
14+hein@96k: ref 86.9 ours 86.9 kbps (-0.0%), corr o=0.9944 r=0.9930 gap=-0.0014, Q o=-126.54 r=-246.46, err_ratio 0.555, minsec o=0.9697 r=0.9499, drop o=0 r=0