Skip to content

Commit 0128377

Browse files
Implement installer music. (#463)
1 parent 98daa27 commit 0128377

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

UnleashedRecomp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/ga
553553
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")
554554

555555
## Audio ##
556+
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")
556557
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")
557558
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")
558559
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")

UnleashedRecomp/api/SWA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
#include "SWA/Inspire/InspireTextureAnimationInfo.h"
8787
#include "SWA/Inspire/InspireTextureOverlay.h"
8888
#include "SWA/Inspire/InspireTextureOverlayInfo.h"
89-
#include "SWA/Message/MsgRequestHelp.h"
9089
#include "SWA/Menu/MenuWindowBase.h"
90+
#include "SWA/Message/MsgRequestHelp.h"
9191
#include "SWA/Movie/MovieDisplayer.h"
9292
#include "SWA/Movie/MovieManager.h"
9393
#include "SWA/Object/Common/DashPanel/ObjDashPanel.h"

UnleashedRecomp/apu/embedded_player.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <apu/embedded_player.h>
33
#include <user/config.h>
44

5+
#include <res/music/installer.ogg.h>
56
#include <res/sounds/sys_worldmap_cursor.ogg.h>
67
#include <res/sounds/sys_worldmap_finaldecide.ogg.h>
78
#include <res/sounds/sys_actstg_pausecansel.ogg.h>
@@ -87,13 +88,17 @@ static void PlayEmbeddedSound(EmbeddedSound s)
8788
data.chunk = Mix_LoadWAV_RW(SDL_RWFromConstMem(soundData, soundDataSize), 1);
8889
}
8990

91+
Mix_VolumeChunk(data.chunk, Config::MasterVolume * Config::EffectsVolume * MIX_MAX_VOLUME);
9092
Mix_PlayChannel(g_channelIndex % MIX_CHANNELS, data.chunk, 0);
9193
++g_channelIndex;
9294
}
9395

96+
static Mix_Music* g_installerMusic;
97+
9498
void EmbeddedPlayer::Init()
9599
{
96-
Mix_OpenAudio(XAUDIO_SAMPLES_HZ, AUDIO_F32SYS, 2, 256);
100+
Mix_OpenAudio(XAUDIO_SAMPLES_HZ, AUDIO_F32SYS, 2, 2048);
101+
g_installerMusic = Mix_LoadMUS_RW(SDL_RWFromConstMem(g_installer_music, sizeof(g_installer_music)), 1);
97102

98103
s_isActive = true;
99104
}
@@ -111,6 +116,21 @@ void EmbeddedPlayer::Play(const char *name)
111116
PlayEmbeddedSound(it->second);
112117
}
113118

119+
void EmbeddedPlayer::PlayMusic()
120+
{
121+
if (!Mix_PlayingMusic())
122+
{
123+
Mix_PlayMusic(g_installerMusic, INT_MAX);
124+
Mix_VolumeMusic(Config::MasterVolume * Config::MusicVolume * MUSIC_VOLUME * MIX_MAX_VOLUME);
125+
}
126+
}
127+
128+
void EmbeddedPlayer::FadeOutMusic()
129+
{
130+
if (Mix_PlayingMusic())
131+
Mix_FadeOutMusic(1000);
132+
}
133+
114134
void EmbeddedPlayer::Shutdown()
115135
{
116136
for (EmbeddedSoundData &data : g_embeddedSoundData)
@@ -119,6 +139,9 @@ void EmbeddedPlayer::Shutdown()
119139
Mix_FreeChunk(data.chunk);
120140
}
121141

142+
Mix_HaltMusic();
143+
Mix_FreeMusic(g_installerMusic);
144+
122145
Mix_CloseAudio();
123146
Mix_Quit();
124147

UnleashedRecomp/apu/embedded_player.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
struct EmbeddedPlayer
44
{
5-
inline static bool s_isActive = false;
5+
// Arbitrarily picked volume to match the mixing in the original game.
6+
static constexpr float MUSIC_VOLUME = 0.25f;
7+
8+
static inline bool s_isActive = false;
69

710
static void Init();
811
static void Play(const char *name);
12+
static void PlayMusic();
13+
static void FadeOutMusic();
914
static void Shutdown();
1015
};

UnleashedRecomp/ui/installer_wizard.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,24 @@ static void PickerCheckResults()
17211721
g_currentPickerVisible = false;
17221722
}
17231723

1724+
static bool g_fadingOutMusic;
1725+
1726+
static void ProcessMusic()
1727+
{
1728+
if (g_isDisappearing)
1729+
{
1730+
if (!g_fadingOutMusic)
1731+
{
1732+
EmbeddedPlayer::FadeOutMusic();
1733+
g_fadingOutMusic = true;
1734+
}
1735+
}
1736+
else
1737+
{
1738+
EmbeddedPlayer::PlayMusic();
1739+
}
1740+
}
1741+
17241742
void InstallerWizard::Init()
17251743
{
17261744
auto &io = ImGui::GetIO();
@@ -1850,6 +1868,7 @@ bool InstallerWizard::Run(std::filesystem::path installPath, bool skipGame)
18501868
while (s_isVisible)
18511869
{
18521870
Video::WaitOnSwapChain();
1871+
ProcessMusic();
18531872
SDL_PumpEvents();
18541873
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
18551874
GameWindow::Update();

0 commit comments

Comments
 (0)