Files
qbz/src/lib/components/QualityBadge.svelte
T
vicrodh c810663c6f 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.
2026-01-16 21:14:22 -06:00

168 lines
3.8 KiB
Svelte

<script lang="ts">
interface Props {
quality?: string;
bitDepth?: number;
samplingRate?: number;
}
let {
quality = '',
bitDepth,
samplingRate
}: Props = $props();
// Determine quality tier
const tier = $derived.by(() => {
// Check bitDepth and samplingRate first
if (bitDepth && bitDepth >= 24 && samplingRate && samplingRate > 96) {
return 'max';
}
if (bitDepth && bitDepth >= 24) {
return 'hires';
}
if (bitDepth === 16 || (samplingRate && samplingRate >= 44.1 && samplingRate <= 48)) {
return 'cd';
}
// Check quality string
const q = quality.toLowerCase();
if (q.includes('mp3') || q.includes('320')) {
return 'lossy';
}
if (q.includes('hi-res') || q.includes('hires') || q.includes('24')) {
return 'hires';
}
if (q.includes('cd') || q.includes('flac') || q.includes('lossless') || q.includes('16')) {
return 'cd';
}
// Default fallback
if (samplingRate && samplingRate >= 44.1) {
return 'cd';
}
return 'cd'; // Default to CD instead of unknown
});
// Format the display text
const displayText = $derived.by(() => {
if (tier === 'max') {
const depth = bitDepth || 24;
const rate = samplingRate || 192;
return `${depth}-bit / ${rate} kHz`;
}
if (tier === 'hires') {
const depth = bitDepth || 24;
const rate = samplingRate || 96;
return `${depth}-bit / ${rate} kHz`;
}
if (tier === 'cd') {
const depth = bitDepth || 16;
const rate = samplingRate || 44.1;
return `${depth}-bit / ${rate} kHz`;
}
if (tier === 'lossy') {
return '320 kbps';
}
return '16-bit / 44.1 kHz';
});
const tierLabel = $derived.by(() => {
if (tier === 'max') return 'Hi-Res';
if (tier === 'hires') return 'Hi-Res';
if (tier === 'cd') return 'CD';
if (tier === 'lossy') return 'MP3';
return 'CD';
});
// Get icon path based on tier
const iconPath = $derived.by(() => {
if (tier === 'max' || tier === 'hires') return '/hi-res-gray.svg';
if (tier === 'cd') return '/cd.svg';
if (tier === 'lossy') return '/mp3.svg';
return '/cd.svg';
});
const isHiRes = $derived(tier === 'max' || tier === 'hires');
</script>
<div class="quality-badge" title="{tierLabel}: {displayText}">
<!-- Icon -->
<img
src={iconPath}
alt={tierLabel}
class="badge-icon"
class:hires={isHiRes}
/>
<!-- Text -->
<div class="badge-text">
<span class="tier-label">{tierLabel}</span>
<span class="quality-info">{displayText}</span>
</div>
</div>
<style>
.quality-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 10px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.06);
border: 1px solid rgba(255, 255, 255, 0.1);
cursor: help;
}
[data-theme="light"] .quality-badge {
background: rgba(40, 42, 54, 0.85);
border: 1px solid rgba(40, 42, 54, 0.95);
}
[data-theme="light"] .tier-label,
[data-theme="light"] .quality-info {
color: #ffffff;
}
[data-theme="light"] .badge-icon {
filter: invert(1) brightness(1.5);
}
[data-theme="light"] .badge-icon.hires {
filter: brightness(1.2);
}
.badge-icon {
width: 16px;
height: 16px;
object-fit: contain;
filter: invert(1) brightness(0.7);
}
.badge-icon.hires {
width: 24px;
height: 24px;
filter: none; /* Hi-Res logo keeps original colors */
}
.badge-text {
display: flex;
flex-direction: column;
line-height: 1.2;
}
.tier-label {
font-size: 8px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
color: #b0b0b0;
}
.quality-info {
font-size: 9px;
font-weight: 500;
color: #999999;
}
</style>