From e8ab7e627101b6d837c9294e4c1992dd55b9afc2 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 20 Aug 2023 16:48:58 +0300 Subject: [PATCH] Add S_RestartMusic function and call it directly when changing amiga filter types --- src/s_sound.c | 38 ++++++++++++++++++++++---------------- src/s_sound.h | 3 +++ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 89d3d96a9..ff2009b5a 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2044,6 +2044,24 @@ void S_Start(void) S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); } +void S_RestartMusic(void) +{ + S_StopMusic(); + I_ShutdownMusic(); + I_InitMusic(); + +#ifdef NO_MIDI + S_SetMusicVolume(cv_digmusicvolume.value, -1); +#else + S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value); +#endif + + if (Playing()) // Gotta make sure the player is in a level + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("titles", looptitle); +} + static void Command_Tunes_f(void) { const char *tunearg; @@ -2150,20 +2168,7 @@ static void Command_RestartAudio_f(void) static void Command_RestartMusic_f(void) //same as RestartAudio but only music gets restarted { - S_StopMusic(); - I_ShutdownMusic(); - I_InitMusic(); - -#ifdef NO_MIDI - S_SetMusicVolume(cv_digmusicvolume.value, -1); -#else - S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value); -#endif - - if (Playing()) // Gotta make sure the player is in a level - P_RestoreMusic(&players[consoleplayer]); - else - S_ChangeMusicInternal("titles", looptitle); + S_RestartMusic(); } void GameSounds_OnChange(void) @@ -2242,8 +2247,9 @@ void AmigaType_OnChange(void) { if (openmpt_mhandle) openmpt_module_ctl_set_text(openmpt_mhandle, "render.resampler.emulate_amiga", cv_amigatype.string); - COM_ImmedExecute("restartmusic"); //need to restart the music system or else it wont work - } + + S_RestartMusic(); //need to restart the music system or else it wont work +} #endif #endif diff --git a/src/s_sound.h b/src/s_sound.h index 2bcf6c4f7..6d9fed164 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -108,6 +108,9 @@ void S_StopSounds(void); void S_ClearSfx(void); void S_Start(void); +// Stops music and restarts it from same position. Used for instant applying changes to amiga filters. +void S_RestartMusic(void); + // // Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum. //