Add public encoder API#117
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
==========================================
- Coverage 82.88% 82.11% -0.78%
==========================================
Files 26 27 +1
Lines 5540 5703 +163
==========================================
+ Hits 4592 4683 +91
- Misses 726 791 +65
- Partials 222 229 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a first public Opus encoder API at the package root, implemented as a thin wrapper around the internal CELT encoder, to complement the existing public decoder API and address #34 (PCM → Opus encoding support).
Changes:
- Introduces
EncoderwithNewEncoder,Init,Encode(S16LE), andEncodeFloat32for 48 kHz mono 20 ms CELT-only packets. - Adds encoder controls
SetBitrateandSetComplexityplus new internal sentinel errors for validation. - Adds round-trip tests that encode then decode back using the existing decoder.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| errors.go | Adds new encoder-related sentinel errors (bitrate/complexity/input/frame validation). |
| encoder.go | Implements the public encoder wrapper API around the internal CELT encoder and constructs a valid Opus packet (TOC + one frame). |
| encoder_test.go | Adds round-trip and validation tests for the new encoder API. |
Comments suppressed due to low confidence (1)
encoder.go:90
- Doc comment says "CELT encoder slice"; this appears to be a typo/incorrect term (likely meant "encoder implementation" or "API surface"). Consider adjusting wording to avoid confusion.
// SetComplexity stores the requested encoder complexity.
//
// The initial CELT encoder slice does not yet vary behavior by complexity,
// but the public API accepts the standard Opus 0..10 range for future
// expansion.
func (e *Encoder) SetComplexity(complexity int) error {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Adds the public Opus encoder API as a wrapper around the internal CELT encoder.
Exposes NewEncoder, Encode (S16LE), EncodeFloat32, SetBitrate, and
SetComplexity at the package root, mirroring the existing Decoder API.
Current scope: 48 kHz, mono, 20 ms CELT-only frames. Stereo, transient
detection, and SILK encoding will land in follow-up PRs.
Round-trip tested against the existing decoder.
Reference issue
Fixes #34