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

@ -1,6 +1,6 @@
use std::collections::HashMap;
use vnox_client::audio::{IncomingVoice, PipelineConfig};
use vnox_client::audio::{AudioStage, IncomingVoice, PipelineConfig};
use vnox_client::net::{ChatMsg, NetCommand, NetEvent, NetHandle, PresenceInfo};
use crate::ui::state::{ChatMessage, ConnState, UiState, VoiceUiState};
@ -304,11 +304,13 @@ pub fn process_net_events(state: &mut AppState) {
// Capture/playback runs independently from incoming control packets.
sync_voice_audio(state);
flush_encoded_voice(state);
report_audio_issues(state);
log_audio_stats(state);
if let Some(pipeline) = state.audio.as_ref() {
pipeline.sync_controls(vnox_client::audio::AudioSync {
mic_enabled: state.ui.mic_enabled && !state.ui.deafen,
vad_mode: state.ui.vad_mode,
vad_threshold: 40.0,
vad_threshold: 15.0,
input_volume: 100.0,
ptt_held: state.ui.ptt_held,
output_volume: if state.ui.deafen {
@ -950,3 +952,66 @@ pub fn flush_encoded_voice(state: &mut AppState) {
});
}
}
/// Surfaces capture and playback failures instead of leaving a "connected" room that is mute.
fn report_audio_issues(state: &mut AppState) {
let Some(pipeline) = state.audio.as_ref() else {
return;
};
let issues = pipeline.take_issues();
let dead = pipeline.is_dead();
for issue in issues {
let message = match issue.stage {
AudioStage::Capture => {
crate::ui::i18n::Message::with("Microphone error: {e}", vec![("e", issue.message)])
}
AudioStage::Playback => crate::ui::i18n::Message::with(
"Audio output error: {e}",
vec![("e", issue.message)],
),
};
state.ui.status_msg = Some(message);
}
if dead {
let reason = state
.ui
.status_msg
.as_ref()
.map(ToString::to_string)
.unwrap_or_default();
state.audio = None;
state.voice_channel = None;
state.ui.voice = VoiceUiState::Error(reason);
}
}
/// Logs signal counters every ten seconds while a voice room is active, so a bug report can
/// tell whether the signal stopped at the microphone, the network or the speaker.
fn log_audio_stats(state: &AppState) {
thread_local! {
static LAST: std::cell::Cell<Option<std::time::Instant>> = const { std::cell::Cell::new(None) };
}
let due = LAST.with(|last| {
let due = last
.get()
.is_none_or(|t| t.elapsed() >= std::time::Duration::from_secs(10));
if due {
last.set(Some(std::time::Instant::now()));
}
due
});
if !due {
return;
}
if let Some(pipeline) = state.audio.as_ref() {
let stats = pipeline.stats();
tracing::info!(
captured = stats.captured_frames,
sent = stats.transmitted_frames,
received = stats.received_packets,
decoded = stats.decoded_frames,
input_peak = stats.input_peak,
"voice audio stats"
);
}
}