Skip to content

Port the RFC SILK output resampler#93

Merged
zshang-oai merged 2 commits intomainfrom
codex/silk-output-resampling
Apr 8, 2026
Merged

Port the RFC SILK output resampler#93
zshang-oai merged 2 commits intomainfrom
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 83.33333% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.46%. Comparing base (914b0f4) to head (50484c7).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
internal/resample/silk/resampler.go 79.56% 26 Missing and 2 partials ⚠️
internal/resample/silk/down_fir.go 76.04% 23 Missing ⚠️
decoder.go 84.37% 12 Missing and 8 partials ⚠️
internal/resample/silk/fixed.go 71.42% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   79.02%   80.46%   +1.44%     
==========================================
  Files           8       13       +5     
  Lines        1535     1966     +431     
==========================================
+ Hits         1213     1582     +369     
- Misses        276      329      +53     
- Partials       46       55       +9     
Flag Coverage Δ
go 80.46% <83.33%> (+1.44%) ⬆️

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
@zshang-oai zshang-oai force-pushed the codex/silk-output-resampling branch from 469fda8 to 210651f Compare April 6, 2026 16:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the RFC 6716 decoder-side SILK output resampler into Go and updates the Opus decoder to produce PCM at a caller-configured output sample rate and channel count (instead of the previous naive upsample-by-repetition path).

Changes:

  • Add internal/resample/silk implementing the SILK decoder resampler (delay handling + per-ratio FIR/IIR paths) with fixture-based tests.
  • Update Decoder to accept a configured output format (NewDecoderWithOutput / Init) and resample SILK output accordingly.
  • Add DecodeToInt16 / DecodeToFloat32 helpers and adjust PCM conversion rounding/clamping behavior.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
decoder.go Stores requested output format, resamples SILK output to requested rate/channels, adds decode helpers.
errors.go Adds new public decoder validation/buffer errors.
decoder_test.go Adds tests for new constructor and decode helper behavior.
packet_test.go Updates empty-packet decode test for expanded return values.
internal/resample/silk/resampler.go Core resampler state, init, delay management, and float/int conversions.
internal/resample/silk/up2_hq.go 2x HQ upsampling path.
internal/resample/silk/iir_fir.go IIR/FIR upsample/interpolation path.
internal/resample/silk/down_fir.go Downsample FIR path.
internal/resample/silk/ar2.go AR2 helper used by downsampling.
internal/resample/silk/fixed.go Fixed-point math helpers used by resampler.
internal/resample/silk/rom.go Resampler coefficient ROM tables.
internal/resample/silk/resampler_test.go Impulse fixtures, chunking equivalence, and round-trip error bounds.
internal/bitdepth/bitdepth.go Adjusts float32→int16 quantization (round/clamp).
internal/bitdepth/bitdepth_test.go Updates expected byte output for new quantization.
internal/resample/resample.go Removes old naive repetition-based resampler implementation.
internal/resample/resample_test.go Removes tests for the deleted naive resampler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/resample/silk/resampler.go Outdated
Comment thread internal/resample/silk/iir_fir.go Outdated
Comment thread internal/resample/silk/down_fir.go Outdated
Comment thread decoder.go
Comment thread internal/resample/silk/resampler.go
@zshang-oai zshang-oai merged commit 3dd2256 into main Apr 8, 2026
19 checks passed
@zshang-oai zshang-oai deleted the codex/silk-output-resampling branch April 8, 2026 16:07
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.

3 participants