diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index ebdf1f766..ec5ec14c8 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -17,6 +17,7 @@ #include "CSD/Platform/csdTexList.h" #include "Sonicteam/Actor.h" #include "Sonicteam/AppMarathon.h" +#include "Sonicteam/AudioEngineXenon.h" #include "Sonicteam/Camera/CameraMode.h" #include "Sonicteam/Camera/Cameraman.h" #include "Sonicteam/Camera/SonicCamera.h" @@ -48,12 +49,15 @@ #include "Sonicteam/Player/State/Object2.h" #include "Sonicteam/Player/State/TailsContext.h" #include "Sonicteam/SoX/AI/StateMachine.h" +#include "Sonicteam/SoX/Audio/IAudioEngine.h" #include "Sonicteam/SoX/Component.h" #include "Sonicteam/SoX/Engine/Doc.h" #include "Sonicteam/SoX/Engine/DocMode.h" #include "Sonicteam/SoX/Engine/Task.h" #include "Sonicteam/SoX/MessageReceiver.h" #include "Sonicteam/SoX/Object.h" +#include "Sonicteam/System/CreateStatic.h" +#include "Sonicteam/System/Singleton.h" #include "Sonicteam/TitleTask.h" #include "boost/smart_ptr/make_shared_object.h" #include "boost/smart_ptr/shared_ptr.h" diff --git a/MarathonRecomp/api/Sonicteam/AudioEngineXenon.h b/MarathonRecomp/api/Sonicteam/AudioEngineXenon.h new file mode 100644 index 000000000..f8354eb0f --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/AudioEngineXenon.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace Sonicteam +{ + class AudioEngineXenon : public SoX::Audio::IAudioEngine, public System::Singleton> + { + public: + MARATHON_INSERT_PADDING(8); + be m_MusicVolume; + be m_EffectsVolume; + MARATHON_INSERT_PADDING(0x14); + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Audio/IAudioEngine.h b/MarathonRecomp/api/Sonicteam/SoX/Audio/IAudioEngine.h new file mode 100644 index 000000000..78775fa23 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Audio/IAudioEngine.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace Sonicteam::SoX::Audio +{ + class IAudioEngine + { + public: + xpointer m_pVftable; + }; +} diff --git a/MarathonRecomp/api/Sonicteam/System/CreateStatic.h b/MarathonRecomp/api/Sonicteam/System/CreateStatic.h new file mode 100644 index 000000000..76b99ed34 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/System/CreateStatic.h @@ -0,0 +1,14 @@ +#pragma once + +namespace Sonicteam::System +{ + template + class CreateStatic + { + public: + static T* Create() + { + return GuestToHostFunction(TCreator); + } + }; +} diff --git a/MarathonRecomp/api/Sonicteam/System/Singleton.h b/MarathonRecomp/api/Sonicteam/System/Singleton.h new file mode 100644 index 000000000..336e58c18 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/System/Singleton.h @@ -0,0 +1,21 @@ +#pragma once + +namespace Sonicteam::System +{ + template + class Singleton + { + inline static TCreator ms_Creator{}; + + public: + static T* GetInstance() + { + auto pInstance = (xpointer*)g_memory.Translate(Ptr); + + if (!pInstance->ptr.get()) + *pInstance = ms_Creator.Create(); + + return *pInstance; + } + }; +} diff --git a/MarathonRecomp/app.cpp b/MarathonRecomp/app.cpp index 272522297..857359be1 100644 --- a/MarathonRecomp/app.cpp +++ b/MarathonRecomp/app.cpp @@ -19,6 +19,13 @@ void App::Restart(std::vector restartArgs) void App::Exit() { + // TODO (Hyper): remove this once the new options menu is implemented. + if (auto pAudioEngine = Sonicteam::AudioEngineXenon::GetInstance()) + { + Config::MusicVolume = pAudioEngine->m_MusicVolume; + Config::EffectsVolume = pAudioEngine->m_EffectsVolume; + } + Config::Save(); #ifdef _WIN32 @@ -44,11 +51,15 @@ PPC_FUNC(sub_8262A568) be Height; }; - auto cfg = reinterpret_cast(g_memory.Translate(ctx.r4.u32)); - cfg->Width = Video::s_viewportWidth; - cfg->Height = Video::s_viewportHeight; + auto pRenderConfig = reinterpret_cast(g_memory.Translate(ctx.r4.u32)); + pRenderConfig->Width = Video::s_viewportWidth; + pRenderConfig->Height = Video::s_viewportHeight; + + auto pAudioEngine = Sonicteam::AudioEngineXenon::GetInstance(); + pAudioEngine->m_MusicVolume = Config::MusicVolume * Config::MasterVolume; + pAudioEngine->m_EffectsVolume = Config::EffectsVolume * Config::MasterVolume; - LOGFN_UTILITY("Changed resolution: {}x{}", cfg->Width.get(), cfg->Height.get()); + LOGFN_UTILITY("Changed resolution: {}x{}", pRenderConfig->Width.get(), pRenderConfig->Height.get()); __imp__sub_8262A568(ctx, base); diff --git a/MarathonRecomp/user/config_def.h b/MarathonRecomp/user/config_def.h index d001c4688..0e4371f2e 100644 --- a/MarathonRecomp/user/config_def.h +++ b/MarathonRecomp/user/config_def.h @@ -39,8 +39,8 @@ CONFIG_DEFINE_ENUM("Bindings", SDL_Scancode, Key_RightStickLeft, SDL_SCANCODE_UN CONFIG_DEFINE_ENUM("Bindings", SDL_Scancode, Key_RightStickRight, SDL_SCANCODE_UNKNOWN); CONFIG_DEFINE_LOCALISED("Audio", float, MasterVolume, 1.0f); -CONFIG_DEFINE_LOCALISED("Audio", float, MusicVolume, 1.0f); -CONFIG_DEFINE_LOCALISED("Audio", float, EffectsVolume, 1.0f); +CONFIG_DEFINE_LOCALISED("Audio", float, MusicVolume, 0.6f); +CONFIG_DEFINE_LOCALISED("Audio", float, EffectsVolume, 0.6f); CONFIG_DEFINE_ENUM_LOCALISED("Audio", EChannelConfiguration, ChannelConfiguration, EChannelConfiguration::Stereo); CONFIG_DEFINE_LOCALISED("Audio", bool, MusicAttenuation, false);