Added FadeBackgroundMusic option

This commit is contained in:
NovaRain
2021-08-13 20:13:36 +08:00
parent 6b34303268
commit a4b7ac76a0
2 changed files with 13 additions and 0 deletions
+3
View File
@@ -104,6 +104,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
+10
View File
@@ -959,8 +959,11 @@ static void __declspec(naked) sfxl_init_hook() {
static const int SampleRate = 44100; // 44.1kHz
static bool fadeBgMusic = false;
void Sound_OnAfterGameInit() {
*ptr_sampleRate = SampleRate / 2; // Revert to 22kHz for secondary sound buffers
if (fadeBgMusic) *(DWORD*)FO_VAR_gsound_background_fade = 1;
}
void Sound_Init() {
@@ -1040,6 +1043,13 @@ void Sound_Init() {
const DWORD sfxlInitAddr[] = {0x4A9999, 0x4A9B34};
HookCalls(sfxl_init_hook, sfxlInitAddr);
}
if (GetConfigInt("Sound", "FadeBackgroundMusic", 1)) {
SafeMemSet(0x45020C, CODETYPE_Nop, 6); // gsound_reset_
SafeWrite32(0x45212C, 250); // delay start
SafeWrite32(0x450ADE, 500); // delay stop
fadeBgMusic = true;
}
}
void Sound_Exit() {