Skip to content

Add SILK NLSF quantization#160

Merged
thomas-vilte merged 1 commit into
pion:mainfrom
thomas-vilte:feat/silk-nlsf-encode
Jul 22, 2026
Merged

Add SILK NLSF quantization#160
thomas-vilte merged 1 commit into
pion:mainfrom
thomas-vilte:feat/silk-nlsf-encode

Conversation

@thomas-vilte

Copy link
Copy Markdown
Member

Description

adds the two-stage NLSF quantizer (silk_NLSF_encode): quantizeNLSF searches every stage-1 codebook vector, greedily quantizes the stage-2 residual backwards for each, and keeps whichever candidate gives the lowest weighted distortion after reconstructing and stabilizing it the way the decoder will. stabilizeNLSF is the encoder-side port of the same minimum-spacing procedure the decoder already had — I refactored decoder.go's normalizeLSFStabilization to call it directly instead of carrying its own duplicate ~140-line copy

ported from NLSF_encode.c and NLSF_stabilize.c

left encodeNLSF/emitNLSFIndices out of this one, same reasoning as find_pitch_lags.go in #158 — both are methods on *Encoder (need rangeEncoder), and that type doesn't exist yet. What's here is the quantization math itself; the range-coding wiring lands with the rest of the encoder plumbing. Test-wise this meant swapping the original's full Encoder→bitstream→Decoder round trip for a direct one — replaying the decoder's stage-2 reconstruction formula against the quantizer's own output, no bitstream involved. The regression test for the stage-2 clamp bug (#147) is unchanged in what it actually checks

known simplification, not introduced here: this quantizer brute-forces every stage-1 codebook entry with self-derived weights, instead of libopus's trellis/delayed-decision search (NLSF_del_dec_quant) with real per-frame perceptual weights and a rate term. Still produces valid, decodable output — just not necessarily the same codebook index libopus would pick

Reference issue

part of the SILK encoder series (#159)

Co-authored-by: François Allais <francois.allais@hotmail.com>
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.56098% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.87%. Comparing base (ad89c91) to head (e3099f7).

Files with missing lines Patch % Lines
internal/silk/nlsf_encode.go 97.54% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
+ Coverage   88.57%   88.87%   +0.30%     
==========================================
  Files          38       39       +1     
  Lines        8252     8325      +73     
==========================================
+ Hits         7309     7399      +90     
+ Misses        712      694      -18     
- Partials      231      232       +1     
Flag Coverage Δ
go 88.87% <97.56%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thomas-vilte
thomas-vilte requested a review from FrantaBOT July 21, 2026 20:43
@thomas-vilte
thomas-vilte merged commit 3f70331 into pion:main Jul 22, 2026
28 of 29 checks passed
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.

2 participants