From af6881e2e1c3430c41546017637646c6d1527e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 21 Aug 2026 01:22:29 +0300 Subject: [PATCH] doc+test(opus-rs shim): SILK now reachable through the existing Application/bitrate surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ec-opus's Encoder now dispatches SILK for Voip under 20 kbps mono 20 ms frames, and this shim's OpusEncoder::new/bitrate_bps already carry both — no new API needed. Correct the stale "CELT-only" doc claim and add a test proving the shim's own encode() call produces a SILK TOC config (0..=11) under those conditions. --- shims/opus-rs/src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/shims/opus-rs/src/lib.rs b/shims/opus-rs/src/lib.rs index 7ccae9bd..58f6b4d6 100644 --- a/shims/opus-rs/src/lib.rs +++ b/shims/opus-rs/src/lib.rs @@ -15,10 +15,10 @@ //! `complexity` is accepted for drop-in compatibility and ignored: this //! encoder has one (fast) analysis path, not a ladder. //! -//! One behaviour is genuinely narrower and is stated rather than hidden: this -//! encoder is **CELT-only**, so [`Application::Voip`] selects a narrower -//! bandwidth at a given rate but not the SILK layer the name implies. Speech -//! below about 32 kbps is where that costs the most. +//! [`Application::Voip`] below 20 kbps, mono, 20 ms frames picks the SILK +//! layer, as the reference does; every other combination stays CELT. Stereo +//! SILK and SILK at other frame sizes fall back to CELT rather than +//! silently approximating it. #![forbid(unsafe_code)] #![warn(missing_docs)] @@ -439,4 +439,19 @@ mod tests { } assert!(MultistreamEncoder::surround(48_000, 9, Application::Audio).is_err()); } + + /// `Application::Voip` under 20 kbps, mono, 20 ms frames reaches the + /// SILK layer through this shim's existing surface — no new API, just + /// the application and bitrate the incumbent already exposed. TOC + /// configs 0..=11 are SILK (RFC 6716 Table 2). + #[test] + fn voip_below_20kbps_reaches_silk() { + let mut enc = OpusEncoder::new(48_000, 1, Application::Voip).unwrap(); + enc.bitrate_bps = 12_000; + let pcm = tone(960, 1); + let mut out = vec![0u8; 1500]; + let len = enc.encode(&pcm, 960, &mut out).unwrap(); + assert!(len > 1); + assert!(out[0] >> 3 <= 11, "TOC config {} is not SILK", out[0] >> 3); + } }