fix(audio): reframe send path to channel frame_ms; pin codec to 48 kHz
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, voice.md §3) and the server enforces it unclamped. on_capture_frame handed the engine's 960-sample frame straight to an encoder configured for the channel's window: frame_ms > 20 was silently ignored, and frame_ms < 20 broke entirely (receiver sized its decode buffer too small -> OPUS_BUFFER_TOO_SMALL -> dead audio). Affected the hardware mic and vc_stream_feed_pcm alike. Reframe each captured/fed block to ls.frame_samples via a per-LocalStream accumulator (pre-sized at announce, no RT-thread alloc) before encode_and_send_frame; the 20 ms case stays a zero-copy fast path. Also pin the codec to 48 kHz in opus_params_from_audio_config — it was honoring a non-48k effective sample_rate against a 48 kHz PCM clock. New ctest frame_ms_reframe covers 40 ms (accumulate) and 10 ms (split) feed->encode->relay->decode->sink round trips. ctest --preset dev 25/25. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -106,6 +106,11 @@ Guidance baked into defaults / docs:
|
||||
- **Frame size: 20 ms default.** Smaller (10 ms) lowers latency at the cost of more
|
||||
per-packet overhead and CPU; larger (40/60 ms) improves efficiency and loss resilience at
|
||||
the cost of latency. Expose it per channel for "low-latency talk" vs "stable music" rooms.
|
||||
The capture engine runs on a fixed 48 kHz / 20 ms clock (960-sample frames), so the send
|
||||
path **reframes** each captured/fed block to the channel's `frame_ms` before encoding
|
||||
(accumulating two 960-frames for a 40 ms channel, splitting each into two 480-frames for a
|
||||
10 ms channel, etc.). This keeps the hardware/`vc_stream_feed_pcm` contract a single 48 kHz
|
||||
clock regardless of the channel's window — see `vc_client::on_capture_frame`.
|
||||
- **Mode/bitrate:** speech channels → `MONO`, `VOIP`, 24–32 kbps, DTX on, FEC on.
|
||||
Music/screen-audio channels → `STEREO`, `AUDIO`, 96–128 kbps, DTX off, FEC optional.
|
||||
- **`application`:** `VOIP` for talk, `AUDIO` for music/screen-share, `LOWDELAY` for
|
||||
|
||||
Reference in New Issue
Block a user