forge
Explore
Log in

Don't you dare go Hollow

The oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's row

Browse files at this commit

1387bbe52a0bffae5dcd74989c6a80ada74b944eAhmet Kaan GümüşParent: 28054d0
  • test
    • the oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's row
Show full message
test(opus): the oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's row

oracle_decode wrote a 120-sample pre-skip whatever the stream's delay was, so
comparing it sample-for-sample against our own decode at the advertised offset
was 192 samples out under the alignment (hybrid_fb_roundtrip: oracle corr
0.028).  It takes the pre-skip from the caller now; the hybrid site passes the
encoder's look_ahead, and all seven rewritten lag tests pass with
EC_OPUS_ALIGN=1 as well as with the default.

r7 (two-pass coarse energy + tf boost k=1.25 on the aligned tree) is the best
combined arm and still leaves the same seven rows worse; its row is in the
table at set_libopus_input_alignment.
crates/ec-opus/src/encoder.rsmodified+5 -0
@@ -272,6 +272,11 @@ impl Encoder {
272272 /// | + continuous 1.3 `alloc_trim` (`-r3`) | 5 | same 7, and corr worse by >.0005 on 9 rows |
273273 /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 |
274274 /// | + tf boost k=1.5 (`-r5`) | 5 | same 7 |
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+ ///
277+ /// The best aligned arm on the KEEP rule is the delay alone without
278+ /// `dc_reject` (5 rows worse); every arm that adds `dc_reject` puts dl8a
279+ /// in the blocking set too.
275280 ///
276281 /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and
277282 /// no arm moves any of those rows back towards its shipped value, so the
crates/ec-opus/tests/conformance.rsmodified+15 -6
@@ -2109,7 +2109,7 @@ fn silk_mediumband_and_10ms_roundtrip() {
21092109 frame_ms == 10 || voiced > 0,
21102110 "{tag}: no frame coded with LTP"
21112111 );
2112- if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len()) {
2112+ if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len(), 120) {
21132113 let (c, _) = aligned_corr(&oracle, &decoded, 2000);
21142114 assert!(c >= 0.99, "{tag}: our decode vs oracle decode corr {c:.4}");
21152115 }
@@ -2159,7 +2159,7 @@ fn silk_multiframe_packets_roundtrip() {
21592159 );
21602160 assert!(corr >= floor, "{tag}: corr {corr:.4} below {floor:.4}");
21612161 assert!(voiced > 0, "{tag}: no frame coded with LTP");
2162- if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len()) {
2162+ if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len(), 120) {
21632163 let (c, _) = aligned_corr(&oracle, &decoded, 2500);
21642164 assert!(
21652165 c >= 0.99,
@@ -2366,12 +2366,21 @@ fn silk_compares_to_celt_on_speech_at_speech_rates() {
23662366 }
23672367
23682368 /// Reference oracle decode of `packets` as Ogg-Opus, or `None` without ffmpeg.
2369-fn oracle_decode(name: &str, packets: &[Vec<u8>], samples: usize) -> Option<Vec<f32>> {
2369+/// `pre_skip` must be the encoder's advertised [`Encoder::look_ahead`] for
2370+/// these packets: it is what the oracle trims off the front, so a caller that
2371+/// compares sample-for-sample against its own decode at that same offset only
2372+/// lines up when the two agree.
2373+fn oracle_decode(
2374+ name: &str,
2375+ packets: &[Vec<u8>],
2376+ samples: usize,
2377+ pre_skip: usize,
2378+) -> Option<Vec<f32>> {
23702379 if Command::new("ffmpeg").arg("-version").output().is_err() {
23712380 return None;
23722381 }
23732382 let path = temp_path(&format!("{name}.opus"));
2374- write_ogg_opus(&path, packets, opus_head(1, 120, None), 1, samples, 120);
2383+ write_ogg_opus(&path, packets, opus_head(1, pre_skip as u16, None), 1, samples, pre_skip as i64);
23752384 let out = Command::new("ffmpeg")
23762385 .args(["-v", "warning", "-c:a", "libopus", "-i"])
23772386 .arg(&path)
@@ -2418,7 +2427,7 @@ fn silk_nsq_improves_quality_at_equal_rate() {
24182427 "{name}: corr {corr:.4} (floor {floor}) at {kbps:.1} kbps"
24192428 ));
24202429 }
2421- if let Some(oracle) = oracle_decode(&format!("silk-nsq-{name}"), &packets, pcm.len()) {
2430+ if let Some(oracle) = oracle_decode(&format!("silk-nsq-{name}"), &packets, pcm.len(), 120) {
24222431 let (c, _) = aligned_corr(&oracle, &decoded, 2000);
24232432 assert!(c >= 0.99, "{name}: our decode vs oracle decode corr {c:.4}");
24242433 }
@@ -2584,7 +2593,7 @@ fn hybrid_fb_roundtrip() {
25842593 (28.0..=36.0).contains(&kbps),
25852594 "{name}: {kbps:.1} kbps for a 32 kbps CBR target"
25862595 );
2587- if let Some(oracle) = oracle_decode(&format!("hybrid-{name}"), &packets, pcm.len()) {
2596+ if let Some(oracle) = oracle_decode(&format!("hybrid-{name}"), &packets, pcm.len(), delay) {
25882597 let n = oracle.len().min(decoded.len() - delay);
25892598 let c = correlation(&oracle[..n], &decoded[delay..delay + n]);
25902599 eprintln!("hybrid FB {name}: oracle vs ours corr {c:.4}");
lanes/opus-opusx2-r7.sweep.txtadded+16 -0
@@ -0,0 +1,16 @@
1+# lane-opusx2 r7: aligned tree + two-pass coarse energy + tf boost k=1.25 (combined winners)
2+# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1)
3+# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo
4+# 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
5+nik 64 69.1 69.2 -0.1 0.9883 0.9864 -0.0020 -109.28 -154.78 0.773 0.9766 0.9745 0 0
6+nik 96 100.9 101.0 -0.1 0.9943 0.9940 -0.0003 -113.00 -31.55 1.801 0.9889 0.9888 0 0
7+reelo 64 63.5 63.6 -0.1 0.9887 0.9866 -0.0020 -177.31 -123.36 1.335 0.9701 0.9686 0 0
8+reelo 96 93.3 93.9 -0.6 0.9943 0.9937 -0.0005 -89.23 -125.18 0.801 0.9870 0.9854 0 0
9+her 64 67.6 67.9 -0.5 0.9827 0.9794 -0.0033 -309.55 -339.00 0.894 0.9475 0.9406 0 0
10+her 96 100.7 101.5 -0.7 0.9915 0.9902 -0.0012 -214.59 -191.50 1.114 0.9768 0.9728 0 0
11+reell 64 71.3 71.3 -0.0 0.9904 0.9880 -0.0024 -271.04 -128.39 1.975 0.9712 0.9644 0 0
12+reell 96 105.3 105.4 -0.0 0.9952 0.9948 -0.0004 -262.90 -29.16 3.846 0.9852 0.9804 0 0
13+dl8a 64 65.7 65.8 -0.2 0.9885 0.9865 -0.0020 -426.86 -378.84 1.181 0.9789 0.9723 0 0
14+dl8a 96 96.4 96.8 -0.4 0.9937 0.9934 -0.0003 -427.68 -423.47 1.014 0.9871 0.9864 0 0
15+hein 64 64.7 64.9 -0.3 0.9884 0.9874 -0.0010 -381.78 -388.31 0.977 0.9320 0.9148 0 0
16+hein 96 86.7 86.9 -0.3 0.9942 0.9930 -0.0012 -330.35 -246.46 1.398 0.9681 0.9499 0 0