Skip to content

tns: fix inverted adaptive TNS order for low-bitrate encoders (D4)#108

Closed
nschimme wants to merge 3 commits into
knik0:masterfrom
nschimme:tns-d4-adaptive-order
Closed

tns: fix inverted adaptive TNS order for low-bitrate encoders (D4)#108
nschimme wants to merge 3 commits into
knik0:masterfrom
nschimme:tns-d4-adaptive-order

Conversation

@nschimme

Copy link
Copy Markdown
Contributor

Summary

  • Corrects the adaptive tnsMaxOrderLong assignment in TnsInit: at voip bitrates (<96 kbps/ch) the encoder now uses order 8 instead of order 12, reducing autocorrelation and Levinson-Durbin cost
  • At ≥96 kbps/ch, order 12 is retained for full prediction quality
  • The old code had the logic inverted: lowest-bitrate encoders (voip 16 kbps) were paying the highest analysis cost

Motivation

This is the D4 arm from the TNS Phase D investigation. Local benchmark on 449 files (TCD-VOIP + music_low, 16 kbps):

arm voip ΔMOS vs base crits (Δ < −0.20) encode time vs base
cand (current HEAD 19b39b1) +0.047 2 (C_24_ECHO_FA −0.224, C_15_NOISE_ML −0.203) +5.9%
D4 (this branch) +0.054 1 (C_15_NOISE_ML −0.214) faster (9.0 ms vs 10.8 ms/file)

D4 fixes C_24_ECHO_FA (+0.183 vs base, was −0.224) and reduces encode time by reducing filter order at voip rates.

Test plan

  • CI benchmark suite (voip + music_low) — primary acceptance criterion
  • No new regressions vs HEAD (cand): voip avg ≥ +0.047, music_low within ±0.005
  • Encode CPU ≤ +10% vs base
  • Bit-exact tests may differ from cand (lower order means different filter coefficients)

🤖 Generated with Claude Code

nschimme and others added 3 commits June 11, 2026 09:17
- Refactored bmask() in quantize.c into a one-pass loop with energy floors.
- Ported spectral whitening and adaptive thresholds to tns.c.
- Optimized autocorrelation and added safety clamping for TNS coefficients.
- Enabled TNS by default and adjusted PNS levels.
- Reworked all comments to match a professional signal engineering style.
- Added TNS_TUNING.md documenting parameter derivations.
At voip rates (<96 kbps/ch), the old 3-tier table assigned order 12,
the highest analysis cost. Correct to order 8 at <96 kbps and 12 at
>=96 kbps — matching the CPU budget constraint where lower bitrates
can afford less filter precision.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nschimme nschimme closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant