forge
Explore
Log in

Don't you dare go Hollow

Tune silk speech quantizer

Browse files at this commit

80636c6f72793f588a4d0c628f7865328e3c519dAhmet Kaan GümüşParent: 38c15e3
  • perf
    • tune silk speech quantizer
Show full message
perf(ec-opus): tune silk speech quantizer
crates/ec-opus/src/silk_enc_write.rsmodified+8 -2
@@ -75,7 +75,8 @@ const GAIN_STEP: f32 = 1.1702;
7575 const RESERVOIR_FRAMES: f32 = 4.0;
7676 /// Rate penalty per unit pulse magnitude in the quantiser's squared-error
7777 /// cost: a dead zone that lets the rate loop keep finer gains for the same
78-/// bits (swept 0..2.5 on speech-like content; 1.5 maximised correlation).
78+/// bits. NB 20 ms speech wants a smaller dead zone; 10 ms WB needs a
79+/// slightly smaller one than the 10 ms NB/MB rows to keep upper-band pulses.
7980 const PULSE_LAMBDA: f32 = 1.5;
8081
8182 impl SilkEncoder {
@@ -484,6 +485,11 @@ impl SilkEncoder {
484485 // vector that best predicts the residual from the *reconstructed*
485486 // history, then quantise sample by sample with the shaped output error
486487 // fed back into the target, under the decoder's seed-driven sign flips.
488+ let pulse_lambda = match (frame_ms, fs) {
489+ (20, 8) => 1.25,
490+ (10, 16) => 1.45,
491+ _ => PULSE_LAMBDA,
492+ };
487493 let run = |per: usize, gains_q16: &[i32; MAX_NB_SUBFR]| -> Run {
488494 let cbk = codebook(per);
489495 let mut r = r.clone();
@@ -551,7 +557,7 @@ impl SilkEncoder {
551557 .filter(|p| p.abs() <= MAX_PULSE)
552558 .min_by(|&a, &b| {
553559 let cost = |p: i32| {
554- (recon(p) - target).powi(2) + PULSE_LAMBDA * p.abs() as f32
560+ (recon(p) - target).powi(2) + pulse_lambda * p.abs() as f32
555561 };
556562 cost(a).partial_cmp(&cost(b)).unwrap()
557563 })
crates/ec-opus/tests/conformance.rsmodified+8 -9
@@ -1714,11 +1714,11 @@ fn silk_mono_nb_wb_roundtrip() {
17141714 #[test]
17151715 fn silk_mediumband_and_10ms_roundtrip() {
17161716 let pcm = speech_like();
1717- for (tag, fs_khz, frame_ms, config, cutoff, bps) in [
1718- ("NB10", 8usize, 10usize, 0u8, 3500.0, 12_000u32),
1719- ("MB10", 12, 10, 4, 5500.0, 16_000),
1720- ("WB10", 16, 10, 8, 7000.0, 20_000),
1721- ("MB20", 12, 20, 5, 5500.0, 16_000),
1717+ for (tag, fs_khz, frame_ms, config, cutoff, bps, floor) in [
1718+ ("NB10", 8usize, 10usize, 0u8, 3500.0, 12_000u32, 0.89f64),
1719+ ("MB10", 12, 10, 4, 5500.0, 16_000, 0.91),
1720+ ("WB10", 16, 10, 8, 7000.0, 20_000, 0.93),
1721+ ("MB20", 12, 20, 5, 5500.0, 16_000, 0.95),
17221722 ] {
17231723 let enc = match fs_khz {
17241724 8 => SilkEncoder::new(false),
@@ -1735,7 +1735,7 @@ fn silk_mediumband_and_10ms_roundtrip() {
17351735 "silk {tag}: corr {corr:.4} at lag {lag}, voiced {voiced}/{} frames, {kbps:.2} kbps",
17361736 packets.len()
17371737 );
1738- assert!(corr >= 0.75, "{tag}: corr {corr:.4}");
1738+ assert!(corr >= floor, "{tag}: corr {corr:.4}");
17391739 assert!(
17401740 frame_ms == 10 || voiced > 0,
17411741 "{tag}: no frame coded with LTP"
@@ -1846,7 +1846,6 @@ fn silk_stereo_speech_roundtrip() {
18461846 let (decoded, _, _) = silk_roundtrip_ms(silk, &mono, frame_ms, Some(per_channel_bps));
18471847 mono_floor[ch] = aligned_corr(&reference, &decoded, 2000).0;
18481848 }
1849-
18501849 let mut enc = Encoder::new(48000, 2, Application::Voip).unwrap();
18511850 enc.set_mode(Some(ec_opus::Mode::Silk));
18521851 enc.set_bandwidth(Some(bandwidth));
@@ -1959,8 +1958,8 @@ fn silk_compares_to_celt_on_speech_at_speech_rates() {
19591958 );
19601959 assert!(silk_corr >= 0.95, "{tag}: SILK corr {silk_corr:.4}");
19611960 assert!(
1962- silk_corr + 0.01 >= celt_corr,
1963- "{tag}: SILK {silk_corr:.4} trails CELT {celt_corr:.4} by >0.01"
1961+ silk_corr >= celt_corr,
1962+ "{tag}: SILK {silk_corr:.4} trails CELT {celt_corr:.4}"
19641963 );
19651964 }
19661965 }