From 4239ba2adc93afb81230b1a4ea42e7eaf68452c6 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 11 Apr 2016 00:00:08 +0200 Subject: [PATCH] changed sound handling to only expire loop sounds during gameplay --- src/game.c | 2 ++ src/libgame/sound.c | 26 ++++++++++++++++++++++++-- src/libgame/sound.h | 3 +++ src/screens.c | 2 ++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/game.c b/src/game.c index 87af3c97..29303a7e 100644 --- a/src/game.c +++ b/src/game.c @@ -3113,6 +3113,8 @@ void InitGame() if (CheckIfGlobalBorderHasChanged()) fade_mask = REDRAW_ALL; + ExpireSoundLoops(TRUE); + FadeOut(fade_mask); ClearField(); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 4af58b67..4831248c 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -122,6 +122,7 @@ static int stereo_volume[SOUND_MAX_LEFT2RIGHT + 1]; static struct SoundControl mixer[NUM_MIXER_CHANNELS]; static int mixer_active_channels = 0; +static boolean expire_loop_sounds = FALSE; static void ReloadCustomSounds(); static void ReloadCustomMusic(); @@ -150,7 +151,8 @@ static void Mixer_ResetChannelExpiration(int channel) { mixer[channel].playing_starttime = Counter(); - if (IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel])) + if (expire_loop_sounds && + IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel])) Mix_ExpireChannel(channel, SOUND_LOOP_EXPIRATION_TIME); } @@ -159,7 +161,8 @@ static boolean Mixer_ChannelExpired(int channel) if (!mixer[channel].active) return TRUE; - if (IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel]) && + if (expire_loop_sounds && + IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel]) && DelayReached(&mixer[channel].playing_starttime, SOUND_LOOP_EXPIRATION_TIME)) return TRUE; @@ -478,6 +481,10 @@ static void HandleSoundRequest(SoundControl snd_ctrl) if (SAME_SOUND_NR(mixer[i], snd_ctrl) || ALL_SOUNDS(snd_ctrl)) Mixer_StopChannel(i); } + else if (SET_EXPIRE_LOOPS(snd_ctrl)) /* set loop expiration on or off */ + { + expire_loop_sounds = snd_ctrl.active; + } else if (snd_ctrl.active) /* add new sound to mixer */ { Mixer_InsertSound(snd_ctrl); @@ -990,6 +997,21 @@ void StopSoundExt(int nr, int state) HandleSoundRequest(snd_ctrl); } +void ExpireSoundLoops(boolean active) +{ + SoundControl snd_ctrl; + + if (!audio.sound_available) + return; + + clear_mem(&snd_ctrl, sizeof(SoundControl)); /* to make valgrind happy */ + + snd_ctrl.active = active; + snd_ctrl.state = SND_CTRL_EXPIRE_LOOPS; + + HandleSoundRequest(snd_ctrl); +} + static void ReloadCustomSounds() { LoadArtworkConfig(sound_info); diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 9e2d2420..26e882b3 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -56,6 +56,7 @@ #define SND_CTRL_ALL_SOUNDS (1 << 4) #define SND_CTRL_RELOAD_SOUNDS (1 << 5) #define SND_CTRL_RELOAD_MUSIC (1 << 6) +#define SND_CTRL_EXPIRE_LOOPS (1 << 7) #define SND_CTRL_PLAY_SOUND (SND_CTRL_NONE) #define SND_CTRL_PLAY_LOOP (SND_CTRL_LOOP) @@ -76,6 +77,7 @@ #define IS_RELOADING(x) ((x).state & (SND_CTRL_RELOAD_SOUNDS |\ SND_CTRL_RELOAD_MUSIC)) #define ALL_SOUNDS(x) ((x).state & SND_CTRL_ALL_SOUNDS) +#define SET_EXPIRE_LOOPS(x) ((x).state & SND_CTRL_EXPIRE_LOOPS) #define MAP_NOCONF_MUSIC(x) (-((x) + 1)) #define UNMAP_NOCONF_MUSIC(x) MAP_NOCONF_MUSIC(x) @@ -113,6 +115,7 @@ void StopMusic(void); void StopSound(int); void StopSounds(void); void StopSoundExt(int, int); +void ExpireSoundLoops(boolean); int getSoundListSize(); int getMusicListSize(); diff --git a/src/screens.c b/src/screens.c index c01a99d7..d6377c1d 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1400,6 +1400,8 @@ void DrawMainMenu() UnmapAllGadgets(); FadeSoundsAndMusic(); + ExpireSoundLoops(FALSE); + KeyboardAutoRepeatOn(); ActivateJoystick(); -- 2.34.1