From 38bb71bada08555afa9eb11d94ed5b5c3205f5f4 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 29 Aug 2018 15:21:17 -0400 Subject: [PATCH 1/3] Add mapmusposition placeholder to LE 413 change music --- src/p_spec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_spec.c b/src/p_spec.c index 103312b52..b3c8da9bd 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2299,6 +2299,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (!(line->flags & ML_BLOCKMONSTERS)) mapmusflags |= MUSIC_RELOADRESET; + mapmusposition = 0; + S_ChangeMusic(mapmusname, mapmusflags, !(line->flags & ML_EFFECT4)); // Except, you can use the ML_BLOCKMONSTERS flag to change this behavior. From 5ea8dc3dfaa724df3a6ca96677796523223e52ad Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 11:17:30 -0400 Subject: [PATCH 2/3] Change to percentage calc from interval decrement for volume fade --- src/sdl/mixer_sound.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 30ddbd275..64ab64cd9 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -72,9 +72,10 @@ static boolean is_looping; // fading static boolean is_fading; +static UINT8 fading_source; static UINT8 fading_target; -static UINT32 fading_steps; -static INT16 fading_volume_step; +static UINT32 fading_timer; +static UINT32 fading_duration; static INT32 fading_id; static void (*fading_callback)(void); @@ -86,8 +87,8 @@ static INT32 current_track; static void var_cleanup(void) { loop_point = song_length =\ - music_bytes = fading_target =\ - fading_steps = fading_volume_step = 0; + music_bytes = fading_source = fading_target =\ + fading_timer = fading_duration = 0; songpaused = is_looping =\ is_fading = false; @@ -530,16 +531,13 @@ static UINT32 music_fade(UINT32 interval, void *param) { if (!is_fading || internal_volume == fading_target || - fading_steps == 0 || - fading_volume_step == 0) + fading_duration == 0) { I_StopFadingSong(); do_fading_callback(); return 0; } - else if ( - (internal_volume > fading_target && internal_volume + fading_volume_step <= fading_target) || // finish fade out - (internal_volume < fading_target && internal_volume + fading_volume_step >= fading_target)) // finish fade in + else if ((fading_timer -= 10) <= 0) { internal_volume = fading_target; Mix_VolumeMusic(get_real_volume(music_volume)); @@ -549,7 +547,12 @@ static UINT32 music_fade(UINT32 interval, void *param) } else { - internal_volume += fading_volume_step; + UINT8 delta = abs(fading_target - fading_source); + double factor = (double)(fading_duration - fading_timer) / (double)fading_duration; + if (fading_target < fading_source) + internal_volume = max(min(internal_volume, fading_source - (UINT8)round(delta * factor)), fading_target); + else if (fading_target > fading_source) + internal_volume = min(max(internal_volume, fading_source + (UINT8)round(delta * factor)), fading_target); Mix_VolumeMusic(get_real_volume(music_volume)); return interval; } @@ -1252,13 +1255,12 @@ void I_StopFadingSong(void) if (fading_id) SDL_RemoveTimer(fading_id); is_fading = false; - fading_target = fading_steps = fading_volume_step = fading_id = 0; + fading_source = fading_target = fading_timer = fading_duration = fading_id = 0; } boolean I_FadeSongFromVolume(UINT8 target_volume, UINT8 source_volume, UINT32 ms, void (*callback)(void)) { - UINT32 target_steps, ms_per_step; - INT16 target_volume_step, volume_delta; + INT16 volume_delta; source_volume = min(source_volume, 100); volume_delta = (INT16)(target_volume - source_volume); @@ -1286,22 +1288,17 @@ boolean I_FadeSongFromVolume(UINT8 target_volume, UINT8 source_volume, UINT32 ms (((ms / 10) * 10) + 10) // higher : ((ms / 10) * 10); // lower - ms_per_step = max(10, ms / abs(volume_delta)); - // 10ms is the usual minimum timer granularity, but platform-dependent - target_steps = ms/ms_per_step; - target_volume_step = volume_delta / (INT16)target_steps; - - if (!target_steps || !target_volume_step) + if (!ms) I_SetInternalMusicVolume(target_volume); else if (source_volume != target_volume) { - fading_id = SDL_AddTimer(ms_per_step, music_fade, NULL); + fading_id = SDL_AddTimer(10, music_fade, NULL); if (fading_id) { is_fading = true; + fading_timer = fading_duration = ms; + fading_source = source_volume; fading_target = target_volume; - fading_steps = target_steps; - fading_volume_step = target_volume_step; fading_callback = callback; if (internal_volume != source_volume) From 5f87f4a47aa4e9e0af487898200d9e0197a8fa1c Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 11:19:34 -0400 Subject: [PATCH 3/3] Don't decrement fade timer if song is paused --- src/sdl/mixer_sound.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 64ab64cd9..41248245f 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -537,6 +537,8 @@ static UINT32 music_fade(UINT32 interval, void *param) do_fading_callback(); return 0; } + else if (songpaused) // don't decrement timer + return interval; else if ((fading_timer -= 10) <= 0) { internal_volume = fading_target;