Files
OpenPlexusX/VibranceHud/Audio/AudioLimiter.cs
T
2026-11-24 23:40:08 +03:00

20 lines
588 B
C#

using System;
namespace VibranceHud.Audio;
public static class AudioLimiter
{
public const float MinVolume = 0.05f;
public const float DefaultAttack = 0.5f;
public const float DefaultRelease = 0.3f;
public static float NextVolume(float peak, float threshold, float currentVolume, float maxVolume, float attack = 0.5f, float release = 0.3f)
{
float num = ((peak > 0.0001f) ? MathF.Min(maxVolume, threshold / peak) : maxVolume);
float num2 = ((num < currentVolume) ? attack : release);
return Math.Clamp(currentVolume + (num - currentVolume) * num2, 0.05f, maxVolume);
}
}