Tune silk speech quantizer
Browse files at this commit80636c6f72793f588a4d0c628f7865328e3c519dParent: 38c15e3- perf
- tune silk speech quantizer
2 changed files +16 -11
crates/ec-opus/src/silk_enc_write.rsmodified+8 -2
| @@ -75,7 +75,8 @@ const GAIN_STEP: f32 = 1.1702; | |||
| 75 | const RESERVOIR_FRAMES: f32 = 4.0; | 75 | const RESERVOIR_FRAMES: f32 = 4.0; |
| 76 | /// Rate penalty per unit pulse magnitude in the quantiser's squared-error | 76 | /// Rate penalty per unit pulse magnitude in the quantiser's squared-error |
| 77 | /// cost: a dead zone that lets the rate loop keep finer gains for the same | 77 | /// 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. | ||
| 79 | const PULSE_LAMBDA: f32 = 1.5; | 80 | const PULSE_LAMBDA: f32 = 1.5; |
| 80 | 81 | ||
| 81 | impl SilkEncoder { | 82 | impl SilkEncoder { |
| @@ -484,6 +485,11 @@ impl SilkEncoder { | |||
| 484 | // vector that best predicts the residual from the *reconstructed* | 485 | // vector that best predicts the residual from the *reconstructed* |
| 485 | // history, then quantise sample by sample with the shaped output error | 486 | // history, then quantise sample by sample with the shaped output error |
| 486 | // fed back into the target, under the decoder's seed-driven sign flips. | 487 | // 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 | + }; | ||
| 487 | let run = |per: usize, gains_q16: &[i32; MAX_NB_SUBFR]| -> Run { | 493 | let run = |per: usize, gains_q16: &[i32; MAX_NB_SUBFR]| -> Run { |
| 488 | let cbk = codebook(per); | 494 | let cbk = codebook(per); |
| 489 | let mut r = r.clone(); | 495 | let mut r = r.clone(); |
| @@ -551,7 +557,7 @@ impl SilkEncoder { | |||
| 551 | .filter(|p| p.abs() <= MAX_PULSE) | 557 | .filter(|p| p.abs() <= MAX_PULSE) |
| 552 | .min_by(|&a, &b| { | 558 | .min_by(|&a, &b| { |
| 553 | let cost = |p: i32| { | 559 | 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 |
| 555 | }; | 561 | }; |
| 556 | cost(a).partial_cmp(&cost(b)).unwrap() | 562 | cost(a).partial_cmp(&cost(b)).unwrap() |
| 557 | }) | 563 | }) |
crates/ec-opus/tests/conformance.rsmodified+8 -9
| @@ -1714,11 +1714,11 @@ fn silk_mono_nb_wb_roundtrip() { | |||
| 1714 | #[test] | 1714 | #[test] |
| 1715 | fn silk_mediumband_and_10ms_roundtrip() { | 1715 | fn silk_mediumband_and_10ms_roundtrip() { |
| 1716 | let pcm = speech_like(); | 1716 | let pcm = speech_like(); |
| 1717 | - for (tag, fs_khz, frame_ms, config, cutoff, bps) in [ | 1717 | + for (tag, fs_khz, frame_ms, config, cutoff, bps, floor) in [ |
| 1718 | - ("NB10", 8usize, 10usize, 0u8, 3500.0, 12_000u32), | 1718 | + ("NB10", 8usize, 10usize, 0u8, 3500.0, 12_000u32, 0.89f64), |
| 1719 | - ("MB10", 12, 10, 4, 5500.0, 16_000), | 1719 | + ("MB10", 12, 10, 4, 5500.0, 16_000, 0.91), |
| 1720 | - ("WB10", 16, 10, 8, 7000.0, 20_000), | 1720 | + ("WB10", 16, 10, 8, 7000.0, 20_000, 0.93), |
| 1721 | - ("MB20", 12, 20, 5, 5500.0, 16_000), | 1721 | + ("MB20", 12, 20, 5, 5500.0, 16_000, 0.95), |
| 1722 | ] { | 1722 | ] { |
| 1723 | let enc = match fs_khz { | 1723 | let enc = match fs_khz { |
| 1724 | 8 => SilkEncoder::new(false), | 1724 | 8 => SilkEncoder::new(false), |
| @@ -1735,7 +1735,7 @@ fn silk_mediumband_and_10ms_roundtrip() { | |||
| 1735 | "silk {tag}: corr {corr:.4} at lag {lag}, voiced {voiced}/{} frames, {kbps:.2} kbps", | 1735 | "silk {tag}: corr {corr:.4} at lag {lag}, voiced {voiced}/{} frames, {kbps:.2} kbps", |
| 1736 | packets.len() | 1736 | packets.len() |
| 1737 | ); | 1737 | ); |
| 1738 | - assert!(corr >= 0.75, "{tag}: corr {corr:.4}"); | 1738 | + assert!(corr >= floor, "{tag}: corr {corr:.4}"); |
| 1739 | assert!( | 1739 | assert!( |
| 1740 | frame_ms == 10 || voiced > 0, | 1740 | frame_ms == 10 || voiced > 0, |
| 1741 | "{tag}: no frame coded with LTP" | 1741 | "{tag}: no frame coded with LTP" |
| @@ -1846,7 +1846,6 @@ fn silk_stereo_speech_roundtrip() { | |||
| 1846 | let (decoded, _, _) = silk_roundtrip_ms(silk, &mono, frame_ms, Some(per_channel_bps)); | 1846 | let (decoded, _, _) = silk_roundtrip_ms(silk, &mono, frame_ms, Some(per_channel_bps)); |
| 1847 | mono_floor[ch] = aligned_corr(&reference, &decoded, 2000).0; | 1847 | mono_floor[ch] = aligned_corr(&reference, &decoded, 2000).0; |
| 1848 | } | 1848 | } |
| 1849 | - | ||
| 1850 | let mut enc = Encoder::new(48000, 2, Application::Voip).unwrap(); | 1849 | let mut enc = Encoder::new(48000, 2, Application::Voip).unwrap(); |
| 1851 | enc.set_mode(Some(ec_opus::Mode::Silk)); | 1850 | enc.set_mode(Some(ec_opus::Mode::Silk)); |
| 1852 | enc.set_bandwidth(Some(bandwidth)); | 1851 | enc.set_bandwidth(Some(bandwidth)); |
| @@ -1959,8 +1958,8 @@ fn silk_compares_to_celt_on_speech_at_speech_rates() { | |||
| 1959 | ); | 1958 | ); |
| 1960 | assert!(silk_corr >= 0.95, "{tag}: SILK corr {silk_corr:.4}"); | 1959 | assert!(silk_corr >= 0.95, "{tag}: SILK corr {silk_corr:.4}"); |
| 1961 | assert!( | 1960 | assert!( |
| 1962 | - silk_corr + 0.01 >= celt_corr, | 1961 | + silk_corr >= celt_corr, |
| 1963 | - "{tag}: SILK {silk_corr:.4} trails CELT {celt_corr:.4} by >0.01" | 1962 | + "{tag}: SILK {silk_corr:.4} trails CELT {celt_corr:.4}" |
| 1964 | ); | 1963 | ); |
| 1965 | } | 1964 | } |
| 1966 | } | 1965 | } |