Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[env]
# audiopus_sys (libopus, behind the `opus` feature) ships a CMakeLists that
# CMake 4 rejects without this.
CMAKE_POLICY_VERSION_MINIMUM = "3.5"
8 changes: 5 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Provide the common audio primitives so that all WaveKat crates speak the same la
- Shared error types (only when genuinely shared)
- Format normalisation operations on `AudioFrame` (i16→f32, sample-rate conversion) — gated behind optional features
- The `AudioSource` / `AudioSink` traits — the producer/consumer seam any audio pipeline composes against. Concrete impls (cpal mic, AI agent, RTP receive) live in their consuming crates; the trait shape lives here so they all interoperate.
- Telephony codecs (`codec::g711`: PCMU + PCMA). Codecs are consumer-layer for `wavekat-sip` (which stays codec-agnostic), but multiple downstream crates need them — keep one canonical implementation here.
- Telephony codecs (`codec::g711`: PCMU + PCMA; `codec::g722`: wideband, pure Rust). Codecs are consumer-layer for `wavekat-sip` (which stays codec-agnostic), but multiple downstream crates need them — keep one canonical implementation here.

## What Does NOT Belong Here

Expand Down Expand Up @@ -63,9 +63,11 @@ wavekat-core/
│ │ ├── lib.rs # public API, re-exports
│ │ ├── audio.rs # AudioFrame, IntoSamples, resample, wav
│ │ ├── audio_io.rs # AudioSource / AudioSink traits
│ │ ├── codec/ # telephony codecs (g711 today)
│ │ ├── codec/ # telephony codecs
│ │ │ ├── mod.rs
│ │ │ └── g711.rs # PCMU + PCMA encode/decode, G711Codec enum
│ │ │ ├── g711.rs # PCMU + PCMA encode/decode, G711Codec enum
│ │ │ ├── g722.rs # G.722 wideband encoder/decoder (64 kbit/s)
│ │ │ └── opus.rs # Opus via libopus (feature `opus`)
│ │ └── error.rs # CoreError
│ └── Cargo.toml
├── docs/ # design documents
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Shared types for the [WaveKat](https://wavekat.com) audio processing ecosystem.
| `IntoSamples` | Trait for transparent sample format conversion |
| `AudioSource` / `AudioSink` | Async producer/consumer traits — the seam every WaveKat audio pipeline composes against |
| `codec::g711` | G.711 μ-law (PCMU) and A-law (PCMA) — telephony codecs for SIP/RTP |
| `codec::g722` | G.722 — wideband (16 kHz) telephony codec at 64 kbit/s, pure Rust |

## Quick Start

Expand Down Expand Up @@ -124,6 +125,38 @@ codec.decode(&bytes, &mut decoded);
assert_eq!(G711_SAMPLE_RATE, 8000);
```

## G.722 Wideband Codec

G.722 carries 16 kHz speech in the same 64 kbit/s as G.711 — the "HD
voice" codec most SIP providers and desk phones speak. Pure Rust, no
feature flag. Two PCM samples ↔ one byte; a 20 ms RTP frame is
320 samples / 160 bytes. The coder is stateful: keep one encoder and
one decoder per stream.

```rust
use wavekat_core::codec::g722::{
G722Decoder, G722Encoder, G722_FRAME_BYTES, G722_FRAME_SAMPLES,
G722_RTP_CLOCK_RATE,
};

let mut encoder = G722Encoder::new();
let mut decoder = G722Decoder::new();

// One 20 ms frame at 16 kHz in, 160 bytes out.
let pcm = vec![0i16; G722_FRAME_SAMPLES];
let mut bytes = Vec::new();
encoder.encode(&pcm, &mut bytes).unwrap();
assert_eq!(bytes.len(), G722_FRAME_BYTES);

let mut decoded = Vec::new();
decoder.decode(&bytes, &mut decoded);
assert_eq!(decoded.len(), G722_FRAME_SAMPLES);

// RFC 3551 quirk: the RTP clock is 8000 although the audio is 16 kHz,
// so the RTP timestamp advances by 160 per frame.
assert_eq!(G722_RTP_CLOCK_RATE, 8000);
```

## Optional Features

### `wav`
Expand Down
Loading
Loading