mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 04:41:39 +00:00
Implemented music volume attenuation for Windows 10+
This commit is contained in:
parent
a32a168f79
commit
0c5962ad02
4 changed files with 68 additions and 1 deletions
|
|
@ -27,6 +27,7 @@ public:
|
||||||
CONFIG_DEFINE_LOCALISED("Audio", float, SEVolume, 1.0f);
|
CONFIG_DEFINE_LOCALISED("Audio", float, SEVolume, 1.0f);
|
||||||
CONFIG_DEFINE_ENUM_LOCALISED("Audio", EVoiceLanguage, VoiceLanguage, EVoiceLanguage::English);
|
CONFIG_DEFINE_ENUM_LOCALISED("Audio", EVoiceLanguage, VoiceLanguage, EVoiceLanguage::English);
|
||||||
CONFIG_DEFINE_LOCALISED("Audio", bool, Subtitles, true);
|
CONFIG_DEFINE_LOCALISED("Audio", bool, Subtitles, true);
|
||||||
|
CONFIG_DEFINE_LOCALISED("Audio", bool, MusicAttenuation, false);
|
||||||
CONFIG_DEFINE_LOCALISED("Audio", bool, WerehogBattleMusic, true);
|
CONFIG_DEFINE_LOCALISED("Audio", bool, WerehogBattleMusic, true);
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM("Video", EGraphicsAPI, GraphicsAPI, EGraphicsAPI::D3D12);
|
CONFIG_DEFINE_ENUM("Video", EGraphicsAPI, GraphicsAPI, EGraphicsAPI::D3D12);
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,16 @@ CONFIG_DEFINE_DESCRIPTION_LOCALE(SEVolume)
|
||||||
{ ELanguage::English, "Adjust the volume for sound effects." }
|
{ ELanguage::English, "Adjust the volume for sound effects." }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_LOCALE(MusicAttenuation)
|
||||||
|
{
|
||||||
|
{ ELanguage::English, "Music Attenuation" }
|
||||||
|
};
|
||||||
|
|
||||||
|
CONFIG_DEFINE_DESCRIPTION_LOCALE(MusicAttenuation)
|
||||||
|
{
|
||||||
|
{ ELanguage::English, "Fade out the game's music when external media is playing.\n\nRequires Windows 10 or later." }
|
||||||
|
};
|
||||||
|
|
||||||
CONFIG_DEFINE_LOCALE(VoiceLanguage)
|
CONFIG_DEFINE_LOCALE(VoiceLanguage)
|
||||||
{
|
{
|
||||||
{ ELanguage::English, "Voice Language" }
|
{ ELanguage::English, "Voice Language" }
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,42 @@
|
||||||
#include <kernel/function.h>
|
#include <kernel/function.h>
|
||||||
#include <patches/audio_patches.h>
|
#include <patches/audio_patches.h>
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
#include <winrt/Windows.Foundation.h>
|
||||||
|
#include <winrt/Windows.Media.Control.h>
|
||||||
|
|
||||||
|
using namespace winrt;
|
||||||
|
using namespace Windows::Foundation;
|
||||||
|
using namespace Windows::Media::Control;
|
||||||
|
|
||||||
|
GlobalSystemMediaTransportControlsSessionManager m_sessionManager = nullptr;
|
||||||
|
|
||||||
|
GlobalSystemMediaTransportControlsSessionManager GetSessionManager()
|
||||||
|
{
|
||||||
|
if (m_sessionManager)
|
||||||
|
return m_sessionManager;
|
||||||
|
|
||||||
|
init_apartment();
|
||||||
|
|
||||||
|
return m_sessionManager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalSystemMediaTransportControlsSession GetCurrentSession()
|
||||||
|
{
|
||||||
|
return GetSessionManager().GetCurrentSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsExternalAudioPlaying()
|
||||||
|
{
|
||||||
|
auto session = GetCurrentSession();
|
||||||
|
|
||||||
|
if (!session)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return session.GetPlaybackInfo().PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
be<float>* GetVolume(bool isMusic = true)
|
be<float>* GetVolume(bool isMusic = true)
|
||||||
{
|
{
|
||||||
auto ppUnkClass = (be<uint32_t>*)g_memory.Translate(0x83362FFC);
|
auto ppUnkClass = (be<uint32_t>*)g_memory.Translate(0x83362FFC);
|
||||||
|
|
@ -22,8 +58,27 @@ void audio_patches::Update(float deltaTime)
|
||||||
if (!pMusicVolume || !pSEVolume)
|
if (!pMusicVolume || !pSEVolume)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
if (Config::MusicAttenuation)
|
||||||
|
{
|
||||||
|
auto time = 1.0f - expf(2.5f * -deltaTime);
|
||||||
|
|
||||||
|
if (IsExternalAudioPlaying())
|
||||||
|
{
|
||||||
|
*pMusicVolume = std::lerp(*pMusicVolume, 0.0f, time);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*pMusicVolume = std::lerp(*pMusicVolume, Config::MusicVolume, time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
*pMusicVolume = Config::MusicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
*pSEVolume = Config::SEVolume;
|
*pSEVolume = Config::SEVolume;
|
||||||
*pMusicVolume = Config::MusicVolume;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stub volume setter.
|
// Stub volume setter.
|
||||||
|
|
|
||||||
|
|
@ -828,6 +828,7 @@ static void DrawConfigOptions()
|
||||||
DrawConfigOption(rowCount++, yOffset, &Config::SEVolume);
|
DrawConfigOption(rowCount++, yOffset, &Config::SEVolume);
|
||||||
DrawConfigOption(rowCount++, yOffset, &Config::VoiceLanguage);
|
DrawConfigOption(rowCount++, yOffset, &Config::VoiceLanguage);
|
||||||
DrawConfigOption(rowCount++, yOffset, &Config::Subtitles);
|
DrawConfigOption(rowCount++, yOffset, &Config::Subtitles);
|
||||||
|
DrawConfigOption(rowCount++, yOffset, &Config::MusicAttenuation); // TODO: grey this out for non-Windows platforms.
|
||||||
DrawConfigOption(rowCount++, yOffset, &Config::WerehogBattleMusic);
|
DrawConfigOption(rowCount++, yOffset, &Config::WerehogBattleMusic);
|
||||||
break;
|
break;
|
||||||
case 3: // VIDEO
|
case 3: // VIDEO
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue