Skip to content

feat: add Opus codec behind an opus feature#30

Merged
wavekat-eason merged 2 commits into
mainfrom
feat/opus-codec
Jul 3, 2026
Merged

feat: add Opus codec behind an opus feature#30
wavekat-eason merged 2 commits into
mainfrom
feat/opus-codec

Conversation

@wavekat-eason

Copy link
Copy Markdown
Contributor

Summary

Adds Opus to wavekat-core behind an off-by-default opus feature, plus a codec-agnostic Encoder / Decoder seam so consumers can hold "a codec" without naming one. This is the wavekat-core half of the WaveKat Voice Opus-wideband work (voice doc 45); it pairs with wavekat-sip's Opus SDP change and lands first in the publish order.

What changes

  • codec::opus — libopus via the opus crate (the maintained binding, not the abandoned audiopus), wrapping the same vendored audiopus_sys libopus. Encode/decode at the negotiated PCM rate, in-band FEC, and PLC concealment for lost frames.
  • codec::{Encoder, Decoder} seam — a small trait pair the consumer can hold generically; G.711 (already in the crate) and Opus both satisfy it, so the SIP/voice layers pick a codec at negotiation time without branching on the concrete type everywhere.
  • Feature-gatedopus is off by default, so the default build and every existing consumer are unaffected (no new C dependency unless you ask for it).

Test plan

  • cargo test -p wavekat-core --features opus — 53 tests + 3 doctests pass. Coverage includes:
    • encode→decode round-trip preserves signal energy,
    • FEC actually recovers a lost frame (recovered frame beats the PLC baseline, proving recovery engages rather than silently falling back to concealment),
    • PLC concealment produces a plausible frame after loss.
  • cargo fmt --all -- --check clean.
  • Default-feature build unchanged (feature is additive and off by default).

Notes for review

  • FEC requires set_packet_loss_perc(...) in addition to set_inband_fec(true) — setting the flag alone doesn't actually emit redundant data. That's covered by the FEC recovery test.
  • Opus RTP runs on the 48 kHz wire clock even for 16 kHz audio (RFC 7587); the clock/timestamp handling lives in the wavekat-sip / voice layers, not here.
  • Draft pending the cross-repo publish sequence: this publishes first (new minor with the opus feature), then wavekat-sip 0.2.0, then WaveKat Voice drops its local [patch.crates-io] and pins the released versions. Also want the Windows MSVC audiopus_sys cmake build confirmed green in CI before undrafting.

🤖 Generated with Claude Code

wavekat-eason and others added 2 commits July 2, 2026 21:02
Wideband voice profile per wavekat-voice doc 45: 16 kHz mono VoIP at
28 kbps, in-band FEC enabled with nonzero expected loss (without which
libopus embeds no redundancy), DTX off. OpusDecoder exposes the two
consumer-driven loss-recovery calls — decode_fec (recover a lost frame
from the next packet) and conceal (PLC) — and sizes decode buffers for
the largest legal frame rather than assuming 20 ms.

Feature-gated because the opus crate pulls a vendored C libopus built
with cmake; the default build stays pure-Rust.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
One enum per direction dispatching to the stateless G.711 tables or a
stateful Opus coder, so a consumer's audio loops carry no codec
branches. The loss-recovery calls (recover_lost, conceal) are uniform:
Opus drives in-band FEC and PLC, G.711 deliberately appends nothing —
its historical loss behavior, silence by absence, is preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.42693% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/wavekat-core/src/codec/opus.rs 99.13% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@wavekat-eason wavekat-eason marked this pull request as ready for review July 3, 2026 07:14
@wavekat-eason wavekat-eason merged commit b4f1a17 into main Jul 3, 2026
3 checks passed
@wavekat-eason wavekat-eason deleted the feat/opus-codec branch July 3, 2026 07:14
@github-actions github-actions Bot mentioned this pull request Jul 3, 2026
wavekat-eason pushed a commit that referenced this pull request Jul 3, 2026
## 🤖 New release

* `wavekat-core`: 0.0.12 -> 0.0.13 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.0.13](v0.0.12...v0.0.13)
- 2026-07-03

### Added

- add Opus codec behind an opus feature
([#30](#30))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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