The oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's row
Browse files at this commit1387bbe52a0bffae5dcd74989c6a80ada74b944eParent: 28054d0- test
- the oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's row
3 changed files +36 -6
- crates/ec-opus/src/encoder.rs +5 -0
- crates/ec-opus/tests/conformance.rs +15 -6
- lanes/opus-opusx2-r7.sweep.txt +16 -0
crates/ec-opus/src/encoder.rsmodified+5 -0
| @@ -272,6 +272,11 @@ impl Encoder { | |||
| 272 | /// | + continuous 1.3 `alloc_trim` (`-r3`) | 5 | same 7, and corr worse by >.0005 on 9 rows | | 272 | /// | + continuous 1.3 `alloc_trim` (`-r3`) | 5 | same 7, and corr worse by >.0005 on 9 rows | |
| 273 | /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 | | 273 | /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 | |
| 274 | /// | + tf boost k=1.5 (`-r5`) | 5 | same 7 | | 274 | /// | + 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. | ||
| 275 | /// | 280 | /// |
| 276 | /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and | 281 | /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and |
| 277 | /// no arm moves any of those rows back towards its shipped value, so the | 282 | /// 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() { | |||
| 2109 | frame_ms == 10 || voiced > 0, | 2109 | frame_ms == 10 || voiced > 0, |
| 2110 | "{tag}: no frame coded with LTP" | 2110 | "{tag}: no frame coded with LTP" |
| 2111 | ); | 2111 | ); |
| 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) { |
| 2113 | let (c, _) = aligned_corr(&oracle, &decoded, 2000); | 2113 | let (c, _) = aligned_corr(&oracle, &decoded, 2000); |
| 2114 | assert!(c >= 0.99, "{tag}: our decode vs oracle decode corr {c:.4}"); | 2114 | assert!(c >= 0.99, "{tag}: our decode vs oracle decode corr {c:.4}"); |
| 2115 | } | 2115 | } |
| @@ -2159,7 +2159,7 @@ fn silk_multiframe_packets_roundtrip() { | |||
| 2159 | ); | 2159 | ); |
| 2160 | assert!(corr >= floor, "{tag}: corr {corr:.4} below {floor:.4}"); | 2160 | assert!(corr >= floor, "{tag}: corr {corr:.4} below {floor:.4}"); |
| 2161 | assert!(voiced > 0, "{tag}: no frame coded with LTP"); | 2161 | 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) { |
| 2163 | let (c, _) = aligned_corr(&oracle, &decoded, 2500); | 2163 | let (c, _) = aligned_corr(&oracle, &decoded, 2500); |
| 2164 | assert!( | 2164 | assert!( |
| 2165 | c >= 0.99, | 2165 | c >= 0.99, |
| @@ -2366,12 +2366,21 @@ fn silk_compares_to_celt_on_speech_at_speech_rates() { | |||
| 2366 | } | 2366 | } |
| 2367 | 2367 | ||
| 2368 | /// Reference oracle decode of `packets` as Ogg-Opus, or `None` without ffmpeg. | 2368 | /// 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>> { | ||
| 2370 | if Command::new("ffmpeg").arg("-version").output().is_err() { | 2379 | if Command::new("ffmpeg").arg("-version").output().is_err() { |
| 2371 | return None; | 2380 | return None; |
| 2372 | } | 2381 | } |
| 2373 | let path = temp_path(&format!("{name}.opus")); | 2382 | 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); |
| 2375 | let out = Command::new("ffmpeg") | 2384 | let out = Command::new("ffmpeg") |
| 2376 | .args(["-v", "warning", "-c:a", "libopus", "-i"]) | 2385 | .args(["-v", "warning", "-c:a", "libopus", "-i"]) |
| 2377 | .arg(&path) | 2386 | .arg(&path) |
| @@ -2418,7 +2427,7 @@ fn silk_nsq_improves_quality_at_equal_rate() { | |||
| 2418 | "{name}: corr {corr:.4} (floor {floor}) at {kbps:.1} kbps" | 2427 | "{name}: corr {corr:.4} (floor {floor}) at {kbps:.1} kbps" |
| 2419 | )); | 2428 | )); |
| 2420 | } | 2429 | } |
| 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) { |
| 2422 | let (c, _) = aligned_corr(&oracle, &decoded, 2000); | 2431 | let (c, _) = aligned_corr(&oracle, &decoded, 2000); |
| 2423 | assert!(c >= 0.99, "{name}: our decode vs oracle decode corr {c:.4}"); | 2432 | assert!(c >= 0.99, "{name}: our decode vs oracle decode corr {c:.4}"); |
| 2424 | } | 2433 | } |
| @@ -2584,7 +2593,7 @@ fn hybrid_fb_roundtrip() { | |||
| 2584 | (28.0..=36.0).contains(&kbps), | 2593 | (28.0..=36.0).contains(&kbps), |
| 2585 | "{name}: {kbps:.1} kbps for a 32 kbps CBR target" | 2594 | "{name}: {kbps:.1} kbps for a 32 kbps CBR target" |
| 2586 | ); | 2595 | ); |
| 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) { |
| 2588 | let n = oracle.len().min(decoded.len() - delay); | 2597 | let n = oracle.len().min(decoded.len() - delay); |
| 2589 | let c = correlation(&oracle[..n], &decoded[delay..delay + n]); | 2598 | let c = correlation(&oracle[..n], &decoded[delay..delay + n]); |
| 2590 | eprintln!("hybrid FB {name}: oracle vs ours corr {c:.4}"); | 2599 | 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 | ||