forge
Explore
Log in

Don't you dare go Hollow

diag(opus): swept CVBR tf-boost knobs + X/band-energy fingerprint in the tf debug

Browse files at this commit

ff9aa5ebe1509a59aa771ce86f104d18f71a4dceAhmet Kaan GümüşParent: 673c26b
The tf boost k/offset and an optional transient-only gate come from
EC_OPUS_TF_K / EC_OPUS_TF_OFF / EC_OPUS_TF_GATE so one build sweeps the
grid; the defaults (k=1, off=.044, all frames) are byte-identical to the
shipped term. EC_OPUS_TF_DEBUG additionally prints the first 8 band
log-energies and sum|X| of the tf channel, which is what the libopus
comparison needs.
crates/ec-opus/src/celt_enc.rsmodified+30 -1
@@ -43,6 +43,21 @@ use crate::celt::{
43 };43 };
44 use crate::range::RangeEncoder;44 use crate::range::RangeEncoder;
45 45
46+/// TF-boost sweep knobs (lane opustr2): `k * (tf_estimate - off) * target`,
47+/// optionally applied only on frames the transient analysis flagged (other
48+/// frames keep the shipped k=1). Read once from the environment;
49+/// `EC_OPUS_TF_K` / `EC_OPUS_TF_OFF` / `EC_OPUS_TF_GATE=transient`.
50+fn tf_boost_params() -> (f32, f32, bool) {
51+ static P: std::sync::OnceLock<(f32, f32, bool)> = std::sync::OnceLock::new();
52+ *P.get_or_init(|| {
53+ let f = |name: &str, dflt: f32| {
54+ std::env::var(name).ok().and_then(|v| v.parse().ok()).unwrap_or(dflt)
55+ };
56+ let gate = std::env::var("EC_OPUS_TF_GATE").map(|v| v == "transient").unwrap_or(false);
57+ (f("EC_OPUS_TF_K", 1.0), f("EC_OPUS_TF_OFF", 0.044), gate)
58+ })
59+}
60+
46 const CACHE_BITS: &[u8] = &crate::celt::CACHE_BITS;61 const CACHE_BITS: &[u8] = &crate::celt::CACHE_BITS;
47 const INV_TABLE: [u8; 128] = [62 const INV_TABLE: [u8; 128] = [
48 255,255,156,110, 86, 70, 59, 51, 45, 40, 37, 33, 31, 28, 26, 25,63 255,255,156,110, 86, 70, 59, 51, 45, 40, 37, 33, 31, 28, 26, 25,
@@ -901,7 +916,14 @@ impl CeltEncoder {
901 // with it, reell@64 goes 2.697 -> 1.764 and reell@96 4.499 -> 2.114916 // with it, reell@64 goes 2.697 -> 1.764 and reell@96 4.499 -> 2.114
902 // (`lanes/opus-opustr-r2.sweep.txt`). Upgrade path: gate the x2 on917 // (`lanes/opus-opustr-r2.sweep.txt`). Upgrade path: gate the x2 on
903 // content -- it pays on music transients and starves hein's speech.918 // content -- it pays on music transients and starves hein's speech.
904- target += ((tf_estimate - 0.044) * target as f32) as i32;919+ // SWEPT (lane opustr2): k/offset/gate come from `tf_boost_params()`;
920+ // the defaults (k=1, off=.044, gate=all) are the shipped point and
921+ // reproduce the line above byte for byte.
922+ {
923+ let (k, off, gate_transient) = tf_boost_params();
924+ let k_eff = if !gate_transient || is_transient { k } else { 1.0 };
925+ target += (k_eff * (tf_estimate - off) * target as f32) as i32;
926+ }
905 // floor depth cap (C:1683-1695): SHR32/MULT16_32_Q15 are identity.927 // floor depth cap (C:1683-1695): SHR32/MULT16_32_Q15 are identity.
906 {928 {
907 let bins = E_BANDS[NB_BANDS - 2] << lm;929 let bins = E_BANDS[NB_BANDS - 2] << lm;
@@ -1848,6 +1870,13 @@ impl CeltEncoder {
1848 tf_select = 1;1870 tf_select = 1;
1849 }1871 }
1850 if std::env::var_os("EC_OPUS_TF_DEBUG").is_some() {1872 if std::env::var_os("EC_OPUS_TF_DEBUG").is_some() {
1873+ let fp: f32 = self.x[tf_chan * n..tf_chan * n + (E_BANDS[len] << lm)]
1874+ .iter()
1875+ .map(|v| v.abs())
1876+ .sum();
1877+ let ble: Vec<String> =
1878+ self.band_log_e[..8].iter().map(|v| format!("{v:.3}")).collect();
1879+ eprint!("BLE {} | FP {fp:.6} ", ble.join(" "));
1851 eprintln!(1880 eprintln!(
1852 "tf: trans {is_transient} lm {lm} tfe {tf_estimate:.4} bias {bias:.5} \1881 "tf: trans {is_transient} lm {lm} tfe {tf_estimate:.4} bias {bias:.5} \
1853 lambda {lambda} sel {tf_select} selcost {selcost:?} metric {:?} imp {:?}",1882 lambda {lambda} sel {tf_select} selcost {selcost:?} metric {:?} imp {:?}",