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:
@@ -9,6 +9,7 @@ namespace ytLive.Services.Audio;
|
||||
public sealed class AudioLevelMeter
|
||||
{
|
||||
private const float Smoothing = 0.2f;
|
||||
private const float DecaySmoothing = 0.5f;
|
||||
private float _level;
|
||||
|
||||
public float Level => _level;
|
||||
@@ -44,7 +45,8 @@ public sealed class AudioLevelMeter
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user