From 0b2a55aadd6ada4784bb82413caab3b2e640e938 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:33:43 -0700 Subject: [PATCH] opus: the Medium profile stays wideband, set explicitly --- CHANGELOG.md | 6 +++--- api/migrations/next.md | 3 +-- crates/lxst-core/src/opus.rs | 15 +++++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8b969..545a49b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,9 @@ Parity with Python LXST 0.6.0. Several experimental APIs change. - `opus-rs` moves from 0.1.29 to 0.1.42, which fixes a decoder panic on a crafted SILK frame. A decoder panic on a peer's packet now rejects the packet and resets the decoder. -- The Medium voice profile encodes narrowband SILK at its 8 kbps ceiling, as - libopus does under Python LXST; it was wideband. The encoder takes the - profile's own sample rate. +- The Medium voice profile stays wideband SILK at its 8 kbps ceiling, now by + an explicit bandwidth setting; the encoder takes the profile's own sample + rate. (libopus 1.5 picks wideband there and libopus 1.6 narrowband.) - `lxst-embedded` sessions default to the 60, 70, and 5 second ring, wait, and connect times; `SessionConfig::times` (`CallTimes`) changes them. - A caller is established once it has handled CONNECTING, so a lost diff --git a/api/migrations/next.md b/api/migrations/next.md index 6a8ebf9..a7a3134 100644 --- a/api/migrations/next.md +++ b/api/migrations/next.md @@ -39,7 +39,6 @@ matches on `lxst_telephony::Error` need a new arm. settings, as upstream does. - Call links signal the next hop's MTU when Reticulum's `link_mtu_discovery` is on (`RNS/Link.py:392-397`). -- The Medium voice profile encodes narrowband SILK at its 8 kbps ceiling, as - libopus does under Python LXST. It was wideband. Decoders are unaffected. +- The Medium voice profile still encodes wideband SILK at its 8 kbps ceiling. - `opus-rs` is pinned at 0.1.42 (was 0.1.29). diff --git a/crates/lxst-core/src/opus.rs b/crates/lxst-core/src/opus.rs index 35a9043..7be2db7 100644 --- a/crates/lxst-core/src/opus.rs +++ b/crates/lxst-core/src/opus.rs @@ -1,9 +1,9 @@ use std::panic::{AssertUnwindSafe, catch_unwind}; -use opus_rs::{Application, OpusDecoder, OpusEncoder}; +use opus_rs::{Application, Bandwidth, OpusDecoder, OpusEncoder}; use thiserror::Error; -use crate::{AudioCodec, CodecKind, Frame, OpusApplication, Profile, RawAudioFrame}; +use crate::{AudioCodec, CodecKind, Frame, OpusApplication, OpusProfile, Profile, RawAudioFrame}; /// The fixed output clock used by the interoperable Opus packet decoder. pub const OPUS_MONO_DECODE_SAMPLE_RATE_HZ: u32 = 48_000; @@ -90,6 +90,11 @@ impl OpusEncoderState { .map_err(|err| OpusCodecError::Codec(err.to_string()))?; encoder.bitrate_bps = opus_profile.bitrate_ceiling() as i32; encoder.use_cbr = false; + if matches!(opus_profile, OpusProfile::VoiceMedium) { + // At 8 kbps libopus builds disagree (1.5 wideband, 1.6 narrowband); wideband is + // what this profile has always sent. + encoder.set_bandwidth(Bandwidth::Wideband); + } Ok(Self { profile, @@ -1067,7 +1072,7 @@ mod tests { } #[test] - fn opus_medium_uses_narrowband_silk_as_libopus_does() { + fn opus_medium_uses_wideband_silk_at_low_bitrate() { let profile = Profile::QualityMedium; let mut source = source_for(profile); let frame = source.next_raw_frame().unwrap(); @@ -1075,9 +1080,7 @@ mod tests { let encoded = encoder.encode_frame(&frame).unwrap(); - // Config 1, SILK narrowband 20 ms: libopus 1.6.1 under LXST 0.6.0 picks the same - // bandwidth at Medium's 8 kbps ceiling. - assert_eq!(encoded.payload[0] & !0x03, 0x08); + assert_eq!(encoded.payload[0] & !0x03, 0x48); assert!(encoded.payload.len() <= profile.opus_payload_ceiling_bytes().unwrap()); }