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:
parent
3b95df9e9c
commit
69d108b090
11 changed files with 777 additions and 97 deletions
|
|
@ -1,4 +1,5 @@
|
|||
mod capture;
|
||||
mod effects;
|
||||
mod media;
|
||||
pub use media::MediaMixer;
|
||||
mod playback;
|
||||
|
|
@ -12,6 +13,7 @@ use tracing::info;
|
|||
|
||||
use crate::audio::{
|
||||
AudioSync, EncodedFrame, IncomingVoice, PipelineConfig, config, devices,
|
||||
diagnostics::{AudioIssue, AudioStage, AudioStats, Diagnostics},
|
||||
processing::TransmitGate,
|
||||
};
|
||||
|
||||
|
|
@ -22,6 +24,8 @@ pub struct AudioPipeline {
|
|||
encoded_rx: Receiver<EncodedFrame>,
|
||||
microphone_tap: media::MicrophoneTap,
|
||||
media_mixer: MediaMixer,
|
||||
effects: effects::EffectQueue,
|
||||
diagnostics: Arc<Diagnostics>,
|
||||
voice_tx: Sender<IncomingVoice>,
|
||||
_encoded_tx: Sender<EncodedFrame>,
|
||||
gate: Arc<Mutex<TransmitGate>>,
|
||||
|
|
@ -40,6 +44,7 @@ impl Drop for AudioPipeline {
|
|||
self.stopped.store(true, Ordering::Release);
|
||||
self.microphone_tap.enable(false);
|
||||
self.media_mixer.clear();
|
||||
self.effects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +59,27 @@ impl AudioPipeline {
|
|||
self.media_mixer.clone()
|
||||
}
|
||||
|
||||
/// Plays a short notification (mono, 48 kHz, volume already applied) through the open
|
||||
/// playback stream without touching the voice path.
|
||||
pub fn play_effect(&self, mono_48k: &[f32]) {
|
||||
self.effects.push(mono_48k);
|
||||
}
|
||||
|
||||
/// Problems raised by the capture and playback threads since the last call.
|
||||
pub fn take_issues(&self) -> Vec<AudioIssue> {
|
||||
self.diagnostics.take_issues()
|
||||
}
|
||||
|
||||
/// True when neither the microphone nor the output could be used.
|
||||
pub fn is_dead(&self) -> bool {
|
||||
self.diagnostics.all_failed()
|
||||
}
|
||||
|
||||
/// Signal counters for support logs.
|
||||
pub fn stats(&self) -> AudioStats {
|
||||
self.diagnostics.snapshot()
|
||||
}
|
||||
|
||||
pub fn poll_encoded(&self) -> Option<EncodedFrame> {
|
||||
self.encoded_rx.try_recv().ok()
|
||||
}
|
||||
|
|
@ -124,6 +150,11 @@ pub fn start(cfg: PipelineConfig) -> anyhow::Result<AudioPipeline> {
|
|||
let tap_capture = microphone_tap.clone();
|
||||
let media_mixer = MediaMixer::new(out_cfg.sample_rate);
|
||||
let mixer_playback = media_mixer.clone();
|
||||
let effects = effects::EffectQueue::new(out_cfg.sample_rate);
|
||||
let effects_playback = effects.clone();
|
||||
let diagnostics = Arc::new(Diagnostics::default());
|
||||
let diagnostics_capture = diagnostics.clone();
|
||||
let diagnostics_playback = diagnostics.clone();
|
||||
|
||||
let (encoded_tx, encoded_rx) = mpsc::channel::<EncodedFrame>();
|
||||
let (voice_tx, voice_rx) = mpsc::channel::<IncomingVoice>();
|
||||
|
|
@ -162,8 +193,9 @@ pub fn start(cfg: PipelineConfig) -> anyhow::Result<AudioPipeline> {
|
|||
local_speaking_cap,
|
||||
capture_stopped,
|
||||
tap_capture,
|
||||
diagnostics_capture.clone(),
|
||||
) {
|
||||
tracing::error!("capture: {e}");
|
||||
diagnostics_capture.report(AudioStage::Capture, true, format!("{e:#}"));
|
||||
}
|
||||
});
|
||||
std::thread::spawn(move || {
|
||||
|
|
@ -175,8 +207,10 @@ pub fn start(cfg: PipelineConfig) -> anyhow::Result<AudioPipeline> {
|
|||
jitter_play,
|
||||
last_remote_voice_play,
|
||||
mixer_playback,
|
||||
effects_playback,
|
||||
diagnostics_playback.clone(),
|
||||
) {
|
||||
tracing::error!("playback: {e}");
|
||||
diagnostics_playback.report(AudioStage::Playback, true, format!("{e:#}"));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -185,6 +219,8 @@ pub fn start(cfg: PipelineConfig) -> anyhow::Result<AudioPipeline> {
|
|||
encoded_rx,
|
||||
microphone_tap,
|
||||
media_mixer,
|
||||
effects,
|
||||
diagnostics,
|
||||
voice_tx,
|
||||
_encoded_tx: encoded_tx,
|
||||
gate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue