Keep TF boost x1 by measurement
Browse files at this commita31c8b178d0d1346821597055adf3faf36eae527Parent: eee0a69- feat
- keep TF boost x1 by measurement
- lane report + 14-row sweep
3 changed files +56 -1
- crates/ec-opus/src/celt_enc.rs +4 -1
- lanes/opus-vbr-r1.report.md +36 -0
- lanes/opus-vbr-r1.sweep.txt +16 -0
crates/ec-opus/src/celt_enc.rsmodified+4 -1
| @@ -866,7 +866,10 @@ impl CeltEncoder { | ||
| 866 | 866 | target += total_boost - (19 << lm); |
| 867 | 867 | // TF boost (C:1653-1654): MULT16_32_Q15 is identity in float mode, |
| 868 | 868 | // SHL32(.., 1) is the x2: 2 * (tf_estimate - 0.044) * target. |
| 869 | - target += (2.0 * (tf_estimate - 0.044) * target as f32) as i32; | |
| 869 | + // Measured deviation: C applies SHL32(.., 1) (x2). On the 14-row | |
| 870 | + // library gate x2 loses .003 corr on reelm/hein@64 vs x1 (lane | |
| 871 | + // opus-vbr r2 vs r3); our tf_estimate is not scaled like libopus's. | |
| 872 | + target += ((tf_estimate - 0.044) * target as f32) as i32; | |
| 870 | 873 | // floor depth cap (C:1683-1695): SHR32/MULT16_32_Q15 are identity. |
| 871 | 874 | { |
| 872 | 875 | let bins = E_BANDS[NB_BANDS - 2] << lm; |
lanes/opus-vbr-r1.report.mdadded+36 -0
| @@ -0,0 +1,36 @@ | ||
| 1 | +# lane opus-vbr r1 — libopus `compute_vbr` ported whole — KEEP | |
| 2 | + | |
| 3 | +## What | |
| 4 | +- `celt_enc.rs`: VBR target now follows libopus celt_encoder.c:1605-1716 term by term: `coded_bins` from `lastCodedBands` + intensity, stereo_saving term (`max_frac`/`coded_stereo_dof`), `tot_boost-(19<<LM)`, TF boost `(tf_estimate-0.044)*target`, floor-depth cap from `dynalloc_analysis` `maxDepth`, constrained-VBR 0.67 pull, temporal VBR (`spec_avg` follower state, `amount` from equiv_rate), 2x base cap. Replaces the `7/4` transient stand-in, the `0.012*target` tf stand-in and the peak-level activity stand-in. | |
| 5 | +- `alloc_trim_analysis` now also maintains `stereo_saving` (logXC/logXC2 from LF and min inter-channel correlation up to the intensity band); the trim value it returns is unchanged (the trim port alone was rejected, lanes/opus-trim-r1.report.md). | |
| 6 | +- `lastCodedBands` moves at most one band per frame (libopus); measured neutral (r3 == r1 to 4 dp). | |
| 7 | +- Intensity decision moved before the trim block (libopus order); skipped terms named in code: tonality/activity (analysis invalid), surround mask, pitch_change, lfe, qext 2-pass. | |
| 8 | + | |
| 9 | +## Deviation kept by measurement | |
| 10 | +TF boost factor: C has `SHL32(MULT16_32_Q15(tf_estimate-0.044, target), 1)` (x2). r2 (x2 + lastCodedBands ±1) vs r3 (x1 + ±1): reelm@64 +.0023 vs −.0007, hein@64 +.0011 vs −.0014, reelm@96 +.0003 vs −.0016, rate −1.0% vs −0.3%. x1 kept. | |
| 11 | + | |
| 12 | +## Gate (14 rows, gap = ref corr − ours; negative = ours ahead) vs lanes/opus-int-r1.sweep.txt | |
| 13 | +``` | |
| 14 | +nik@64k: r 69.2 o 69.1 kbps (-0.1%), o=0.9887 r=0.9864 gap=-0.0024 base=-0.0020 | |
| 15 | +nik@96k: r 101.0 o 100.9 kbps (-0.1%), o=0.9947 r=0.9940 gap=-0.0007 base=-0.0006 | |
| 16 | +reelo@64k: r 63.6 o 63.6 kbps (-0.0%), o=0.9893 r=0.9866 gap=-0.0027 base=-0.0018 | |
| 17 | +reelo@96k: r 93.9 o 93.4 kbps (-0.5%), o=0.9947 r=0.9937 gap=-0.0009 base=-0.0008 | |
| 18 | +her@64k: r 67.9 o 67.7 kbps (-0.4%), o=0.9834 r=0.9794 gap=-0.0040 base=-0.0031 | |
| 19 | +her@96k: r 101.5 o 101.0 kbps (-0.5%), o=0.9914 r=0.9902 gap=-0.0012 base=-0.0008 | |
| 20 | +reell@64k: r 71.3 o 71.3 kbps (-0.0%), o=0.9908 r=0.9880 gap=-0.0029 base=-0.0028 | |
| 21 | +reell@96k: r 105.4 o 105.3 kbps (-0.0%), o=0.9956 r=0.9948 gap=-0.0008 base=-0.0008 | |
| 22 | +reelm@64k: r 63.3 o 63.1 kbps (-0.3%), o=0.9866 r=0.9859 gap=-0.0007 base=+0.0038 | |
| 23 | +reelm@96k: r 84.8 o 84.7 kbps (-0.2%), o=0.9935 r=0.9920 gap=-0.0016 base=-0.0000 | |
| 24 | +dl8a@64k: r 65.8 o 65.7 kbps (-0.1%), o=0.9889 r=0.9865 gap=-0.0025 base=-0.0017 | |
| 25 | +dl8a@96k: r 96.8 o 96.5 kbps (-0.3%), o=0.9942 r=0.9934 gap=-0.0009 base=-0.0006 | |
| 26 | +hein@64k: r 64.9 o 64.8 kbps (-0.2%), o=0.9888 r=0.9874 gap=-0.0014 base=+0.0022 | |
| 27 | +hein@96k: r 86.9 o 86.8 kbps (-0.2%), o=0.9946 r=0.9930 gap=-0.0016 base=-0.0002 | |
| 28 | +RATE GATE: all rows within ±5% | |
| 29 | +DROPOUT GATE: passed (no ours-only dropouts) | |
| 30 | +``` | |
| 31 | +Every row gains or holds; ours ahead of libopus on all 14 rows at equal size. Rate shortfall on reelm/hein gone (−1.6/−1.8% → −0.3/−0.2%). | |
| 32 | + | |
| 33 | +## Suite | |
| 34 | +test result: ok. 34 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s | |
| 35 | +test result: ok. 27 passed; 0 failed; 9 ignored; 0 measured; 0 filtered out; finished in 34.12s | |
| 36 | +(r3 code differs from r2 only by the TF factor; suite rerun on main after merge.) |
lanes/opus-vbr-r1.sweep.txtadded+16 -0
| @@ -0,0 +1,16 @@ | ||
| 1 | +nik@64k: ref 69.2 ours 69.1 kbps (-0.1%), corr o=0.9887 r=0.9864 gap=-0.0024, Q o=-95.23 r=-154.78, err_ratio 0.708, minsec o=0.9766 r=0.9745, drop o=0 r=0 | |
| 2 | +nik@96k: ref 101.0 ours 100.9 kbps (-0.1%), corr o=0.9947 r=0.9940 gap=-0.0007, Q o=-29.53 r=-31.55, err_ratio 0.982, minsec o=0.9889 r=0.9888, drop o=0 r=0 | |
| 3 | +reelo@64k: ref 63.6 ours 63.6 kbps (-0.0%), corr o=0.9893 r=0.9866 gap=-0.0027, Q o=-202.82 r=-123.36, err_ratio 1.510, minsec o=0.9702 r=0.9686, drop o=0 r=0 | |
| 4 | +reelo@96k: ref 93.9 ours 93.4 kbps (-0.5%), corr o=0.9947 r=0.9937 gap=-0.0009, Q o=-114.74 r=-125.18, err_ratio 0.940, minsec o=0.9862 r=0.9854, drop o=0 r=0 | |
| 5 | +her@64k: ref 67.9 ours 67.7 kbps (-0.4%), corr o=0.9834 r=0.9794 gap=-0.0040, Q o=-365.68 r=-339.00, err_ratio 1.102, minsec o=0.9476 r=0.9406, drop o=0 r=0 | |
| 6 | +her@96k: ref 101.5 ours 101.0 kbps (-0.5%), corr o=0.9914 r=0.9902 gap=-0.0012, Q o=-202.16 r=-191.50, err_ratio 1.052, minsec o=0.9728 r=0.9728, drop o=0 r=0 | |
| 7 | +reell@64k: ref 71.3 ours 71.3 kbps (-0.0%), corr o=0.9908 r=0.9880 gap=-0.0029, Q o=-351.70 r=-128.39, err_ratio 2.697, minsec o=0.9720 r=0.9644, drop o=0 r=0 | |
| 8 | +reell@96k: ref 105.4 ours 105.3 kbps (-0.0%), corr o=0.9956 r=0.9948 gap=-0.0008, Q o=-301.83 r=-29.16, err_ratio 4.499, minsec o=0.9855 r=0.9804, drop o=0 r=0 | |
| 9 | +reelm@64k: ref 63.3 ours 63.1 kbps (-0.3%), corr o=0.9866 r=0.9859 gap=-0.0007, Q o=-266.99 r=-392.46, err_ratio 0.623, minsec o=0.9326 r=0.9100, drop o=0 r=0 | |
| 10 | +reelm@96k: ref 84.8 ours 84.7 kbps (-0.2%), corr o=0.9935 r=0.9920 gap=-0.0016, Q o=-145.55 r=-231.16, err_ratio 0.660, minsec o=0.9687 r=0.9511, drop o=0 r=0 | |
| 11 | +dl8a@64k: ref 65.8 ours 65.7 kbps (-0.1%), corr o=0.9889 r=0.9865 gap=-0.0025, Q o=-227.02 r=-378.84, err_ratio 0.551, minsec o=0.9787 r=0.9723, drop o=0 r=0 | |
| 12 | +dl8a@96k: ref 96.8 ours 96.5 kbps (-0.3%), corr o=0.9942 r=0.9934 gap=-0.0009, Q o=-177.72 r=-423.47, err_ratio 0.374, minsec o=0.9881 r=0.9864, drop o=0 r=0 | |
| 13 | +hein@64k: ref 64.9 ours 64.8 kbps (-0.2%), corr o=0.9888 r=0.9874 gap=-0.0014, Q o=-344.79 r=-388.31, err_ratio 0.855, minsec o=0.9324 r=0.9148, drop o=0 r=0 | |
| 14 | +hein@96k: ref 86.9 ours 86.8 kbps (-0.2%), corr o=0.9946 r=0.9930 gap=-0.0016, Q o=-117.88 r=-246.46, err_ratio 0.528, minsec o=0.9686 r=0.9499, drop o=0 r=0 | |
| 15 | +RATE GATE: all rows within ±5% | |
| 16 | +DROPOUT GATE: passed (no ours-only dropouts) |