feat: implement 3-state DAC badge and hardware sample rate detection

Backend changes:
- Add audio_diagnostics module to read actual hardware sample rate from /proc/asound
- New command get_hardware_audio_status() parses hw_params for real-time monitoring
- Add glob dependency for file pattern matching

Frontend (AudioOutputBadges):
- Implement 3-state DAC badge system:
  - Green: DAC passthrough working correctly (rates match)
  - Yellow: DAC passthrough ON but resampling detected (warning)
  - Gray: DAC passthrough OFF (intentionally disabled)
- Dynamic tooltips showing actual hardware sample rate
- Compare file sample rate vs hardware sample rate
- Increase tooltip z-index to 9999 to prevent occlusion issues
- Add pointer-events: none to tooltip to prevent interaction issues

Frontend (SettingsView):
- Replace hardcoded "192 kHz" with dynamic hardware sample rate
- Load and display actual hardware audio status
- Show format details (e.g., S32_LE) when available
- Display "No active playback" when no audio is playing
- Add muted styling for inactive state

Frontend (QualityBadge):
- Add native tooltip showing tier and format
- Add cursor: help to indicate interactivity

i18n:
- Add "noActivePlayback" translations (EN/ES)

This allows users to verify bit-perfect playback is working and detect
resampling issues that would compromise audio quality.
This commit is contained in:
vicrodh committed 2026-01-16 21:14:22 -06:00
1 parent 09881856d0
commit c810663c6f
9 files changed
+202 -14

No files matched your search

@@ -0,0 +1,73 @@
//! Audio diagnostics commands for detecting actual hardware sample rate
use std::fs;
/// Hardware audio status
#[derive(Debug, Clone, serde::Serialize)]
pub struct HardwareAudioStatus {
/// Actual sample rate being used by hardware (Hz)
pub hardware_sample_rate: Option<u32>,
/// Audio format (e.g., "S32_LE")
pub hardware_format: Option<String>,
/// Whether hardware is currently active
pub is_active: bool,
}
/// Get actual hardware audio status by reading /proc/asound
#[tauri::command]
pub fn get_hardware_audio_status() -> Result<HardwareAudioStatus, String> {
// Read all hw_params files from /proc/asound
let proc_pattern = "/proc/asound/card*/pcm*/sub*/hw_params";
// Use glob to find all matching files
let paths = glob::glob(proc_pattern)
.map_err(|e| format!("Failed to glob hw_params: {}", e))?;
for path in paths.flatten() {
if let Ok(contents) = fs::read_to_string(&path) {
// Parse the hw_params file
let mut sample_rate: Option<u32> = None;
let mut format: Option<String> = None;
for line in contents.lines() {
let line = line.trim();
// Parse rate line: "rate: 192000 (192000/1)"
if line.starts_with("rate:") {
if let Some(rate_str) = line.split_whitespace().nth(1) {
sample_rate = rate_str.parse().ok();
}
}
// Parse format line: "format: S32_LE"
if line.starts_with("format:") {
if let Some(fmt) = line.split_whitespace().nth(1) {
format = Some(fmt.to_string());
}
}
}
// If we found both, return it
if sample_rate.is_some() {
log::info!(
"Hardware audio status: {}Hz, format: {:?}",
sample_rate.unwrap_or(0),
format
);
return Ok(HardwareAudioStatus {
hardware_sample_rate: sample_rate,
hardware_format: format,
is_active: true,
});
}
}
}
// No active hardware found
Ok(HardwareAudioStatus {
hardware_sample_rate: None,
hardware_format: None,
is_active: false,
})
}
+2
View File
@@ -2,6 +2,7 @@
//!
//! Exposes backend functionality to the frontend via IPC
pub mod audio_diagnostics;
pub mod auth;
pub mod cache;
pub mod favorites;
@@ -14,6 +15,7 @@ pub mod queue;
pub mod search;
pub mod share;
pub use audio_diagnostics::*;
pub use auth::*;
pub use cache::*;
pub use favorites::*;