From 4a093e3f77b775a3a2fc6962b9c1b0c905f41b92 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Mon, 11 Aug 2025 13:03:57 +0100 Subject: [PATCH] Implement music attenuation --- MarathonRecomp/app.cpp | 3 +++ MarathonRecomp/patches/audio_patches.cpp | 30 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/MarathonRecomp/app.cpp b/MarathonRecomp/app.cpp index 857359be1..f7e277a8f 100644 --- a/MarathonRecomp/app.cpp +++ b/MarathonRecomp/app.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,8 @@ PPC_FUNC(sub_825EA610) // Allow variable FPS when config is not 60 FPS. App::s_pApp->m_pDoc->m_VFrame = Config::FPS != 60; + AudioPatches::Update(App::s_deltaTime); + __imp__sub_825EA610(ctx, base); } diff --git a/MarathonRecomp/patches/audio_patches.cpp b/MarathonRecomp/patches/audio_patches.cpp index d25fa1f57..923871ace 100644 --- a/MarathonRecomp/patches/audio_patches.cpp +++ b/MarathonRecomp/patches/audio_patches.cpp @@ -1,8 +1,9 @@ -#include +#include #include #include #include #include +#include int AudioPatches::m_isAttenuationSupported = -1; @@ -22,5 +23,28 @@ bool AudioPatches::CanAttenuate() #endif } -// TODO (Hyper): implement music attenuation. -void AudioPatches::Update(float deltaTime) {} +void AudioPatches::Update(float deltaTime) +{ + auto pAudioEngine = Sonicteam::AudioEngineXenon::GetInstance(); + + if (!pAudioEngine) + return; + + if (Config::MusicAttenuation && CanAttenuate()) + { + auto time = 1.0f - expf(2.5f * -deltaTime); + + if (os::media::IsExternalMediaPlaying()) + { + pAudioEngine->m_MusicVolume = std::lerp(pAudioEngine->m_MusicVolume, 0.0f, time); + } + else + { + pAudioEngine->m_MusicVolume = std::lerp(pAudioEngine->m_MusicVolume, Config::MusicVolume, time); + } + } + else + { + pAudioEngine->m_MusicVolume = Config::MusicVolume; + } +}