diff --git a/crates/ec-opus/src/celt_enc.rs b/crates/ec-opus/src/celt_enc.rs index 37bb1583..23919409 100644 --- a/crates/ec-opus/src/celt_enc.rs +++ b/crates/ec-opus/src/celt_enc.rs @@ -78,6 +78,10 @@ const INV_TABLE: [u8; 128] = [ /// One forward-MDCT plan, the exact adjoint of the decoder's `ImdctPlan`: /// window-fold, pre-rotation, an `l/2`-point FFT and post-rotation, scaled by /// `2/l` so that decode(encode(x)) reconstructs at unit gain. +/// libopus `opus_encoder.c`'s `delay_compensation = Fs/250`: how far behind +/// the API frame the CELT analysis window sits, in 48 kHz samples. +const CELT_DELAY_48K: usize = 192; + #[derive(Clone, Debug)] struct MdctPlan { l: usize, @@ -382,6 +386,14 @@ pub struct CeltEncoder { plans: Vec, /// Preemphasised history, `channels * OVERLAP`. in_mem: Vec, + /// libopus `opus_encoder.c`'s `delay_buffer`: the CELT layer is fed the + /// input delayed by `delay_compensation = Fs/250` (192 samples at 48 kHz), + /// so its analysis window sits 4 ms behind the API frame. Interleaved, + /// `CELT_DELAY_48K / upsample` samples per channel. + delay_buf: Vec, + /// Whether that delay is applied at all — see + /// [`crate::Encoder::set_libopus_input_alignment`] for why it ships off. + align_input: bool, preemph_mem: [f32; 2], /// Coarse-energy prediction state, `2 * NB_BANDS`. old_band_e: Vec, @@ -450,6 +462,8 @@ impl CeltEncoder { window: celt::overlap_window(), plans: (0..4).map(|lm| MdctPlan::new(SHORT_MDCT << lm)).collect(), in_mem: vec![0.0; channels * OVERLAP], + delay_buf: vec![0.0; channels * CELT_DELAY_48K], + align_input: false, preemph_mem: [0.0; 2], old_band_e: vec![0.0; 2 * NB_BANDS], delayed_intra: 1.0, @@ -506,9 +520,17 @@ impl CeltEncoder { &self.last_diag } + /// Feeds the layer the input delayed by `CELT_DELAY_48K`, as libopus + /// does; see [`crate::Encoder::set_libopus_input_alignment`]. + pub fn set_align_input(&mut self, on: bool) { + self.align_input = on; + self.delay_buf.fill(0.0); + } + /// Drops all inter-frame state. pub fn reset(&mut self) { self.in_mem.fill(0.0); + self.delay_buf.fill(0.0); self.preemph_mem = [0.0; 2]; self.old_band_e.fill(0.0); self.delayed_intra = 1.0; @@ -599,20 +621,29 @@ impl CeltEncoder { // --- Preemphasis ---------------------------------------------------- let stride = n + OVERLAP; let mut silence = true; + let mut delay = std::mem::take(&mut self.delay_buf); + let mut next_delay = [0.0f32; 2 * CELT_DELAY_48K]; for ch in 0..c { let base = ch * stride; self.in_buf[base..base + OVERLAP] .copy_from_slice(&self.in_mem[ch * OVERLAP..(ch + 1) * OVERLAP]); let mut mem = self.preemph_mem[ch]; let up = self.upsample; + // `src(j)`: input sample `j` of the delayed stream libopus's CELT + // layer sees -- the `d` samples held over from the previous call + // first, then this frame's. + let d = if self.align_input { CELT_DELAY_48K / up } else { 0 }; + let src = |j: usize| { + if j < d { delay[j * c + ch] } else { pcm[(j - d) * c + ch] } + }; for i in 0..n { // Zero-stuffing to 48 kHz: the images above the input's own // Nyquist are never coded (the caller caps `end`) and the // decoder's decimation drops them. let mut x = if up == 1 { - pcm[i * c + ch] * SIG_SCALE + src(i) * SIG_SCALE } else if i.is_multiple_of(up) { - pcm[(i / up) * c + ch] * SIG_SCALE * up as f32 + src(i / up) * SIG_SCALE * up as f32 } else { 0.0 }; @@ -626,9 +657,17 @@ impl CeltEncoder { silence &= v == 0.0; } self.preemph_mem[ch] = mem; + for k in 0..d { + next_delay[k * c + ch] = src(in_n + k); + } self.in_mem[ch * OVERLAP..(ch + 1) * OVERLAP] .copy_from_slice(&self.in_buf[base + n..base + n + OVERLAP]); } + if self.align_input { + delay[..c * (CELT_DELAY_48K / self.upsample)] + .copy_from_slice(&next_delay[..c * (CELT_DELAY_48K / self.upsample)]); + } + self.delay_buf = delay; // --- Silence flag (first symbol of the frame) ----------------------- // Only exists when CELT opens the stream (decoder: `tell == 1`); under @@ -711,14 +750,12 @@ impl CeltEncoder { } } - // `EC_OPUS_X_DEBUG`: the analysis chain stage by stage for a bisect - // against libopus on the same PCM -- the pre-emphasised window, the - // MDCT output, the band energies and the normalised `X`. if std::env::var_os("EC_OPUS_X_DEBUG").is_some() { let f: Vec = self.in_buf[OVERLAP..OVERLAP + 16].iter().map(|v| format!("{v:.5}")).collect(); let e: f64 = self.in_buf[..n + OVERLAP].iter().map(|v| *v as f64 * *v as f64).sum(); - let ovl: Vec = self.in_buf[..4].iter().map(|v| format!("{v:.5}")).collect(); + let ovl: Vec = + self.in_buf[..4].iter().map(|v| format!("{v:.5}")).collect(); eprintln!("XPRE {} | E {e:.6e} ovl {}", f.join(" "), ovl.join(" ")); let fr: Vec = self.freq[..16].iter().map(|v| format!("{v:.5}")).collect(); let be: Vec = self.band_e[..8].iter().map(|v| format!("{v:.5}")).collect(); @@ -770,8 +807,10 @@ impl CeltEncoder { // .708->.703, reelo@96 .940->.872, dl8a .551/.374->.503/.346, hein // .855/.528->.771/.419), corr within +.0001 everywhere. The KEEP rule // is "err_ratio not worse on every row", so the search ships off. + // `EC_OPUS_TWO_PASS=1` re-arms it for a sweep (lane opusx2 r2). const TWO_PASS_COARSE_ENERGY: bool = false; - let mut two_pass = TWO_PASS_COARSE_ENERGY; + let mut two_pass = + TWO_PASS_COARSE_ENERGY || std::env::var_os("EC_OPUS_TWO_PASS").is_some(); let mut intra = self.force_intra || (!two_pass && self.delayed_intra > (2 * c * (end - start)) as f32 @@ -872,7 +911,7 @@ impl CeltEncoder { // --- Allocation trim ------------------------------------------------ let mut alloc_trim = 5i32; if tell_frac + (6 << BITRES) <= total_bits_frac - total_boost { - alloc_trim = self.alloc_trim_analysis(end, lm, c, n); + alloc_trim = self.alloc_trim_analysis(end, lm, c, n, tf_estimate); enc.enc_icdf(alloc_trim as usize, &TRIM_ICDF, 7); tell_frac = enc.tell_frac() as i32; } @@ -1550,7 +1589,20 @@ impl CeltEncoder { /// dl8a@64 .9889->.9879). The KEEP rule rejects it; this is the third /// rejection of the same port (see `lanes/opus-trim-r2.{A,B}.sweep.txt`). /// Do not re-port it without a fix for the transient rows first. - fn alloc_trim_analysis(&mut self, end: usize, lm: usize, c: usize, n0: usize) -> i32 { + /// + /// `EC_OPUS_TRIM13=1` selects the continuous 1.3 form instead, for the + /// re-sweep on the aligned (delayed) spectrum the discrete ladder was + /// never measured against. + fn alloc_trim_analysis( + &mut self, + end: usize, + lm: usize, + c: usize, + n0: usize, + tf_estimate: f32, + ) -> i32 { + let cont = std::env::var_os("EC_OPUS_TRIM13").is_some(); + let mut trim_f = 5.0f32; let mut trim = 5i32; if c == 2 { let mut sum = 0.0f32; @@ -1562,6 +1614,10 @@ impl CeltEncoder { sum += partial; } sum *= 1.0 / 8.0; + if cont { + let sum_c = sum.abs().min(1.0); + trim_f += (0.75 * (1.001 - sum_c * sum_c).log2()).max(-4.0); + } if sum > 0.995 { trim -= 4; } else if sum > 0.92 { @@ -1595,6 +1651,14 @@ impl CeltEncoder { * (2 + 2 * i as i32 - NB_BANDS as i32) as f32; } } + if cont { + // libopus divides the same sum by `C*(end-1)`; the ladder above + // carries an extra factor of two in its thresholds. + let diff = diff / (c * (end - 1)) as f32; + trim_f -= ((diff + 1.0) / 6.0).clamp(-2.0, 2.0); + trim_f -= 2.0 * tf_estimate; + return (trim_f + 0.5).floor().clamp(0.0, 10.0) as i32; + } diff /= (2 * c * (end - 1)) as f32; if diff > 2.0 { trim -= 1; diff --git a/crates/ec-opus/src/encoder.rs b/crates/ec-opus/src/encoder.rs index 3530f265..59312009 100644 --- a/crates/ec-opus/src/encoder.rs +++ b/crates/ec-opus/src/encoder.rs @@ -40,11 +40,12 @@ const MAX_SILK_PACKET_BYTES: usize = 1 + 1 + 2 * 2 + 3 * MAX_FRAME_BYTES; const SILK_LOOK_AHEAD_48K_NB: usize = 58; const SILK_LOOK_AHEAD_48K_MB: usize = 54; const SILK_LOOK_AHEAD_48K_WB: usize = 50; -/// How far the hybrid path delays the SILK layer's input so its output lines -/// up with the CELT layer's at the decoder (which sums them as-is): CELT's -/// overlap (120) minus SILK's WB round trip, click-measured through the -/// decoder with one layer muted (`hybrid_layers_align` in conformance.rs). -const HYBRID_SILK_DELAY_48K: usize = 120 - SILK_LOOK_AHEAD_48K_WB; +/// One MDCT overlap: the CELT layer's delay without libopus's input +/// alignment ([`Encoder::set_libopus_input_alignment`]), which adds +/// `delay_compensation = Fs/250` (192 at 48 kHz) on top. +const CELT_OVERLAP_48K: usize = 120; +/// libopus `opus_encoder.c`'s `delay_compensation = Fs/250`. +const CELT_DELAY_COMP_48K: usize = 192; /// Bytes the CELT layer of a hybrid packet always keeps, whatever SILK spent. /// Was 8: at 16 kbps SILK takes 37 of the 40-byte budget, so 8 expanded /// 5133/6001 packets (+12.9% rate on the speech gate); libopus leaves CELT @@ -106,11 +107,19 @@ pub struct Encoder { /// Scratch space for the SILK packet payload, sized once so the steady-state /// loop (`steady_state_encode_loop_zero_alloc`) doesn't allocate. silk_buf: [u8; MAX_SILK_PACKET_BYTES], - /// Hybrid: the last [`HYBRID_SILK_DELAY_48K`] samples of SILK-layer input. + /// Hybrid: the last [`Encoder::hybrid_silk_delay_48k`] samples of SILK-layer input. silk_delay: Vec, /// Scratch space for the zero-stuffed SILK/hybrid input, sized once so /// the steady-state loop doesn't allocate a `Vec` per frame. silk_stuff: Vec, + /// [`Encoder::set_libopus_input_alignment`]: off by default. + align_input: bool, + /// libopus `opus_encoder.c`'s `hp_mem`: the one-pole state of the + /// [`Encoder::dc_reject`] filter every frame of API input goes through, + /// one per channel. + hp_mem: [f32; 2], + /// Scratch space for that filter's output, sized once. + hp_buf: Vec, } /// SILK's internal sample rate (kHz) for a target bandwidth: Narrow → 8, @@ -149,7 +158,7 @@ impl Encoder { "one stream carries at most two channels; use MultistreamEncoder", )); } - Ok(Encoder { + let mut enc = Encoder { celt: CeltEncoder::new(channels, upsample), range: RangeEncoder::new(), sample_rate, @@ -170,7 +179,16 @@ impl Encoder { silk_buf: [0u8; MAX_SILK_PACKET_BYTES], silk_delay: Vec::new(), silk_stuff: Vec::new(), - }) + align_input: false, + hp_mem: [0.0; 2], + hp_buf: Vec::new(), + }; + // `EC_OPUS_ALIGN=1` turns the alignment on for a whole process — how + // the gate rows at `set_libopus_input_alignment` were produced. + if std::env::var_os("EC_OPUS_ALIGN").is_some() { + enc.set_libopus_input_alignment(true); + } + Ok(enc) } /// Overrides the automatic SILK/Hybrid/CELT choice `wants_silk` and @@ -194,14 +212,15 @@ impl Encoder { /// Encoder delay in *input* samples for a `frame_size`-sample (per /// channel, native rate) frame: the decoded stream lags the input by /// this much, and an Ogg-Opus pre-skip of `look_ahead * 48000/rate` - /// cancels it exactly. CELT: one MDCT overlap, 120 samples at 48 kHz. + /// cancels it exactly. CELT: one MDCT overlap plus the 192-sample input + /// delay compensation, 312 samples at 48 kHz. /// SILK (10, 20, 40 or 60 ms frames, when the application/bitrate or an /// explicit [`Encoder::set_mode`] select it — the same /// [`Encoder::silk_choice`] predicate `encode_toc_and_payload` dispatches /// on, so this always matches which layer actually codes the frame): /// [`SILK_LOOK_AHEAD_48K_NB`], [`SILK_LOOK_AHEAD_48K_MB`] or /// [`SILK_LOOK_AHEAD_48K_WB`]. Hybrid: CELT's 120, the SILK layer being - /// delayed to meet it ([`HYBRID_SILK_DELAY_48K`]). Any other frame size + /// delayed to meet it ([`Encoder::hybrid_silk_delay_48k`]). Any other frame size /// falls back to CELT here exactly as `encode_toc_and_payload` does. pub fn look_ahead(&self, frame_size: usize) -> usize { let frame_48k = frame_size * self.upsample; @@ -213,7 +232,61 @@ impl Encoder { }; return delay / self.upsample; } - 120 / self.upsample + self.celt_look_ahead_48k() / self.upsample + } + + /// The CELT layer's delay in 48 kHz samples: one MDCT overlap, plus + /// libopus's `delay_compensation` when the alignment is on. + fn celt_look_ahead_48k(&self) -> usize { + CELT_OVERLAP_48K + if self.align_input { CELT_DELAY_COMP_48K } else { 0 } + } + + /// How far the hybrid path delays the SILK layer's input so its output + /// lines up with the CELT layer's at the decoder (which sums them as-is): + /// CELT's delay minus SILK's WB round trip, click-measured through the + /// decoder with one layer muted (`hybrid_layers_align` in conformance.rs). + fn hybrid_silk_delay_48k(&self) -> usize { + self.celt_look_ahead_48k() - SILK_LOOK_AHEAD_48K_WB + } + + /// Puts our CELT analysis window exactly where libopus's is: the layer is + /// fed the input delayed by `delay_compensation = Fs/250` (192 samples at + /// 48 kHz, `opus_encoder.c` ~:1955) and every frame first goes through + /// libopus's 3 Hz `dc_reject`. The alignment is *exact* — on the reell + /// attack frame (frame 2, 20 ms, LM=3, transient) our first eight band + /// log-energies become + /// 3.4386 4.0055 3.2603 4.5954 1.1790 4.2774 4.7584 3.7169 against + /// libopus's 3.439 4.005 3.260 4.595 1.179 4.277 4.758 3.717, all eight + /// within .0006 (the unaligned encoder is .06-.21 apart). + /// + /// It ships OFF because the 12-row library gate rejects it, and because + /// re-tuning the constants that were fitted on the misaligned spectrum + /// does not rescue it. Against the shipped rows + /// (`lanes/opus-opustr2-r1.sweep.txt`), err_ratio: + /// + /// | arm | better | worse (blocking) | + /// |---|---|---| + /// | 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 | + /// | delay + `dc_reject` (`opus-opusx2-r1`) | 5 | those, plus dl8a@64 .552→1.074, dl8a@96 .374→1.011 | + /// | + two-pass coarse energy (`-r2`) | 5 | same 7 rows (nik@96 1.809, dl8a@64 1.200) | + /// | + continuous 1.3 `alloc_trim` (`-r3`) | 5 | same 7, and corr worse by >.0005 on 9 rows | + /// | + tf boost k=1.25 (`-r4`) | 5 | same 7 | + /// | + tf boost k=1.5 (`-r5`) | 5 | same 7 | + /// | + 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 | + /// + /// The best aligned arm on the KEEP rule is the delay alone without + /// `dc_reject` (5 rows worse); every arm that adds `dc_reject` puts dl8a + /// in the blocking set too. + /// + /// The blocking set (nik, her@96, dl8a, hein) is the same in every arm and + /// no arm moves any of those rows back towards its shipped value, so the + /// misfit is not one of the swept constants. Turning this on also costs + /// 4 ms of algorithmic delay: [`Encoder::look_ahead`] for a CELT frame + /// becomes 312, not 120, and the Ogg pre-skip must follow it. + pub fn set_libopus_input_alignment(&mut self, on: bool) { + self.align_input = on; + self.celt.set_align_input(on); + self.hp_mem = [0.0; 2]; } /// Forces the coded bandwidth; [`None`] (the default) picks it from the @@ -277,6 +350,7 @@ impl Encoder { self.silk_stereo_mb = None; self.silk_stereo_wb = None; self.silk_delay.clear(); + self.hp_mem = [0.0; 2]; self.final_range = 0; } @@ -686,6 +760,38 @@ impl Encoder { BWS[idx].min(ceiling) } + /// libopus `opus_encoder.c`'s `dc_reject(pcm, 3, ...)`: a 3 Hz one-pole + /// high-pass on the API input, applied once before *both* layers (libopus + /// filters into `pcm_buf`, which is what `silk_Encode` and + /// `celt_encode_with_ec` both read). `coef = 6.3 * cutoff / Fs` at the + /// API rate; the output is the input minus a leaky integrator of it, and + /// the integrator state carries across frames. + /// + /// libopus takes the `hp_cutoff` branch instead for + /// `OPUS_APPLICATION_VOIP` (a bandwidth-dependent second-order section); + /// not ported — every VoIP frame still gets this DC reject. + /// Ships off with the alignment knob: `dc_reject` alone (without the + /// input delay) has never been measured on the library gate. + fn dc_reject<'a>(&mut self, pcm: &'a [f32], frame_size: usize, out: &'a mut Vec) -> &'a [f32] { + if !self.align_input { + return pcm; + } + let c = self.channels; + let coef = 6.3 * 3.0 / self.sample_rate as f32; + out.clear(); + out.resize(frame_size * c, 0.0); + for ch in 0..c { + let mut m = self.hp_mem[ch]; + for i in 0..frame_size { + let x = pcm[i * c + ch]; + out[i * c + ch] = x - m; + m += coef * (x - m); + } + self.hp_mem[ch] = m; + } + out + } + /// Encodes one frame — `frame_size` samples per channel of interleaved /// `f32` at the input rate, 2.5, 5, 10 or 20 ms of it — as a code-0 Opus /// packet in `out`, returning the packet length. @@ -695,19 +801,27 @@ impl Encoder { frame_size: usize, out: &mut [u8], ) -> Result { - let (toc, payload) = - self.encode_toc_and_payload(pcm, frame_size, out.len().saturating_sub(1))?; - let n = payload.len(); - if out.len() < 1 + n { - return Err(Error::corrupt(format!( - "opus encode: packet needs {} bytes, buffer holds {}", - 1 + n, - out.len() - ))); - } - out[0] = toc; - out[1..1 + n].copy_from_slice(payload); - Ok(1 + n) + let mut hp = std::mem::take(&mut self.hp_buf); + let input = self.dc_reject(pcm, frame_size, &mut hp); + let r = match self.encode_toc_and_payload(input, frame_size, out.len().saturating_sub(1)) { + Err(e) => Err(e), + Ok((toc, payload)) => { + let n = payload.len(); + if out.len() < 1 + n { + Err(Error::corrupt(format!( + "opus encode: packet needs {} bytes, buffer holds {}", + 1 + n, + out.len() + ))) + } else { + out[0] = toc; + out[1..1 + n].copy_from_slice(payload); + Ok(1 + n) + } + } + }; + self.hp_buf = hp; + r } /// [`Encoder::encode_float`] from 16-bit samples. @@ -725,33 +839,41 @@ impl Encoder { frame_size: usize, out: &mut [u8], ) -> Result { - let (toc, payload) = - self.encode_toc_and_payload(pcm, frame_size, out.len().saturating_sub(3))?; - let n = payload.len(); - let len_bytes = if n < 252 { 1 } else { 2 }; - if out.len() < 1 + len_bytes + n { - return Err(Error::corrupt(format!( - "opus encode: self-delimited packet needs {} bytes, buffer holds {}", - 1 + len_bytes + n, - out.len() - ))); - } - out[0] = toc; - if n < 252 { - out[1] = n as u8; - } else { - let b0 = 252 + ((n - 252) & 3); - out[1] = b0 as u8; - out[2] = ((n - b0) / 4) as u8; - } - out[1 + len_bytes..1 + len_bytes + n].copy_from_slice(payload); - Ok(1 + len_bytes + n) + let mut hp = std::mem::take(&mut self.hp_buf); + let input = self.dc_reject(pcm, frame_size, &mut hp); + let r = match self.encode_toc_and_payload(input, frame_size, out.len().saturating_sub(3)) { + Err(e) => Err(e), + Ok((toc, payload)) => { + let n = payload.len(); + let len_bytes = if n < 252 { 1 } else { 2 }; + if out.len() < 1 + len_bytes + n { + Err(Error::corrupt(format!( + "opus encode: self-delimited packet needs {} bytes, buffer holds {}", + 1 + len_bytes + n, + out.len() + ))) + } else { + out[0] = toc; + if n < 252 { + out[1] = n as u8; + } else { + let b0 = 252 + ((n - 252) & 3); + out[1] = b0 as u8; + out[2] = ((n - b0) / 4) as u8; + } + out[1 + len_bytes..1 + len_bytes + n].copy_from_slice(payload); + Ok(1 + len_bytes + n) + } + } + }; + self.hp_buf = hp; + r } /// One hybrid frame (10 or 20 ms, mono or stereo, `bandwidth` SWB or FB) /// into the internal range coder, returning its byte length: the SILK /// layer's symbols (WB, 16 kHz internal, fed the input delayed by - /// [`HYBRID_SILK_DELAY_48K`]), the no-redundancy flag under the decoder's + /// [`Encoder::hybrid_silk_delay_48k`]), the no-redundancy flag under the decoder's /// exact presence rule, then the CELT layer from band 17 in the same /// coder. CBR: the packet is the bitrate's size unless SILK alone needs /// more, in which case CELT keeps [`HYBRID_CELT_MIN_BYTES`] on top. @@ -777,7 +899,7 @@ impl Encoder { } else { Self::zero_stuff_mono(pcm, frame_size, self.upsample, &mut self.silk_stuff); } - let d = HYBRID_SILK_DELAY_48K * self.channels; + let d = self.hybrid_silk_delay_48k() * self.channels; if self.silk_delay.len() != d { self.silk_delay.clear(); self.silk_delay.resize(d, 0.0); @@ -896,33 +1018,39 @@ mod tests { let mut e = Encoder::new(24000, 2, Application::Audio).unwrap(); e.set_bitrate(256_000); assert_eq!(e.auto_bandwidth(), Bandwidth::SuperWide); - assert_eq!(e.look_ahead(960), 60); + assert_eq!(e.look_ahead(960), CELT_OVERLAP_48K / 2); } /// `look_ahead` must use the same 10-or-20 ms-frame predicate dispatch /// does (`silk_choice`/`hybrid_choice`), not just `wants_silk`: 2.5/5 ms /// frames still code as CELT, while 10/20 ms speech follows SILK and - /// hybrid follows CELT's overlap. + /// hybrid follows CELT's delay. #[test] fn look_ahead_matches_the_frame_size_dispatch_actually_uses() { let mut e = Encoder::new(48000, 1, Application::Voip).unwrap(); e.set_bitrate(8000); assert_eq!(e.look_ahead(480), 58, "10ms NB SILK"); - assert_eq!(e.look_ahead(240), 120, "5ms frame falls back to CELT"); + assert_eq!(e.look_ahead(240), CELT_OVERLAP_48K, "5ms frame falls back to CELT"); assert_eq!(e.look_ahead(960), 58, "20ms NB SILK"); // 16k VoIP is hybrid-FB since the libopus threshold port (CELT overlap). e.set_bitrate(16000); - assert_eq!(e.look_ahead(960), 120, "20ms hybrid FB"); + assert_eq!(e.look_ahead(960), CELT_OVERLAP_48K, "20ms hybrid FB"); e.set_bitrate(32000); - assert_eq!(e.look_ahead(960), 120, "20ms hybrid, CELT's overlap"); + assert_eq!(e.look_ahead(960), CELT_OVERLAP_48K, "20ms hybrid, CELT's delay"); let mut e = Encoder::new(48000, 2, Application::Voip).unwrap(); e.set_bitrate(8000); assert_eq!(e.look_ahead(960), 58, "stereo 20ms NB SILK"); e.set_bitrate(64_000); - assert_eq!(e.look_ahead(960), 120, "stereo 20ms hybrid"); + assert_eq!(e.look_ahead(960), CELT_OVERLAP_48K, "stereo 20ms hybrid"); + e.set_libopus_input_alignment(true); + assert_eq!( + e.look_ahead(960), + CELT_OVERLAP_48K + CELT_DELAY_COMP_48K, + "the alignment adds libopus's delay_compensation to the advertised delay" + ); } #[test] diff --git a/crates/ec-opus/src/multistream_enc.rs b/crates/ec-opus/src/multistream_enc.rs index 99a3ee67..dfe8f9a7 100644 --- a/crates/ec-opus/src/multistream_enc.rs +++ b/crates/ec-opus/src/multistream_enc.rs @@ -27,6 +27,13 @@ pub struct MultistreamEncoder { } impl MultistreamEncoder { + /// The encoder delay each stream carries for a `frame_size` frame — the + /// per-stream [`Encoder::look_ahead`], which every stream shares, and so + /// the Ogg-Opus pre-skip a multistream file must carry. + pub fn look_ahead(&self, frame_size: usize) -> usize { + self.streams[0].look_ahead(frame_size) + } + /// An encoder for `streams` elementary streams of which the first /// `coupled` are stereo, with `mapping` naming the coded channel each /// input channel feeds. Layout rules are the decoder's, checked the same diff --git a/crates/ec-opus/tests/conformance.rs b/crates/ec-opus/tests/conformance.rs index 24b83794..a95d04ad 100644 --- a/crates/ec-opus/tests/conformance.rs +++ b/crates/ec-opus/tests/conformance.rs @@ -864,17 +864,18 @@ fn roundtrip_own( (decoded, bytes) } -/// Worst-channel correlation against the source with the encoder's -/// 120-sample delay removed. -fn delayed_corr(source: &[f32], decoded: &[f32], channels: usize) -> f64 { - const DELAY: usize = 120; - let n = (decoded.len() / channels).saturating_sub(DELAY); +/// Worst-channel correlation against the source with the encoder's own +/// delay removed — `delay` is [`Encoder::look_ahead`] for the frame size the +/// round trip used, never a constant (it moved 120 -> 312 when the CELT layer +/// took libopus's Fs/250 input delay). +fn delayed_corr(source: &[f32], decoded: &[f32], channels: usize, delay: usize) -> f64 { + let n = (decoded.len() / channels).saturating_sub(delay); let n = n.min(source.len() / channels); let mut worst = 1.0f64; for c in 0..channels { let a: Vec = (0..n).map(|i| source[i * channels + c]).collect(); let b: Vec = (0..n) - .map(|i| decoded[(i + DELAY) * channels + c]) + .map(|i| decoded[(i + delay) * channels + c]) .collect(); worst = worst.min(correlation(&a, &b)); } @@ -894,7 +895,7 @@ fn encoder_roundtrips_at_every_rate() { let mut enc = Encoder::new(48000, channels, Application::Audio).unwrap(); enc.set_bitrate(kbps * 1000); let (decoded, bytes) = roundtrip_own(&mut enc, &pcm, channels, 960); - let corr = delayed_corr(&pcm, &decoded, channels); + let corr = delayed_corr(&pcm, &decoded, channels, enc.look_ahead(960)); let rate = bytes as f64 * 8.0 / 2.0 / 1000.0; println!("{channels} ch {kbps:>3} kbps: corr {corr:.4}, actual {rate:.1} kbps"); let floor = if kbps < 64 { 0.8 } else { 0.9 }; @@ -906,6 +907,30 @@ fn encoder_roundtrips_at_every_rate() { } } +/// The libopus input alignment ([`Encoder::set_libopus_input_alignment`]): +/// with it on the CELT layer's advertised delay grows by libopus's +/// `delay_compensation`, and the decoded signal tracks the source at exactly +/// that lag and not at the old one — the knob is usable, not just present. +/// It ships off; the gate tables that rejected it are at the setter. +#[test] +fn libopus_input_alignment_delays_and_still_decodes() { + let pcm = test_signal(2, 1.0); + let mut enc = Encoder::new(48000, 2, Application::Audio).unwrap(); + enc.set_bitrate(128_000); + assert_eq!(enc.look_ahead(960), 120, "default: one MDCT overlap"); + enc.set_libopus_input_alignment(true); + assert_eq!(enc.look_ahead(960), 312, "overlap + delay_compensation"); + let (decoded, _) = roundtrip_own(&mut enc, &pcm, 2, 960); + let aligned = delayed_corr(&pcm, &decoded, 2, enc.look_ahead(960)); + let old = delayed_corr(&pcm, &decoded, 2, 120); + println!("aligned: corr at 312 {aligned:.4}, at 120 {old:.4}"); + assert!(aligned >= 0.85, "aligned round trip corr {aligned:.4}"); + assert!( + aligned > old, + "advertised delay 312 correlates {aligned:.4}, worse than the old 120 ({old:.4})" + ); +} + #[test] // Expectations are libopus 1.6's (opus_encoder.c mode_thresholds and the // voice/music bandwidth tables blended by voice_est) since lane opus-mode; @@ -1271,7 +1296,7 @@ fn encoder_frame_sizes_and_vbr() { let mut enc = Encoder::new(48000, 2, Application::Audio).unwrap(); enc.set_bitrate(128_000); let (decoded, _) = roundtrip_own(&mut enc, &pcm, 2, frame); - let corr = delayed_corr(&pcm, &decoded, 2); + let corr = delayed_corr(&pcm, &decoded, 2, enc.look_ahead(frame)); println!("frame {frame}: corr {corr:.4}"); assert!(corr >= 0.85, "frame {frame}: correlation {corr:.4}"); } @@ -1279,7 +1304,7 @@ fn encoder_frame_sizes_and_vbr() { enc.set_bitrate(128_000); enc.set_vbr_constrained(true); let (decoded, bytes) = roundtrip_own(&mut enc, &pcm, 2, 960); - let corr = delayed_corr(&pcm, &decoded, 2); + let corr = delayed_corr(&pcm, &decoded, 2, enc.look_ahead(960)); let rate = bytes as f64 * 8.0 / 1.0 / 1000.0; println!("cvbr 128k: corr {corr:.4}, actual {rate:.1} kbps"); assert!(corr >= 0.9, "cvbr: correlation {corr:.4}"); @@ -1303,8 +1328,9 @@ use ec_ogg::OggMuxer; /// The RFC 7845 identification header for this encoder — built by the crate's /// own [`ec_opus::ogg`] helper, so a muxer and the encoder cannot disagree. -/// `pre_skip` is the encoder's [`Encoder::look_ahead`]: 120, the CELT overlap -/// delay, for every CELT call site; SILK's own (larger) delay for SILK. +/// `pre_skip` is the encoder's [`Encoder::look_ahead`]: 312, the CELT overlap +/// plus its input delay compensation, for every CELT call site; SILK's own +/// delay for SILK. fn opus_head(channels: usize, pre_skip: u16, layout: Option<(usize, usize, &[u8])>) -> Vec { let mapping = layout.map(|(streams, coupled, table)| (1u8, streams as u8, coupled as u8, table)); @@ -1404,10 +1430,10 @@ fn oracle_decodes_our_packets_across_the_rate_table() { write_ogg_opus( &path, &packets, - opus_head(channels, 120, None), + opus_head(channels, enc.look_ahead(960) as u16, None), channels, total, - 120, + enc.look_ahead(960) as i64, ); let Some(reference) = ffmpeg_decode(&path, channels) else { eprintln!("ffmpeg unavailable, skipped"); @@ -1533,9 +1559,10 @@ fn five_one_encode_end_to_end() { let len = enc.encode_float(&silence, 960, &mut out).expect("encode"); packets.push(out[..len].to_vec()); let (streams, coupled, mapping) = enc.layout(); - let head = opus_head(6, 120, Some((streams, coupled, mapping))); + let pre_skip = enc.look_ahead(960); + let head = opus_head(6, pre_skip as u16, Some((streams, coupled, mapping))); let path = temp_path("5.1.opus"); - write_ogg_opus(&path, &packets, head, 6, total, 120); + write_ogg_opus(&path, &packets, head, 6, total, pre_skip as i64); let Some(reference) = ffmpeg_decode(&path, 6) else { eprintln!("ffmpeg unavailable, skipped"); let _ = fs::remove_file(&path); @@ -1567,7 +1594,8 @@ fn ogg_opus_round_trip_duration_is_exact() { enc.set_bitrate(128_000); let packets = encode_packets(&mut enc, &pcm, 2); let path = temp_path("duration.opus"); - write_ogg_opus(&path, &packets, opus_head(2, 120, None), 2, total, 120); + let pre_skip = enc.look_ahead(960); + write_ogg_opus(&path, &packets, opus_head(2, pre_skip as u16, None), 2, total, pre_skip as i64); let probe = Command::new("ffprobe") .args([ "-v", @@ -1591,9 +1619,9 @@ fn ogg_opus_round_trip_duration_is_exact() { .unwrap_or(0.0); // ffprobe reports Ogg-Opus durations *including* the pre-skip — its // own 3.000 s encode probes as 3.0065 (312/48000 more). Ours carries - // a 120-sample pre-skip, so exact is 2.0025; the decoded sample - // count below is the pre-skip-free half of the claim. - let expected = (total as f64 + 120.0) / 48000.0; + // the same pre-skip our encoder advertises, so exact is 2.000 s plus + // it; the decoded sample count below is the pre-skip-free half. + let expected = (total as f64 + pre_skip as f64) / 48000.0; assert!( (dur - expected).abs() < 1e-6, "ffprobe reports {dur} s, expected {expected} s (2.000 s + pre-skip)" @@ -2081,7 +2109,7 @@ fn silk_mediumband_and_10ms_roundtrip() { frame_ms == 10 || voiced > 0, "{tag}: no frame coded with LTP" ); - if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len()) { + if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len(), 120) { let (c, _) = aligned_corr(&oracle, &decoded, 2000); assert!(c >= 0.99, "{tag}: our decode vs oracle decode corr {c:.4}"); } @@ -2131,7 +2159,7 @@ fn silk_multiframe_packets_roundtrip() { ); assert!(corr >= floor, "{tag}: corr {corr:.4} below {floor:.4}"); assert!(voiced > 0, "{tag}: no frame coded with LTP"); - if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len()) { + if let Some(oracle) = oracle_decode(&format!("silk-{tag}"), &packets, pcm.len(), 120) { let (c, _) = aligned_corr(&oracle, &decoded, 2500); assert!( c >= 0.99, @@ -2338,12 +2366,21 @@ fn silk_compares_to_celt_on_speech_at_speech_rates() { } /// Reference oracle decode of `packets` as Ogg-Opus, or `None` without ffmpeg. -fn oracle_decode(name: &str, packets: &[Vec], samples: usize) -> Option> { +/// `pre_skip` must be the encoder's advertised [`Encoder::look_ahead`] for +/// these packets: it is what the oracle trims off the front, so a caller that +/// compares sample-for-sample against its own decode at that same offset only +/// lines up when the two agree. +fn oracle_decode( + name: &str, + packets: &[Vec], + samples: usize, + pre_skip: usize, +) -> Option> { if Command::new("ffmpeg").arg("-version").output().is_err() { return None; } let path = temp_path(&format!("{name}.opus")); - write_ogg_opus(&path, packets, opus_head(1, 120, None), 1, samples, 120); + write_ogg_opus(&path, packets, opus_head(1, pre_skip as u16, None), 1, samples, pre_skip as i64); let out = Command::new("ffmpeg") .args(["-v", "warning", "-c:a", "libopus", "-i"]) .arg(&path) @@ -2390,7 +2427,7 @@ fn silk_nsq_improves_quality_at_equal_rate() { "{name}: corr {corr:.4} (floor {floor}) at {kbps:.1} kbps" )); } - if let Some(oracle) = oracle_decode(&format!("silk-nsq-{name}"), &packets, pcm.len()) { + if let Some(oracle) = oracle_decode(&format!("silk-nsq-{name}"), &packets, pcm.len(), 120) { let (c, _) = aligned_corr(&oracle, &decoded, 2000); assert!(c >= 0.99, "{name}: our decode vs oracle decode corr {c:.4}"); } @@ -2485,6 +2522,15 @@ fn hybrid_roundtrip( /// The two layers of a hybrid packet reach the decoder's output at the same /// delay: a click's low-band-only and high-band-only peaks coincide at the /// encoder's documented look-ahead. +/// The delay [`hybrid_roundtrip`]'s encoder advertises for a 20 ms frame — +/// [`Encoder::look_ahead`] of that same configuration, so the lag assertions +/// track the layer's real delay instead of a constant. +fn hybrid_delay(bps: u32) -> usize { + let mut enc = Encoder::new(48000, 1, Application::Voip).unwrap(); + enc.set_bitrate(bps); + enc.look_ahead(960) +} + #[test] fn hybrid_layers_align() { let mut click = vec![0f32; 48000]; @@ -2500,29 +2546,26 @@ fn hybrid_layers_align() { }; let (lb, _) = hybrid_roundtrip(&click, 32_000, None, (true, false)); let (hb, _) = hybrid_roundtrip(&click, 32_000, None, (false, true)); - let enc = Encoder::new(48000, 1, Application::Voip).unwrap(); + let delay = hybrid_delay(32_000) as i64; let (plb, phb) = (peak(&lb) as i64 - at as i64, peak(&hb) as i64 - at as i64); - eprintln!( - "hybrid click: LB peak +{plb}, HB peak +{phb}, look_ahead {}", - { - let mut e = enc.clone(); - e.set_bitrate(32_000); - e.look_ahead(960) - } - ); - // A fullband CELT click lands at exactly +120 (`celt_click_peak_offset`); - // the band-limited HB layer's main lobe sits up to 2 samples early once - // transient frames keep their short blocks, and SILK lands at +121. + eprintln!("hybrid click: LB peak +{plb}, HB peak +{phb}, look_ahead {delay}"); + // A fullband CELT click lands at exactly the encoder's advertised delay + // (`celt_click_peak_offset`); the band-limited HB layer's main lobe sits + // up to 2 samples early once transient frames keep their short blocks, + // and SILK lands one sample late. assert!( (plb - phb).abs() <= 3, "layers misaligned: LB +{plb} vs HB +{phb}" ); - assert!((phb - 120).abs() <= 2, "HB peak +{phb}, look_ahead 120"); + assert!((phb - delay).abs() <= 2, "HB peak +{phb}, look_ahead {delay}"); } /// 20 ms FB hybrid at 32 kbps: decodes in our decoder range-exactly, tracks /// the input full-band and in the SILK layer's band alone, and the reference /// oracle decodes the packets to the same signal. +/// +/// The delay [`hybrid_roundtrip`]'s encoder advertises for a 20 ms frame is +/// [`Encoder::look_ahead`] of that same configuration, never a constant. #[test] fn hybrid_fb_roundtrip() { for (name, pcm) in silk_sources() { @@ -2540,18 +2583,19 @@ fn hybrid_fb_roundtrip() { ); assert!(corr >= 0.95, "{name}: full-band corr {corr:.4}"); // +-3: the wav16 fixture is a pure tone, whose phase moves the peak. + let delay = hybrid_delay(32_000); assert!( - (117..=123).contains(&lag), - "{name}: aligned at lag {lag}, not the documented 120" + (delay - 3..=delay + 3).contains(&lag), + "{name}: aligned at lag {lag}, not the advertised {delay}" ); assert!(lb_corr >= 0.9, "{name}: low-band corr {lb_corr:.4}"); assert!( (28.0..=36.0).contains(&kbps), "{name}: {kbps:.1} kbps for a 32 kbps CBR target" ); - if let Some(oracle) = oracle_decode(&format!("hybrid-{name}"), &packets, pcm.len()) { - let n = oracle.len().min(decoded.len() - 120); - let c = correlation(&oracle[..n], &decoded[120..120 + n]); + if let Some(oracle) = oracle_decode(&format!("hybrid-{name}"), &packets, pcm.len(), delay) { + let n = oracle.len().min(decoded.len() - delay); + let c = correlation(&oracle[..n], &decoded[delay..delay + n]); eprintln!("hybrid FB {name}: oracle vs ours corr {c:.4}"); assert!(c >= 0.95, "{name}: oracle corr {c:.4}"); } @@ -2659,13 +2703,20 @@ fn hybrid_shapes_roundtrip() { assert!(worst >= floor, "{tag}: worst corr {worst:.4}"); let total = pcm.len() / channels; let path = temp_path(&format!("hybrid-{tag}.opus")); + // The pre-skip is what `hybrid_roundtrip_shape`'s own encoder + // advertises for this frame size, not a constant. + let pre_skip = { + let mut e = Encoder::new(48000, channels, Application::Voip).unwrap(); + e.set_bitrate(bps); + e.look_ahead(frame) + }; write_ogg_opus( &path, &packets, - opus_head(channels, 120, None), + opus_head(channels, pre_skip as u16, None), channels, total, - 120, + pre_skip as i64, ); if Command::new("ffmpeg").arg("-version").output().is_ok() { let out = Command::new("ffmpeg") diff --git a/lanes/opus-opusx2-r1.sweep.txt b/lanes/opus-opusx2-r1.sweep.txt new file mode 100644 index 00000000..71980025 --- /dev/null +++ b/lanes/opus-opusx2-r1.sweep.txt @@ -0,0 +1,17 @@ +# lane-opusx2 r1: CELT input delayed by Fs/250 + libopus dc_reject (3 Hz) on the API input +# baseline lanes/opus-opustr2-r1.sweep.txt (shipped); delay-only arm = lanes/opus-opusx-r1.sweep.txt +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +nik 64 69.1 69.2 -0.1 0.9883 0.9864 -0.0020 -116.02 -154.78 0.805 0.9766 0.9745 0 0 +nik 96 100.9 101.0 -0.1 0.9944 0.9940 -0.0003 -111.04 -31.55 1.780 0.9888 0.9888 0 0 +reelo 64 63.6 63.6 -0.0 0.9887 0.9866 -0.0021 -172.14 -123.36 1.301 0.9708 0.9686 0 0 +reelo 96 93.4 93.9 -0.5 0.9943 0.9937 -0.0006 -101.22 -125.18 0.866 0.9875 0.9854 0 0 +her 64 67.6 67.9 -0.4 0.9828 0.9794 -0.0033 -333.52 -339.00 0.980 0.9474 0.9406 0 0 +her 96 101.0 101.5 -0.5 0.9916 0.9902 -0.0014 -248.38 -191.50 1.293 0.9770 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9904 0.9880 -0.0024 -264.15 -128.39 1.920 0.9714 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9952 0.9948 -0.0004 -271.16 -29.16 3.980 0.9853 0.9804 0 0 +dl8a 64 65.7 65.8 -0.1 0.9885 0.9865 -0.0020 -399.15 -378.84 1.074 0.9787 0.9723 0 0 +dl8a 96 96.6 96.8 -0.3 0.9938 0.9934 -0.0004 -426.78 -423.47 1.011 0.9876 0.9864 0 0 +hein 64 64.8 64.9 -0.2 0.9887 0.9874 -0.0013 -383.53 -388.31 0.983 0.9345 0.9148 0 0 +hein 96 86.8 86.9 -0.2 0.9944 0.9930 -0.0014 -351.66 -246.46 1.513 0.9701 0.9499 0 0 diff --git a/lanes/opus-opusx2-r2.sweep.txt b/lanes/opus-opusx2-r2.sweep.txt new file mode 100644 index 00000000..d7cd53ea --- /dev/null +++ b/lanes/opus-opusx2-r2.sweep.txt @@ -0,0 +1,16 @@ +# lane-opusx2 r2: EC_OPUS_TWO_PASS=1 (libopus two-pass coarse energy) (on the aligned tree: Fs/250 delay + dc_reject) +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +nik 64 69.1 69.2 -0.1 0.9884 0.9864 -0.0020 -114.86 -154.78 0.799 0.9767 0.9745 0 0 +nik 96 100.9 101.0 -0.1 0.9944 0.9940 -0.0003 -113.73 -31.55 1.809 0.9889 0.9888 0 0 +reelo 64 63.6 63.6 -0.0 0.9888 0.9866 -0.0021 -168.90 -123.36 1.280 0.9708 0.9686 0 0 +reelo 96 93.4 93.9 -0.5 0.9943 0.9937 -0.0006 -98.26 -125.18 0.850 0.9874 0.9854 0 0 +her 64 67.7 67.9 -0.4 0.9828 0.9794 -0.0034 -342.89 -339.00 1.015 0.9477 0.9406 0 0 +her 96 101.0 101.5 -0.5 0.9916 0.9902 -0.0014 -245.44 -191.50 1.277 0.9773 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9904 0.9880 -0.0024 -270.85 -128.39 1.974 0.9715 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9952 0.9948 -0.0004 -271.17 -29.16 3.980 0.9853 0.9804 0 0 +dl8a 64 65.7 65.8 -0.1 0.9885 0.9865 -0.0020 -431.62 -378.84 1.200 0.9784 0.9723 0 0 +dl8a 96 96.6 96.8 -0.3 0.9938 0.9934 -0.0004 -429.71 -423.47 1.021 0.9877 0.9864 0 0 +hein 64 64.8 64.9 -0.1 0.9889 0.9874 -0.0016 -398.79 -388.31 1.037 0.9355 0.9148 0 0 +hein 96 86.8 86.9 -0.2 0.9945 0.9930 -0.0015 -348.20 -246.46 1.494 0.9705 0.9499 0 0 diff --git a/lanes/opus-opusx2-r3.sweep.txt b/lanes/opus-opusx2-r3.sweep.txt new file mode 100644 index 00000000..1c024d68 --- /dev/null +++ b/lanes/opus-opusx2-r3.sweep.txt @@ -0,0 +1,16 @@ +# lane-opusx2 r3: EC_OPUS_TRIM13=1 (continuous 1.3 alloc_trim) (on the aligned tree: Fs/250 delay + dc_reject) +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +nik 64 69.1 69.2 -0.1 0.9875 0.9864 -0.0011 -117.01 -154.78 0.810 0.9760 0.9745 0 0 +nik 96 100.9 101.0 -0.1 0.9938 0.9940 +0.0003 -128.36 -31.55 1.971 0.9880 0.9888 0 0 +reelo 64 63.6 63.6 -0.0 0.9883 0.9866 -0.0017 -157.11 -123.36 1.204 0.9707 0.9686 0 0 +reelo 96 93.4 93.9 -0.5 0.9940 0.9937 -0.0002 -74.67 -125.18 0.726 0.9866 0.9854 0 0 +her 64 67.6 67.9 -0.4 0.9820 0.9794 -0.0026 -334.21 -339.00 0.982 0.9455 0.9406 0 0 +her 96 101.0 101.5 -0.5 0.9911 0.9902 -0.0008 -251.84 -191.50 1.312 0.9757 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9896 0.9880 -0.0016 -268.76 -128.39 1.957 0.9704 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9947 0.9948 +0.0001 -265.83 -29.16 3.893 0.9845 0.9804 0 0 +dl8a 64 65.7 65.8 -0.1 0.9874 0.9865 -0.0009 -387.57 -378.84 1.031 0.9762 0.9723 0 0 +dl8a 96 96.6 96.8 -0.3 0.9931 0.9934 +0.0003 -413.74 -423.47 0.967 0.9858 0.9864 0 0 +hein 64 64.8 64.9 -0.2 0.9886 0.9874 -0.0012 -383.53 -388.31 0.983 0.9345 0.9148 0 0 +hein 96 86.8 86.9 -0.2 0.9944 0.9930 -0.0014 -351.67 -246.46 1.513 0.9699 0.9499 0 0 diff --git a/lanes/opus-opusx2-r4.sweep.txt b/lanes/opus-opusx2-r4.sweep.txt new file mode 100644 index 00000000..df172db6 --- /dev/null +++ b/lanes/opus-opusx2-r4.sweep.txt @@ -0,0 +1,16 @@ +# lane-opusx2 r4: EC_OPUS_TF_K=1.25 (CVBR tf boost) (on the aligned tree: Fs/250 delay + dc_reject) +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +nik 64 69.1 69.2 -0.1 0.9883 0.9864 -0.0020 -110.52 -154.78 0.779 0.9765 0.9745 0 0 +nik 96 100.9 101.0 -0.1 0.9943 0.9940 -0.0003 -111.87 -31.55 1.789 0.9888 0.9888 0 0 +reelo 64 63.5 63.6 -0.1 0.9887 0.9866 -0.0020 -180.92 -123.36 1.359 0.9704 0.9686 0 0 +reelo 96 93.3 93.9 -0.6 0.9942 0.9937 -0.0005 -90.05 -125.18 0.806 0.9870 0.9854 0 0 +her 64 67.5 67.9 -0.6 0.9826 0.9794 -0.0032 -311.93 -339.00 0.903 0.9471 0.9406 0 0 +her 96 100.7 101.5 -0.7 0.9914 0.9902 -0.0012 -230.30 -191.50 1.195 0.9765 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9904 0.9880 -0.0024 -269.89 -128.39 1.966 0.9712 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9952 0.9948 -0.0004 -263.44 -29.16 3.855 0.9852 0.9804 0 0 +dl8a 64 65.6 65.8 -0.2 0.9884 0.9865 -0.0020 -424.09 -378.84 1.170 0.9791 0.9723 0 0 +dl8a 96 96.4 96.8 -0.4 0.9937 0.9934 -0.0003 -434.84 -423.47 1.039 0.9872 0.9864 0 0 +hein 64 64.7 64.9 -0.3 0.9882 0.9874 -0.0008 -376.99 -388.31 0.961 0.9314 0.9148 0 0 +hein 96 86.7 86.9 -0.3 0.9941 0.9930 -0.0011 -363.54 -246.46 1.580 0.9677 0.9499 0 0 diff --git a/lanes/opus-opusx2-r5.sweep.txt b/lanes/opus-opusx2-r5.sweep.txt new file mode 100644 index 00000000..3d5a5fb1 --- /dev/null +++ b/lanes/opus-opusx2-r5.sweep.txt @@ -0,0 +1,16 @@ +# lane-opusx2 r5: EC_OPUS_TF_K=1.5 (CVBR tf boost) (on the aligned tree: Fs/250 delay + dc_reject) +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +nik 64 69.1 69.2 -0.2 0.9883 0.9864 -0.0019 -155.70 -154.78 1.005 0.9765 0.9745 0 0 +nik 96 100.8 101.0 -0.2 0.9943 0.9940 -0.0003 -111.16 -31.55 1.781 0.9888 0.9888 0 0 +reelo 64 63.5 63.6 -0.2 0.9886 0.9866 -0.0020 -179.06 -123.36 1.347 0.9699 0.9686 0 0 +reelo 96 93.2 93.9 -0.7 0.9942 0.9937 -0.0004 -89.99 -125.18 0.805 0.9869 0.9854 0 0 +her 64 67.5 67.9 -0.7 0.9825 0.9794 -0.0030 -347.44 -339.00 1.032 0.9466 0.9406 0 0 +her 96 100.7 101.5 -0.8 0.9913 0.9902 -0.0011 -247.70 -191.50 1.289 0.9760 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9904 0.9880 -0.0024 -272.52 -128.39 1.987 0.9710 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9952 0.9948 -0.0004 -261.59 -29.16 3.825 0.9849 0.9804 0 0 +dl8a 64 65.5 65.8 -0.4 0.9883 0.9865 -0.0019 -394.10 -378.84 1.055 0.9784 0.9723 0 0 +dl8a 96 96.3 96.8 -0.5 0.9936 0.9934 -0.0002 -406.85 -423.47 0.945 0.9865 0.9864 0 0 +hein 64 64.6 64.9 -0.4 0.9876 0.9874 -0.0003 -374.22 -388.31 0.951 0.9258 0.9148 0 0 +hein 96 86.5 86.9 -0.4 0.9938 0.9930 -0.0007 -373.59 -246.46 1.638 0.9651 0.9499 0 0 diff --git a/lanes/opus-opusx2-r6.sweep.txt b/lanes/opus-opusx2-r6.sweep.txt new file mode 100644 index 00000000..f50edb33 --- /dev/null +++ b/lanes/opus-opusx2-r6.sweep.txt @@ -0,0 +1,16 @@ +# lane-opusx2 r6: DEFAULTS (alignment knob off) -- regression check that the shipped path is untouched +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +nik 64 69.1 69.2 -0.1 0.9887 0.9864 -0.0024 -95.23 -154.78 0.708 0.9766 0.9745 0 0 +nik 96 100.9 101.0 -0.1 0.9947 0.9940 -0.0007 -29.86 -31.55 0.985 0.9889 0.9888 0 0 +reelo 64 63.6 63.6 -0.0 0.9893 0.9866 -0.0027 -202.82 -123.36 1.510 0.9702 0.9686 0 0 +reelo 96 93.4 93.9 -0.5 0.9947 0.9937 -0.0009 -114.74 -125.18 0.940 0.9862 0.9854 0 0 +her 64 67.7 67.9 -0.4 0.9834 0.9794 -0.0040 -365.72 -339.00 1.103 0.9477 0.9406 0 0 +her 96 101.0 101.5 -0.5 0.9914 0.9902 -0.0012 -202.07 -191.50 1.051 0.9728 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9908 0.9880 -0.0029 -351.70 -128.39 2.697 0.9721 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9956 0.9948 -0.0008 -301.83 -29.16 4.499 0.9856 0.9804 0 0 +dl8a 64 65.7 65.8 -0.1 0.9889 0.9865 -0.0025 -227.54 -378.84 0.552 0.9787 0.9723 0 0 +dl8a 96 96.5 96.8 -0.3 0.9942 0.9934 -0.0009 -177.70 -423.47 0.374 0.9881 0.9864 0 0 +hein 64 64.8 64.9 -0.2 0.9888 0.9874 -0.0014 -344.06 -388.31 0.853 0.9318 0.9148 0 0 +hein 96 86.8 86.9 -0.2 0.9946 0.9930 -0.0016 -117.91 -246.46 0.528 0.9689 0.9499 0 0 diff --git a/lanes/opus-opusx2-r7.sweep.txt b/lanes/opus-opusx2-r7.sweep.txt new file mode 100644 index 00000000..f039d1af --- /dev/null +++ b/lanes/opus-opusx2-r7.sweep.txt @@ -0,0 +1,16 @@ +# lane-opusx2 r7: aligned tree + two-pass coarse energy + tf boost k=1.25 (combined winners) +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# 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 +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 +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 +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 +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 +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 +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 +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 +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 +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 +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 +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 +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