From 7caf9639e0170200c72f4973dc937019bd80ba5d Mon Sep 17 00:00:00 2001 From: Amun Date: Wed, 8 Oct 2025 21:34:43 +0300 Subject: [PATCH] Audio engine: small bug(see desc) The music wouldn't play if the sound was 0 and you changed the song because it would be stopped by the fade during the next frame. --- src/AudioLib/MaSoundInstance.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/AudioLib/MaSoundInstance.cpp b/src/AudioLib/MaSoundInstance.cpp index 3ecee20..bc5f3b3 100644 --- a/src/AudioLib/MaSoundInstance.cpp +++ b/src/AudioLib/MaSoundInstance.cpp @@ -140,11 +140,12 @@ void MaSoundInstance::Config3D(bool toggle, float minDist, float maxDist) void MaSoundInstance::Fade(float toVolume, float secDurationFromMinMax) { - toVolume = std::clamp(toVolume, 0.0f, 1.0f); - m_FadeTargetVolume = toVolume; - - float rate = 1.0f / CS_CLIENT_FPS / secDurationFromMinMax; - m_FadeRatePerFrame = GetVolume() > toVolume ? -rate : rate; + m_FadeTargetVolume = std::clamp(toVolume, 0.0f, 1.0f); + if (m_FadeTargetVolume != GetVolume()) + { + const float rate = 1.0f / CS_CLIENT_FPS / secDurationFromMinMax; + m_FadeRatePerFrame = GetVolume() > m_FadeTargetVolume ? -rate : rate; + } } void MaSoundInstance::StopFading()