forge
Explore
Log in

Don't you dare go Hollow

12 kHz input caps bandwidth at Medium, not Narrow

Browse files at this commit

6efce8183d4bd381ff75e969e5a25315c99e5b77Ahmet Kaan GümüşParent: b3bcc7e
  • fix
    • 12 kHz input caps bandwidth at Medium, not Narrow
Show full message
fix(opus): 12 kHz input caps bandwidth at Medium, not Narrow

opus_encode_native's input-rate ceiling has four tiers (<=24k SWB,
<=16k WB, <=12k MB, <=8k NB); our match folded 12 kHz into the Narrow
arm, coding 12 kHz VoIP a band narrower than the reference would.

The opus-rs shim's slower-rates test surfaced it, stale in the other
direction: it still expected CELT's 120-sample overlap at every rate,
but since the libopus threshold port 16 kHz and below dispatch to SILK
at 32 kbps, whose resampler look-ahead is what the encoder reports.
Both expectations now follow the dispatch.
crates/ec-opus/src/encoder.rsmodified+1 -0
@@ -680,6 +680,7 @@ impl Encoder {
680 48000 => Bandwidth::Full,680 48000 => Bandwidth::Full,
681 24000 => Bandwidth::SuperWide,681 24000 => Bandwidth::SuperWide,
682 16000 => Bandwidth::Wide,682 16000 => Bandwidth::Wide,
683+ 12000 => Bandwidth::Medium,
683 _ => Bandwidth::Narrow,684 _ => Bandwidth::Narrow,
684 };685 };
685 BWS[idx].min(ceiling)686 BWS[idx].min(ceiling)
shims/opus-rs/src/lib.rsmodified+8 -4
@@ -374,15 +374,19 @@ mod tests {
374 }374 }
375 375
376 /// Input below 48 kHz, which the shim used to refuse outright, and the376 /// Input below 48 kHz, which the shim used to refuse outright, and the
377- /// `look_ahead` that goes with it (120 samples at 48 kHz, scaled).377+ /// `look_ahead` that goes with it. 48/24 kHz VoIP at 32 kbps run
378+ /// hybrid (SWB/FB), so the delay is CELT's 120-sample overlap, scaled;
379+ /// 16 kHz and below cap the bandwidth at WB or narrower, where hybrid
380+ /// does not exist, so dispatch takes SILK and the delay is the SILK
381+ /// resampler look-ahead (WB 50 / MB 54 / NB 58 at 48 kHz), scaled.
378 #[test]382 #[test]
379 fn slower_input_rates_encode_and_report_their_own_delay() {383 fn slower_input_rates_encode_and_report_their_own_delay() {
380 for &(rate, frame, look) in &[384 for &(rate, frame, look) in &[
381 (48_000i32, 960usize, 120usize),385 (48_000i32, 960usize, 120usize),
382 (24_000, 480, 60),386 (24_000, 480, 60),
383- (16_000, 320, 40),387+ (16_000, 320, 50 / 3),
384- (12_000, 240, 30),388+ (12_000, 240, 54 / 4),
385- (8_000, 160, 20),389+ (8_000, 160, 58 / 6),
386 ] {390 ] {
387 let mut enc = OpusEncoder::new(rate, 1, Application::Voip).unwrap();391 let mut enc = OpusEncoder::new(rate, 1, Application::Voip).unwrap();
388 enc.bitrate_bps = 32_000;392 enc.bitrate_bps = 32_000;