Skip to content

Commit 5097a9e

Browse files
authored
Implement music attenuation (#89)
1 parent c8fd07c commit 5097a9e

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

MarathonRecomp/app.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <kernel/function.h>
55
#include <os/process.h>
66
#include <os/logger.h>
7+
#include <patches/audio_patches.h>
78
#include <ui/game_window.h>
89
#include <user/config.h>
910
#include <user/paths.h>
@@ -98,6 +99,8 @@ PPC_FUNC(sub_825EA610)
9899
// Allow variable FPS when config is not 60 FPS.
99100
App::s_pApp->m_pDoc->m_VFrame = Config::FPS != 60;
100101

102+
AudioPatches::Update(App::s_deltaTime);
103+
101104
__imp__sub_825EA610(ctx, base);
102105
}
103106

MarathonRecomp/patches/audio_patches.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include <user/config.h>
1+
#include <api/Marathon.h>
22
#include <kernel/function.h>
33
#include <os/media.h>
44
#include <os/version.h>
55
#include <patches/audio_patches.h>
6+
#include <user/config.h>
67

78
int AudioPatches::m_isAttenuationSupported = -1;
89

@@ -22,5 +23,28 @@ bool AudioPatches::CanAttenuate()
2223
#endif
2324
}
2425

25-
// TODO (Hyper): implement music attenuation.
26-
void AudioPatches::Update(float deltaTime) {}
26+
void AudioPatches::Update(float deltaTime)
27+
{
28+
auto pAudioEngine = Sonicteam::AudioEngineXenon::GetInstance();
29+
30+
if (!pAudioEngine)
31+
return;
32+
33+
if (Config::MusicAttenuation && CanAttenuate())
34+
{
35+
auto time = 1.0f - expf(2.5f * -deltaTime);
36+
37+
if (os::media::IsExternalMediaPlaying())
38+
{
39+
pAudioEngine->m_MusicVolume = std::lerp(pAudioEngine->m_MusicVolume, 0.0f, time);
40+
}
41+
else
42+
{
43+
pAudioEngine->m_MusicVolume = std::lerp(pAudioEngine->m_MusicVolume, Config::MusicVolume, time);
44+
}
45+
}
46+
else
47+
{
48+
pAudioEngine->m_MusicVolume = Config::MusicVolume;
49+
}
50+
}

0 commit comments

Comments
 (0)