changed sound handling to only expire loop sounds during gameplay
authorHolger Schemel <info@artsoft.org>
Sun, 10 Apr 2016 22:00:08 +0000 (00:00 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 10 Apr 2016 22:00:08 +0000 (00:00 +0200)
src/game.c
src/libgame/sound.c
src/libgame/sound.h
src/screens.c

index 87af3c9784116f75271d95b6253658f8af098001..29303a7e2f75eb069f2d18bb80d21beae9f9b3a3 100644 (file)
@@ -3113,6 +3113,8 @@ void InitGame()
   if (CheckIfGlobalBorderHasChanged())
     fade_mask = REDRAW_ALL;
 
+  ExpireSoundLoops(TRUE);
+
   FadeOut(fade_mask);
 
   ClearField();
index 4af58b671dd45294c2bc1b0a35ab6f54a246bd1b..4831248c86d2b9abc1ef56cf9ad0cd885ebc06c3 100644 (file)
@@ -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);
index 9e2d2420489697359b5542d304491c7fdb07cf35..26e882b3e177c5345b97c8a3670046463dd83c9e 100644 (file)
@@ -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();
index c01a99d711a640b175858a7e03dce7e8de5eb9cd..d6377c1d4254aa70921996e9aa79a2cbab898008 100644 (file)
@@ -1400,6 +1400,8 @@ void DrawMainMenu()
   UnmapAllGadgets();
   FadeSoundsAndMusic();
 
+  ExpireSoundLoops(FALSE);
+
   KeyboardAutoRepeatOn();
   ActivateJoystick();