The 12-row gate rows for the Fs/250 CELT input delay, and the alignment constants it moves
Browse files at this commit1af3439583fea8ded05a667bf15f31886b2b0aceParent: 5d7f93b- test
- the 12-row gate rows for the Fs/250 CELT input delay, and the alignment constants it moves
4 changed files +39 -22
- crates/ec-opus/src/encoder.rs +6 -6
- crates/ec-opus/tests/conformance.rs +6 -4
- lanes/opus-gate-r1.sweep.txt +12 -12
- lanes/opus-opusx-r1.sweep.txt +15 -0
crates/ec-opus/src/encoder.rsmodified+6 -6
| @@ -902,33 +902,33 @@ mod tests { | ||
| 902 | 902 | let mut e = Encoder::new(24000, 2, Application::Audio).unwrap(); |
| 903 | 903 | e.set_bitrate(256_000); |
| 904 | 904 | assert_eq!(e.auto_bandwidth(), Bandwidth::SuperWide); |
| 905 | - assert_eq!(e.look_ahead(960), 60); | |
| 905 | + assert_eq!(e.look_ahead(960), CELT_LOOK_AHEAD_48K / 2); | |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | /// `look_ahead` must use the same 10-or-20 ms-frame predicate dispatch |
| 909 | 909 | /// does (`silk_choice`/`hybrid_choice`), not just `wants_silk`: 2.5/5 ms |
| 910 | 910 | /// frames still code as CELT, while 10/20 ms speech follows SILK and |
| 911 | - /// hybrid follows CELT's overlap. | |
| 911 | + /// hybrid follows CELT's delay. | |
| 912 | 912 | #[test] |
| 913 | 913 | fn look_ahead_matches_the_frame_size_dispatch_actually_uses() { |
| 914 | 914 | let mut e = Encoder::new(48000, 1, Application::Voip).unwrap(); |
| 915 | 915 | e.set_bitrate(8000); |
| 916 | 916 | assert_eq!(e.look_ahead(480), 58, "10ms NB SILK"); |
| 917 | - assert_eq!(e.look_ahead(240), 120, "5ms frame falls back to CELT"); | |
| 917 | + assert_eq!(e.look_ahead(240), CELT_LOOK_AHEAD_48K, "5ms frame falls back to CELT"); | |
| 918 | 918 | assert_eq!(e.look_ahead(960), 58, "20ms NB SILK"); |
| 919 | 919 | |
| 920 | 920 | // 16k VoIP is hybrid-FB since the libopus threshold port (CELT overlap). |
| 921 | 921 | e.set_bitrate(16000); |
| 922 | - assert_eq!(e.look_ahead(960), 120, "20ms hybrid FB"); | |
| 922 | + assert_eq!(e.look_ahead(960), CELT_LOOK_AHEAD_48K, "20ms hybrid FB"); | |
| 923 | 923 | |
| 924 | 924 | e.set_bitrate(32000); |
| 925 | - assert_eq!(e.look_ahead(960), 120, "20ms hybrid, CELT's overlap"); | |
| 925 | + assert_eq!(e.look_ahead(960), CELT_LOOK_AHEAD_48K, "20ms hybrid, CELT's delay"); | |
| 926 | 926 | |
| 927 | 927 | let mut e = Encoder::new(48000, 2, Application::Voip).unwrap(); |
| 928 | 928 | e.set_bitrate(8000); |
| 929 | 929 | assert_eq!(e.look_ahead(960), 58, "stereo 20ms NB SILK"); |
| 930 | 930 | e.set_bitrate(64_000); |
| 931 | - assert_eq!(e.look_ahead(960), 120, "stereo 20ms hybrid"); | |
| 931 | + assert_eq!(e.look_ahead(960), CELT_LOOK_AHEAD_48K, "stereo 20ms hybrid"); | |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | #[test] |
crates/ec-opus/tests/conformance.rsmodified+6 -4
| @@ -1303,8 +1303,9 @@ use ec_ogg::OggMuxer; | ||
| 1303 | 1303 | |
| 1304 | 1304 | /// The RFC 7845 identification header for this encoder — built by the crate's |
| 1305 | 1305 | /// own [`ec_opus::ogg`] helper, so a muxer and the encoder cannot disagree. |
| 1306 | -/// `pre_skip` is the encoder's [`Encoder::look_ahead`]: 120, the CELT overlap | |
| 1307 | -/// delay, for every CELT call site; SILK's own (larger) delay for SILK. | |
| 1306 | +/// `pre_skip` is the encoder's [`Encoder::look_ahead`]: 312, the CELT overlap | |
| 1307 | +/// plus its input delay compensation, for every CELT call site; SILK's own | |
| 1308 | +/// delay for SILK. | |
| 1308 | 1309 | fn opus_head(channels: usize, pre_skip: u16, layout: Option<(usize, usize, &[u8])>) -> Vec<u8> { |
| 1309 | 1310 | let mapping = |
| 1310 | 1311 | layout.map(|(streams, coupled, table)| (1u8, streams as u8, coupled as u8, table)); |
| @@ -2510,14 +2511,15 @@ fn hybrid_layers_align() { | ||
| 2510 | 2511 | e.look_ahead(960) |
| 2511 | 2512 | } |
| 2512 | 2513 | ); |
| 2513 | - // A fullband CELT click lands at exactly +120 (`celt_click_peak_offset`); | |
| 2514 | + // A fullband CELT click lands at exactly +312 (`celt_click_peak_offset`: | |
| 2515 | + // the MDCT overlap plus the 192-sample input delay compensation); | |
| 2514 | 2516 | // the band-limited HB layer's main lobe sits up to 2 samples early once |
| 2515 | 2517 | // transient frames keep their short blocks, and SILK lands at +121. |
| 2516 | 2518 | assert!( |
| 2517 | 2519 | (plb - phb).abs() <= 3, |
| 2518 | 2520 | "layers misaligned: LB +{plb} vs HB +{phb}" |
| 2519 | 2521 | ); |
| 2520 | - assert!((phb - 120).abs() <= 2, "HB peak +{phb}, look_ahead 120"); | |
| 2522 | + assert!((phb - 312).abs() <= 2, "HB peak +{phb}, look_ahead 312"); | |
| 2521 | 2523 | } |
| 2522 | 2524 | |
| 2523 | 2525 | /// 20 ms FB hybrid at 32 kbps: decodes in our decoder range-exactly, tracks |
lanes/opus-gate-r1.sweep.txtmodified+12 -12
| @@ -1,15 +1,15 @@ | ||
| 1 | 1 | # ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) |
| 2 | 2 | # both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo |
| 3 | 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.1 69.2 -0.1 0.9887 0.9864 -0.0023 -80.86 -154.78 0.643 0.9767 0.9745 0 0 | |
| 5 | -nik 96 100.9 101.0 -0.1 0.9947 0.9940 -0.0007 -26.28 -31.55 0.954 0.9886 0.9888 0 0 | |
| 6 | -reelo 64 63.5 63.6 -0.1 0.9893 0.9866 -0.0026 -202.81 -123.36 1.509 0.9699 0.9686 0 0 | |
| 7 | -reelo 96 93.3 93.9 -0.6 0.9946 0.9937 -0.0008 -112.54 -125.18 0.928 0.9861 0.9854 0 0 | |
| 8 | -her 64 67.6 67.9 -0.6 0.9833 0.9794 -0.0039 -366.18 -339.00 1.104 0.9471 0.9406 0 0 | |
| 9 | -her 96 100.8 101.5 -0.7 0.9913 0.9902 -0.0010 -206.21 -191.50 1.072 0.9724 0.9728 0 0 | |
| 10 | -reell 64 71.3 71.3 -0.0 0.9908 0.9880 -0.0028 -198.89 -128.39 1.440 0.9718 0.9644 0 0 | |
| 11 | -reell 96 105.3 105.4 -0.0 0.9956 0.9948 -0.0008 -169.83 -29.16 2.516 0.9854 0.9804 0 0 | |
| 12 | -dl8a 64 65.7 65.8 -0.2 0.9889 0.9865 -0.0024 -221.23 -378.84 0.536 0.9794 0.9723 0 0 | |
| 13 | -dl8a 96 96.5 96.8 -0.4 0.9942 0.9934 -0.0008 -144.33 -423.47 0.315 0.9878 0.9864 0 0 | |
| 14 | -hein 64 64.7 64.9 -0.3 0.9883 0.9874 -0.0009 -115.57 -388.31 0.302 0.9286 0.9148 0 0 | |
| 15 | -hein 96 86.7 86.9 -0.3 0.9942 0.9930 -0.0012 -105.73 -246.46 0.490 0.9664 0.9499 0 0 | |
| 4 | +nik 64 69.1 69.2 -0.1 0.9887 0.9864 -0.0023 -114.88 -154.78 0.800 0.9769 0.9745 0 0 | |
| 5 | +nik 96 100.9 101.0 -0.1 0.9947 0.9940 -0.0007 -109.44 -31.55 1.763 0.9891 0.9888 0 0 | |
| 6 | +reelo 64 63.6 63.6 -0.0 0.9894 0.9866 -0.0028 -170.07 -123.36 1.287 0.9709 0.9686 0 0 | |
| 7 | +reelo 96 93.4 93.9 -0.5 0.9950 0.9937 -0.0013 -100.39 -125.18 0.861 0.9875 0.9854 0 0 | |
| 8 | +her 64 67.6 67.9 -0.4 0.9837 0.9794 -0.0042 -333.52 -339.00 0.980 0.9481 0.9406 0 0 | |
| 9 | +her 96 101.0 101.5 -0.5 0.9925 0.9902 -0.0022 -248.22 -191.50 1.292 0.9774 0.9728 0 0 | |
| 10 | +reell 64 71.3 71.3 -0.0 0.9908 0.9880 -0.0028 -263.61 -128.39 1.916 0.9717 0.9644 0 0 | |
| 11 | +reell 96 105.3 105.4 -0.0 0.9956 0.9948 -0.0008 -266.25 -29.16 3.900 0.9856 0.9804 0 0 | |
| 12 | +dl8a 64 65.7 65.8 -0.1 0.9890 0.9865 -0.0025 -204.82 -378.84 0.498 0.9789 0.9723 0 0 | |
| 13 | +dl8a 96 96.6 96.8 -0.3 0.9943 0.9934 -0.0009 -170.45 -423.47 0.361 0.9882 0.9864 0 0 | |
| 14 | +hein 64 64.8 64.9 -0.2 0.9888 0.9874 -0.0014 -382.47 -388.31 0.980 0.9345 0.9148 0 0 | |
| 15 | +hein 96 86.8 86.9 -0.2 0.9945 0.9930 -0.0015 -367.35 -246.46 1.602 0.9700 0.9499 0 0 |
lanes/opus-opusx-r1.sweep.txtadded+15 -0
| @@ -0,0 +1,15 @@ | ||
| 1 | +# lane-opusx r1: CELT input delayed by Fs/250 (192 samples) like libopus opus_encoder.c | |
| 2 | +# baseline lanes/opus-opustr2-r1.sweep.txt; same 12 rows, same recipe | |
| 3 | +# VERDICT: FAILS the KEEP rule -- err_ratio worse on 5 of 12 rows (better on 7), corr never worse by >.0005 | |
| 4 | +nik@64k: ref 69.2 ours 69.1 kbps (-0.1%), corr o=0.9887 r=0.9864 gap=-0.0023, Q o=-114.88 r=-154.78, err_ratio 0.800, minsec o=0.9769 r=0.9745, drop o=0 r=0 | |
| 5 | +nik@96k: ref 101.0 ours 100.9 kbps (-0.1%), corr o=0.9947 r=0.9940 gap=-0.0007, Q o=-109.44 r=-31.55, err_ratio 1.763, minsec o=0.9891 r=0.9888, drop o=0 r=0 | |
| 6 | +reelo@64k: ref 63.6 ours 63.6 kbps (-0.0%), corr o=0.9894 r=0.9866 gap=-0.0028, Q o=-170.07 r=-123.36, err_ratio 1.287, minsec o=0.9709 r=0.9686, drop o=0 r=0 | |
| 7 | +reelo@96k: ref 93.9 ours 93.4 kbps (-0.5%), corr o=0.9950 r=0.9937 gap=-0.0013, Q o=-100.39 r=-125.18, err_ratio 0.861, minsec o=0.9875 r=0.9854, drop o=0 r=0 | |
| 8 | +her@64k: ref 67.9 ours 67.6 kbps (-0.4%), corr o=0.9837 r=0.9794 gap=-0.0042, Q o=-333.52 r=-339.00, err_ratio 0.980, minsec o=0.9481 r=0.9406, drop o=0 r=0 | |
| 9 | +her@96k: ref 101.5 ours 101.0 kbps (-0.5%), corr o=0.9925 r=0.9902 gap=-0.0022, Q o=-248.22 r=-191.50, err_ratio 1.292, minsec o=0.9774 r=0.9728, drop o=0 r=0 | |
| 10 | +reell@64k: ref 71.3 ours 71.3 kbps (-0.0%), corr o=0.9908 r=0.9880 gap=-0.0028, Q o=-263.61 r=-128.39, err_ratio 1.916, minsec o=0.9717 r=0.9644, drop o=0 r=0 | |
| 11 | +reell@96k: ref 105.4 ours 105.3 kbps (-0.0%), corr o=0.9956 r=0.9948 gap=-0.0008, Q o=-266.25 r=-29.16, err_ratio 3.900, minsec o=0.9856 r=0.9804, drop o=0 r=0 | |
| 12 | +dl8a@64k: ref 65.8 ours 65.7 kbps (-0.1%), corr o=0.9890 r=0.9865 gap=-0.0025, Q o=-204.82 r=-378.84, err_ratio 0.498, minsec o=0.9789 r=0.9723, drop o=0 r=0 | |
| 13 | +dl8a@96k: ref 96.8 ours 96.6 kbps (-0.3%), corr o=0.9943 r=0.9934 gap=-0.0009, Q o=-170.45 r=-423.47, err_ratio 0.361, minsec o=0.9882 r=0.9864, drop o=0 r=0 | |
| 14 | +hein@64k: ref 64.9 ours 64.8 kbps (-0.2%), corr o=0.9888 r=0.9874 gap=-0.0014, Q o=-382.47 r=-388.31, err_ratio 0.980, minsec o=0.9345 r=0.9148, drop o=0 r=0 | |
| 15 | +hein@96k: ref 86.9 ours 86.8 kbps (-0.2%), corr o=0.9945 r=0.9930 gap=-0.0015, Q o=-367.35 r=-246.46, err_ratio 1.602, minsec o=0.9700 r=0.9499, drop o=0 r=0 |