diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index fc6ccf50c..85c4c23c1 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -84,6 +84,7 @@ static UINT32 fading_timer; static UINT32 fading_duration; static INT32 fading_id; static void (*fading_callback)(void); +static boolean fading_nocleanup; #ifdef HAVE_LIBGME static Music_Emu *gme; @@ -99,7 +100,12 @@ static void var_cleanup(void) songpaused = is_looping =\ is_fading = false; - fading_callback = NULL; + // HACK: See music_loop, where we want the fade timing to proceed after a non-looping + // song has stopped playing + if (!fading_nocleanup) + fading_callback = NULL; + else + fading_nocleanup = false; // use it once, set it back immediately internal_volume = 100; } @@ -125,6 +131,8 @@ void I_StartupSound(void) return; } + fading_nocleanup = false; + var_cleanup(); music = NULL; @@ -537,7 +545,15 @@ static void music_loop(void) music_bytes = loop_point*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetSongPosition) } else + { + // HACK: Let fade timing proceed beyond the end of a + // non-looping song. This is a specific case where the timing + // should persist after stopping a song, so I don't believe + // this should apply every time the user stops a song. + // This is auto-unset in var_cleanup, called by I_StopSong + fading_nocleanup = true; I_StopSong(); + } } static UINT32 music_fade(UINT32 interval, void *param) @@ -1151,7 +1167,10 @@ boolean I_PlaySong(boolean looping) void I_StopSong(void) { - I_StopFadingSong(); + // HACK: See music_loop on why we want fade timing to proceed + // after end of song + if (!fading_nocleanup) + I_StopFadingSong(); #ifdef HAVE_LIBGME if (gme) @@ -1269,6 +1288,8 @@ void I_StopFadingSong(void) SDL_RemoveTimer(fading_id); is_fading = false; fading_source = fading_target = fading_timer = fading_duration = fading_id = 0; + // don't unset fading_nocleanup here just yet; fading_callback is cleaned up + // in var_cleanup() } boolean I_FadeSongFromVolume(UINT8 target_volume, UINT8 source_volume, UINT32 ms, void (*callback)(void))