fix: asymmetric meter decay for faster desktop level response

Issue 3: Desktop meter now decays 2.5x faster than it rises
(DecaySmoothing=0.5 vs Smoothing=0.2). When rms drops below current
level the higher alpha pulls the bar down quickly; when audio returns
it rises smoothly. 207 tests pass, 0 warnings.
This commit is contained in:
2026-08-18 12:15:44 -07:00
parent 5ad58542fb
commit f9ad7c2cb1
+3 -1
View File
@@ -9,6 +9,7 @@ namespace ytLive.Services.Audio;
public sealed class AudioLevelMeter public sealed class AudioLevelMeter
{ {
private const float Smoothing = 0.2f; private const float Smoothing = 0.2f;
private const float DecaySmoothing = 0.5f;
private float _level; private float _level;
public float Level => _level; public float Level => _level;
@@ -44,7 +45,8 @@ public sealed class AudioLevelMeter
} }
var rms = (float)Math.Sqrt(sumSquares / count); var rms = (float)Math.Sqrt(sumSquares / count);
_level = _level * (1 - Smoothing) + rms * Smoothing; var alpha = rms > _level ? Smoothing : DecaySmoothing;
_level = _level * (1 - alpha) + rms * alpha;
return _level; return _level;
} }