Skip to content

Port the RFC SILK output resampler#93

Open
zshang-oai wants to merge 1 commit intomasterfrom
codex/silk-output-resampling
Open

Port the RFC SILK output resampler#93
zshang-oai wants to merge 1 commit intomasterfrom
codex/silk-output-resampling

Conversation

@zshang-oai
Copy link
Copy Markdown
Contributor

Summary

This ports the decoder-side SILK output resampler from the RFC reference implementation into a dedicated Go subpackage and wires the Opus decoder to resample SILK output directly to the caller's requested output rate.

The branch removes the old naive sample-repetition path and replaces it with the RFC-style decoder resampler state, delay handling, and per-ratio FIR/IIR paths.

Public API

This PR updates the public decoder API so callers can request a specific output sample rate and channel count instead of relying on the old fixed behavior:

  • add NewDecoderWithOutput(sampleRate, channels)
  • change (*Decoder).Init(sampleRate, channels) to validate and store the requested output format
  • add DecodeToInt16 and DecodeToFloat32 helpers that return samples-per-channel
  • make Decode/DecodeFloat32 use the configured output format before converting to the public PCM buffers

That aligns the exposed API with the output rates exercised by the RFC conformance flow: 8, 12, 16, 24, or 48 kHz, mono or stereo.

RFC Alignment

Where possible, this follows the RFC/reference implementation directly:

  • RFC 6716 Section 4.2.9 defines decoder-side SILK resampling and makes the resampler delay normative while allowing implementation freedom in the filter itself.
  • RFC 6716 Section 6.1 defines conformance against the Appendix A reference decoder and explicitly evaluates supported output sampling rates and channel counts.
  • RFC 6716 says the Appendix A reference source takes precedence if prose and source diverge, so this branch stays structurally close to the reference resampler and decoder-side setup.

Relevant references:

Implementation Notes

  • add internal/resample/silk as a Go port of the RFC SILK decoder resampler
  • preserve the reference delay matrix and supported decoder-side rate conversions
  • keep per-channel resampler state in Decoder so mono/stereo SILK output can be resampled without reinitializing every packet
  • update PCM conversion helpers to operate on configured channel counts
  • add impulse fixtures and round-trip checks for the supported decoder-side SILK ratios

Validation

  • go test ./...
  • go test -race ./...
  • attempted golangci-lint run, but the tool currently fails in this environment before analysis with context loading failed: no go files to analyze

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 84.13043% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.98%. Comparing base (10397d9) to head (469fda8).

Files with missing lines Patch % Lines
decoder.go 82.73% 15 Missing and 9 partials ⚠️
internal/resample/silk/down_fir.go 75.26% 23 Missing ⚠️
internal/resample/silk/resampler.go 83.19% 17 Missing and 3 partials ⚠️
internal/resample/silk/fixed.go 71.42% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   76.32%   78.98%   +2.66%     
==========================================
  Files           8       13       +5     
  Lines        1246     1680     +434     
==========================================
+ Hits          951     1327     +376     
- Misses        264      310      +46     
- Partials       31       43      +12     
Flag Coverage Δ
go 78.98% <84.13%> (+2.66%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@zshang-oai zshang-oai changed the title [codex] Port the RFC SILK output resampler Port the RFC SILK output resampler Mar 27, 2026
@zshang-oai zshang-oai marked this pull request as ready for review March 27, 2026 16:04
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