From 0128377ad9733fbae554dcce63b78eb3d38c8887 Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Tue, 25 Feb 2025 23:00:51 +0300 Subject: [PATCH] Implement installer music. (#463) --- UnleashedRecomp/CMakeLists.txt | 1 + UnleashedRecomp/api/SWA.h | 2 +- UnleashedRecomp/apu/embedded_player.cpp | 25 ++++++++++++++++++++++++- UnleashedRecomp/apu/embedded_player.h | 7 ++++++- UnleashedRecomp/ui/installer_wizard.cpp | 19 +++++++++++++++++++ UnleashedRecompResources | 2 +- 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 2bdeaf4..ce05eb1 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -553,6 +553,7 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/ga BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon_night.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon_night.bmp" ARRAY_NAME "g_game_icon_night") ## Audio ## +BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/music/installer.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/music/installer.ogg" ARRAY_NAME "g_installer_music") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_worldmap_cursor.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_worldmap_cursor.ogg" ARRAY_NAME "g_sys_worldmap_cursor") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_worldmap_finaldecide.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_worldmap_finaldecide.ogg" ARRAY_NAME "g_sys_worldmap_finaldecide") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausecansel.ogg" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausecansel.ogg" ARRAY_NAME "g_sys_actstg_pausecansel") diff --git a/UnleashedRecomp/api/SWA.h b/UnleashedRecomp/api/SWA.h index bf2f5ea..dbeb7df 100644 --- a/UnleashedRecomp/api/SWA.h +++ b/UnleashedRecomp/api/SWA.h @@ -86,8 +86,8 @@ #include "SWA/Inspire/InspireTextureAnimationInfo.h" #include "SWA/Inspire/InspireTextureOverlay.h" #include "SWA/Inspire/InspireTextureOverlayInfo.h" -#include "SWA/Message/MsgRequestHelp.h" #include "SWA/Menu/MenuWindowBase.h" +#include "SWA/Message/MsgRequestHelp.h" #include "SWA/Movie/MovieDisplayer.h" #include "SWA/Movie/MovieManager.h" #include "SWA/Object/Common/DashPanel/ObjDashPanel.h" diff --git a/UnleashedRecomp/apu/embedded_player.cpp b/UnleashedRecomp/apu/embedded_player.cpp index 6049a87..b3563f5 100644 --- a/UnleashedRecomp/apu/embedded_player.cpp +++ b/UnleashedRecomp/apu/embedded_player.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -87,13 +88,17 @@ static void PlayEmbeddedSound(EmbeddedSound s) data.chunk = Mix_LoadWAV_RW(SDL_RWFromConstMem(soundData, soundDataSize), 1); } + Mix_VolumeChunk(data.chunk, Config::MasterVolume * Config::EffectsVolume * MIX_MAX_VOLUME); Mix_PlayChannel(g_channelIndex % MIX_CHANNELS, data.chunk, 0); ++g_channelIndex; } +static Mix_Music* g_installerMusic; + void EmbeddedPlayer::Init() { - Mix_OpenAudio(XAUDIO_SAMPLES_HZ, AUDIO_F32SYS, 2, 256); + Mix_OpenAudio(XAUDIO_SAMPLES_HZ, AUDIO_F32SYS, 2, 2048); + g_installerMusic = Mix_LoadMUS_RW(SDL_RWFromConstMem(g_installer_music, sizeof(g_installer_music)), 1); s_isActive = true; } @@ -111,6 +116,21 @@ void EmbeddedPlayer::Play(const char *name) PlayEmbeddedSound(it->second); } +void EmbeddedPlayer::PlayMusic() +{ + if (!Mix_PlayingMusic()) + { + Mix_PlayMusic(g_installerMusic, INT_MAX); + Mix_VolumeMusic(Config::MasterVolume * Config::MusicVolume * MUSIC_VOLUME * MIX_MAX_VOLUME); + } +} + +void EmbeddedPlayer::FadeOutMusic() +{ + if (Mix_PlayingMusic()) + Mix_FadeOutMusic(1000); +} + void EmbeddedPlayer::Shutdown() { for (EmbeddedSoundData &data : g_embeddedSoundData) @@ -119,6 +139,9 @@ void EmbeddedPlayer::Shutdown() Mix_FreeChunk(data.chunk); } + Mix_HaltMusic(); + Mix_FreeMusic(g_installerMusic); + Mix_CloseAudio(); Mix_Quit(); diff --git a/UnleashedRecomp/apu/embedded_player.h b/UnleashedRecomp/apu/embedded_player.h index 40e241b..454d45a 100644 --- a/UnleashedRecomp/apu/embedded_player.h +++ b/UnleashedRecomp/apu/embedded_player.h @@ -2,9 +2,14 @@ struct EmbeddedPlayer { - inline static bool s_isActive = false; + // Arbitrarily picked volume to match the mixing in the original game. + static constexpr float MUSIC_VOLUME = 0.25f; + + static inline bool s_isActive = false; static void Init(); static void Play(const char *name); + static void PlayMusic(); + static void FadeOutMusic(); static void Shutdown(); }; diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index 243f21b..06321c7 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -1721,6 +1721,24 @@ static void PickerCheckResults() g_currentPickerVisible = false; } +static bool g_fadingOutMusic; + +static void ProcessMusic() +{ + if (g_isDisappearing) + { + if (!g_fadingOutMusic) + { + EmbeddedPlayer::FadeOutMusic(); + g_fadingOutMusic = true; + } + } + else + { + EmbeddedPlayer::PlayMusic(); + } +} + void InstallerWizard::Init() { auto &io = ImGui::GetIO(); @@ -1850,6 +1868,7 @@ bool InstallerWizard::Run(std::filesystem::path installPath, bool skipGame) while (s_isVisible) { Video::WaitOnSwapChain(); + ProcessMusic(); SDL_PumpEvents(); SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); GameWindow::Update(); diff --git a/UnleashedRecompResources b/UnleashedRecompResources index 1375ed7..c6d50cc 160000 --- a/UnleashedRecompResources +++ b/UnleashedRecompResources @@ -1 +1 @@ -Subproject commit 1375ed71841dd391be609f9380ec456f2679463b +Subproject commit c6d50cced704fea609fbe93323d506c211fe8402