diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index a56ca413..f6438c4b 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -131,6 +131,9 @@ WorldMapTerrainInfo=0 ;Set to 0 to leave the default unchanged (i.e. 4). The maximum is 32 NumSoundBuffers=0 +;Set to 1 to enable fade effects for background music when stopping and starting the playback +FadeBackgroundMusic=1 + ;Set to 1 to allow attaching sound files to combat float messages AllowSoundForFloats=0 diff --git a/sfall/Modules/Sound.cpp b/sfall/Modules/Sound.cpp index 33500d44..564aaa15 100644 --- a/sfall/Modules/Sound.cpp +++ b/sfall/Modules/Sound.cpp @@ -950,7 +950,9 @@ constexpr int SampleRate = 44100; // 44.1kHz void Sound::init() { // Set the 44.1kHz sample rate for the primary sound buffer SafeWrite32(0x44FDBC, SampleRate); - LoadGameHook::OnAfterGameInit() += []() { fo::var::sampleRate = SampleRate / 2; }; // Revert to 22kHz for secondary sound buffers + LoadGameHook::OnAfterGameInit() += []() { + fo::var::sampleRate = SampleRate / 2; // Revert to 22kHz for secondary sound buffers + }; LoadGameHook::OnGameReset() += WipeSounds; LoadGameHook::OnBeforeGameClose() += WipeSounds; @@ -1024,6 +1026,15 @@ void Sound::init() { if (IniReader::GetConfigInt("Sound", "AutoSearchSFX", 1)) { HookCalls(sfxl_init_hook, {0x4A9999, 0x4A9B34}); } + + if (IniReader::GetConfigInt("Sound", "FadeBackgroundMusic", 1)) { + SafeMemSet(0x45020C, CodeType::Nop, 6); // gsound_reset_ + SafeWrite32(0x45212C, 250); // delay start + SafeWrite32(0x450ADE, 500); // delay stop + LoadGameHook::OnAfterGameInit() += []() { + *(DWORD*)FO_VAR_gsound_background_fade = 1; + }; + } } void Sound::exit() {