feat(audio): channel sample_rate caps Opus bandwidth (narrowband/wideband)
Some checks failed
Build Linux Binaries / linux/amd64 (push) Has been cancelled
Build Linux Binaries / linux/arm64 (push) Has been cancelled

The per-channel sample_rate field was inert after pinning the codec to
48 kHz. Make it meaningful without changing the 48 kHz clock: carry it as
OpusParams::max_bandwidth_hz and apply OPUS_SET_MAX_BANDWIDTH in
OpusEncoder::init (8000->narrowband, 16000->wideband, 24000->super-wideband,
48000->full). A low-bitrate room can now shed out-of-band content while
every endpoint keeps a single 48 kHz clock.

Make sample_rate channel-authoritative on the server: conn_session no
longer overrides effective sample_rate with the client's always-48000
request (it now behaves like frame_ms/mode). vc_get_stream_audio_config
reports the channel's configured rate for own streams too.

New ctest channel_samplerate: a 7 kHz tone is attenuated ~1000x on an
8 kHz (narrowband) channel vs a 48 kHz (full-band) channel, proving the cap
is in effect. ctest --preset dev 26/26.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 16:56:49 +02:00
parent a460009a2f
commit e155e342f4
9 changed files with 379 additions and 15 deletions

View File

@@ -442,7 +442,19 @@ up instantly. Newest status at the top.
## Recent completed work
All items below are `[x]` done; `ctest --preset dev` 25/25 on Windows after all.
All items below are `[x]` done; `ctest --preset dev` 26/26 on Windows after all.
- **Per-channel sample_rate as a bandwidth cap** (2026-06-22): the channel `sample_rate` field
was inert (the codec is pinned to 48 kHz). Made it meaningful without changing the 48 kHz
clock: it's carried as `OpusParams::max_bandwidth_hz` and applied via `OPUS_SET_MAX_BANDWIDTH`
in `OpusEncoder::init` (8000→narrowband … 48000→full). Made it **channel-authoritative** on
the server (`conn_session.cpp` no longer overrides effective `sample_rate` with the client's
always-48000 request — like `frame_ms`/`mode`). `vc_get_stream_audio_config` now reports the
channel's configured rate for own streams too. New ctest `channel_samplerate`: a 7 kHz tone is
attenuated ~1000× on an 8 kHz channel vs a 48 kHz channel. Files: `opus_codec.{h,cpp}`,
`client.cpp`, `server/src/conn_session.cpp`, `docs/voice.md`, `tests/test_channel_samplerate.cpp`,
`tests/CMakeLists.txt`. (Future: a true non-48k stack is possible but unnecessary — 48 kHz is
what nearly all hard/software runs at; the bandwidth cap covers the narrowband use case.)
- **Non-20ms channel frame_ms fix** (2026-06-22): the AudioEngine capture clock is fixed at
48 kHz / 20 ms (960-sample frames), but a channel may set any Opus `frame_ms` (2.5…60 ms,