forge
Explore
Log in

Don't you dare go Hollow

U8: ec-opus drop set_libopus_input_alignment and align_input; alignment is application != LowDelay (the default)

Browse files at this commit

b96276d41dfbb1a7b14f48f10ce08999ff1691eeAhmet Kaan GümüşParent: 76ef26d
crates/ec-opus/src/encoder.rsmodified+3 -59
@@ -54,8 +54,7 @@ enum Prefill {
54 }54 }
55 55
56 /// One MDCT overlap: the CELT layer's delay without libopus's input56 /// One MDCT overlap: the CELT layer's delay without libopus's input
57-/// alignment ([`Encoder::set_libopus_input_alignment`]), which adds57+/// alignment, which adds `delay_compensation = Fs/250` (192 at 48 kHz) on top.
58-/// `delay_compensation = Fs/250` (192 at 48 kHz) on top.
59 const CELT_OVERLAP_48K: usize = 120;58 const CELT_OVERLAP_48K: usize = 120;
60 /// libopus `opus_encoder.c`'s `delay_compensation = Fs/250`.59 /// libopus `opus_encoder.c`'s `delay_compensation = Fs/250`.
61 const CELT_DELAY_COMP_48K: usize = 192;60 const CELT_DELAY_COMP_48K: usize = 192;
@@ -294,8 +293,6 @@ pub struct Encoder {
294 /// 4088 bytes, and an inline array that size is a third of the whole293 /// 4088 bytes, and an inline array that size is a third of the whole
295 /// budget on the `Encoder` that a caller holds by value.294 /// budget on the `Encoder` that a caller holds by value.
296 silk_buf: Box<[u8; MAX_SILK_PACKET_BYTES]>,295 silk_buf: Box<[u8; MAX_SILK_PACKET_BYTES]>,
297- /// [`Encoder::set_libopus_input_alignment`].
298- align_input: bool,
299 filter: InputFilter,296 filter: InputFilter,
300 /// Scratch space for the filter's output, sized once.297 /// Scratch space for the filter's output, sized once.
301 hp_buf: Vec<f32>,298 hp_buf: Vec<f32>,
@@ -441,7 +438,6 @@ impl Encoder {
441 mode: None,438 mode: None,
442 silk: None,439 silk: None,
443 silk_buf: Box::new([0u8; MAX_SILK_PACKET_BYTES]),440 silk_buf: Box::new([0u8; MAX_SILK_PACKET_BYTES]),
444- align_input: application != Application::LowDelay,
445 filter: InputFilter::new(),441 filter: InputFilter::new(),
446 hp_buf: Vec::new(),442 hp_buf: Vec::new(),
447 delay_buffer: vec![0.0; encoder_buffer(sample_rate) * channels],443 delay_buffer: vec![0.0; encoder_buffer(sample_rate) * channels],
@@ -516,65 +512,13 @@ impl Encoder {
516 /// libopus's `delay_compensation` when the alignment is on.512 /// libopus's `delay_compensation` when the alignment is on.
517 fn celt_look_ahead_48k(&self) -> usize {513 fn celt_look_ahead_48k(&self) -> usize {
518 CELT_OVERLAP_48K514 CELT_OVERLAP_48K
519- + if self.align_input {515+ + if self.application != Application::LowDelay {
520 CELT_DELAY_COMP_48K516 CELT_DELAY_COMP_48K
521 } else {517 } else {
522 0518 0
523 }519 }
524 }520 }
525 521
526- /// On by default except for [`Application::LowDelay`], as in libopus: the
527- /// SILK layer's own delay is 312 samples, and only an aligned CELT layer
528- /// keeps CELT, SILK and hybrid frames of one stream at the same delay.
529- ///
530- /// Puts our CELT analysis window exactly where libopus's is: the layer is
531- /// fed the input delayed by `delay_compensation = Fs/250` (192 samples at
532- /// 48 kHz, `opus_encoder.c` ~:1955) and every frame first goes through
533- /// libopus's 3 Hz `dc_reject`. The alignment is *exact* — on the reell
534- /// attack frame (frame 2, 20 ms, LM=3, transient) our first eight band
535- /// log-energies become
536- /// 3.4386 4.0055 3.2603 4.5954 1.1790 4.2774 4.7584 3.7169 against
537- /// libopus's 3.439 4.005 3.260 4.595 1.179 4.277 4.758 3.717, all eight
538- /// within .0006 (the unaligned encoder is .06-.21 apart).
539- ///
540- /// It ships OFF because the 12-row library gate rejects it, and because
541- /// re-tuning the constants that were fitted on the misaligned spectrum
542- /// does not rescue it. Against the shipped rows
543- /// (`lanes/opus-opustr2-r1.sweep.txt`), err_ratio:
544- ///
545- /// | arm | better | worse (blocking) |
546- /// |---|---|---|
547- /// | delay only (`opus-opusx-r1`) | 7 | nik@64 .708→.800, nik@96 .985→1.763, her@96 1.051→1.292, hein@64 .853→.980, hein@96 .528→1.602 |
548- /// | delay + `dc_reject` (`opus-opusx2-r1`) | 5 | those, plus dl8a@64 .552→1.074, dl8a@96 .374→1.011 |
549- /// | + two-pass coarse energy (`-r2`) | 5 | same 7 rows (nik@96 1.809, dl8a@64 1.200) |
550- /// | + continuous 1.3 `alloc_trim` (`-r3`) | 5 | same 7, and corr worse by >.0005 on 9 rows |
551- /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 |
552- /// | + tf boost k=1.5 (`-r5`) | 5 | same 7 |
553- /// | + 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 |
554- /// | + 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 |
555- ///
556- /// The best aligned arm on the KEEP rule is the delay alone without
557- /// `dc_reject` (5 rows worse); every arm that adds `dc_reject` puts dl8a
558- /// in the blocking set too.
559- ///
560- /// The last row is the one that was expected to rescue this: libopus's
561- /// actual operating point is the aligned spectrum *with* `analysis->valid`
562- /// true, and running the real analysis (`crates/ec-opus/src/analysis.rs`,
563- /// `music_prob` matching a patched-libopus trace to .001) moves reell@64
564- /// 2.697→1.865, reell@96 4.499→3.986, reelo@64 1.510→1.123 and her@64
565- /// 1.103→.952 — the largest movement any arm has produced on those rows —
566- /// and still leaves the same seven rows worse.
567- ///
568- /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and
569- /// no arm moves any of those rows back towards its shipped value, so the
570- /// misfit is not one of the swept constants. Turning this on also costs
571- /// 4 ms of algorithmic delay: [`Encoder::look_ahead`] for a CELT frame
572- /// becomes 312, not 120, and the Ogg pre-skip must follow it.
573- pub fn set_libopus_input_alignment(&mut self, on: bool) {
574- self.align_input = on;
575- self.filter = InputFilter::new();
576- }
577-
578 /// Forces the coded bandwidth; [`None`] (the default) picks it from the522 /// Forces the coded bandwidth; [`None`] (the default) picks it from the
579 /// bitrate, the application and the input's Nyquist.523 /// bitrate, the application and the input's Nyquist.
580 pub fn set_bandwidth(&mut self, bandwidth: Option<Bandwidth>) {524 pub fn set_bandwidth(&mut self, bandwidth: Option<Bandwidth>) {
@@ -1929,7 +1873,7 @@ impl Encoder {
1929 }1873 }
1930 1874
1931 fn total_buffer(&self) -> usize {1875 fn total_buffer(&self) -> usize {
1932- if self.align_input {1876+ if self.application != Application::LowDelay {
1933 self.sample_rate as usize / 2501877 self.sample_rate as usize / 250
1934 } else {1878 } else {
1935 01879 0