fix(client): surface audio failures and use adaptive voice activation

Capture and playback failures were only written to the log on detached
threads, so a microphone or output that could not be opened still showed a
connected voice room with no sound. Threads now report into a shared
diagnostics sink that the UI polls: errors appear in the status bar, a
room with neither working half is marked failed, and signal counters
(captured, sent, received, decoded, input peak) are logged every ten
seconds. A microphone that delivers only digital silence is reported, and
rejected voice datagrams are logged instead of dropped silently.

Voice activation now tracks the background noise floor and opens just
above it, capped by a much lower default ceiling; the old fixed threshold
(about -26 dBFS) rarely opened for normal speech. Stream configuration only
accepts f32 formats and says so when a device offers nothing else.

Playback gains a mixing queue for short notification effects.
This commit is contained in:
Loki 2026-10-25 00:18:03 +02:00
parent 3b95df9e9c
commit 69d108b090
Signed by: boba
GPG key ID: 253067914055423B
11 changed files with 777 additions and 97 deletions

View file

@ -31,6 +31,7 @@ impl State {
let events = event_tx.clone();
let receiver = tokio::spawn(async move {
let mut bytes = vec![0u8; voice::MAX_DATAGRAM + 1];
let mut rejected: u64 = 0;
while let Ok((length, source)) = worker_udp.recv_from(&mut bytes).await {
let event = {
let Ok(mut state) = worker_state.lock() else {
@ -40,12 +41,29 @@ impl State {
continue;
};
if source != state.endpoint {
// A relay answering from another address looks exactly like silence.
rejected += 1;
if rejected == 1 || rejected % 500 == 0 {
tracing::warn!(
%source,
expected = %state.endpoint,
rejected,
"voice datagram from an unexpected address ignored"
);
}
continue;
}
let Ok((sequence, frame)) = voice::decode(&state.credentials, &bytes[..length])
else {
continue;
};
let (sequence, frame) =
match voice::decode(&state.credentials, &bytes[..length]) {
Ok(decoded) => decoded,
Err(error) => {
rejected += 1;
if rejected == 1 || rejected % 500 == 0 {
tracing::warn!(%error, rejected, "voice datagram rejected");
}
continue;
}
};
if !state.replay.accept(sequence) || frame.opus.is_empty() {
continue;
}