rnd-20030901-B-src
[rocksndiamonds.git] / src / libgame / sound.c
index 3f1d04e9eee0cd0593e1f54114e5e3af1f3c626a..72681647ed847bbfeba8edf3ea3172408532e22a 100644 (file)
@@ -149,9 +149,14 @@ struct SoundControl
 typedef struct SoundControl SoundControl;
 
 static struct ArtworkListInfo *sound_info = NULL;
+#if 0
 static SoundInfo **Sound = NULL;
+#endif
 static MusicInfo **Music = NULL;
-static int num_sounds = 0, num_music = 0;
+#if 0
+static int num_sounds = 0;
+#endif
+static int num_music = 0;
 static int stereo_volume[SOUND_MAX_LEFT2RIGHT + 1];
 
 
@@ -175,6 +180,8 @@ static void ReloadCustomSounds();
 static void ReloadCustomMusic();
 static void FreeSound(void *);
 
+static SoundInfo *getSoundInfoEntryFromSoundID(int);
+
 
 /* ------------------------------------------------------------------------- */
 /* functions for native (non-SDL) Unix audio/mixer support                   */
@@ -292,7 +299,7 @@ void UnixCloseAudio(void)
   if (audio.device_fd)
     close(audio.device_fd);
 
-  if (IS_PARENT_PROCESS())
+  if (IS_PARENT_PROCESS() && HAS_CHILD_PROCESS())
     kill(audio.mixer_pid, SIGTERM);
 }
 
@@ -307,7 +314,7 @@ static void InitAudioDevice_Linux(struct AudioFormatInfo *afmt)
   /* "ioctl()" expects pointer to 'int' value for stereo flag
      (boolean is defined as 'char', which will not work here) */
   unsigned int fragment_spec = 0;
-  int fragment_size_query;
+  int fragment_size_query = -1;
   int stereo = TRUE;
   struct
   {
@@ -500,6 +507,8 @@ static void WriteReloadInfoToPipe(char *set_identifier, int type)
   if (leveldir_current == NULL)                /* should never happen */
     Error(ERR_EXIT, "leveldir_current == NULL");
 
+  memset(&snd_ctrl, 0, sizeof(SoundControl));  /* to make valgrind happy */
+
   snd_ctrl.active = FALSE;
   snd_ctrl.state = type;
   snd_ctrl.data_len = strlen(set_identifier) + 1;
@@ -816,6 +825,7 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
 {
   SoundInfo *snd_info;
   int i, k;
+  int num_sounds = getSoundListSize();
 
 #if 0
   printf("NEW SOUND %d ARRIVED [%d] [%d ACTIVE CHANNELS]\n",
@@ -832,7 +842,13 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
   else if (snd_ctrl.nr >= num_sounds)
     return;
 
+#if 0
   snd_info = (IS_MUSIC(snd_ctrl) ? Music[snd_ctrl.nr] : Sound[snd_ctrl.nr]);
+#else
+  snd_info = (IS_MUSIC(snd_ctrl) ? Music[snd_ctrl.nr] :
+             getSoundInfoEntryFromSoundID(snd_ctrl.nr));
+#endif
+
   if (snd_info == NULL)
     return;
 
@@ -1782,6 +1798,17 @@ struct FileInfo *getSoundListEntry(int pos)
          &sound_info->dynamic_file_list[list_pos]);
 }
 
+static SoundInfo *getSoundInfoEntryFromSoundID(int pos)
+{
+  int num_list_entries = sound_info->num_file_list_entries;
+  int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries);
+  SoundInfo **snd_info =
+    (SoundInfo **)(pos < num_list_entries ? sound_info->artwork_list :
+                  sound_info->dynamic_artwork_list);
+
+  return snd_info[list_pos];
+}
+
 int getSoundListPropertyMappingSize()
 {
   return sound_info->num_property_mapping_entries;
@@ -1794,10 +1821,9 @@ struct PropertyMapping *getSoundListPropertyMapping()
 
 void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
                   struct ConfigInfo *config_suffix_list,
-                  char **base_prefixes,
-                  char **ext1_suffixes,
-                  char **ext2_suffixes,
-                  char **ext3_suffixes)
+                  char **base_prefixes, char **ext1_suffixes,
+                  char **ext2_suffixes, char **ext3_suffixes,
+                  char **ignore_tokens)
 {
   int i;
 
@@ -1810,7 +1836,7 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   sound_info->num_dynamic_file_list_entries = 0;
 
   sound_info->file_list =
-    getFileListFromConfigList(config_list, config_suffix_list,
+    getFileListFromConfigList(config_list, config_suffix_list, ignore_tokens,
                              num_file_list_entries);
   sound_info->dynamic_file_list = NULL;
 
@@ -1838,10 +1864,15 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   for (i=0; ext3_suffixes[i] != NULL; i++)
     sound_info->num_ext3_suffixes++;
 
+  sound_info->num_ignore_tokens = 0;
+  for (i=0; ignore_tokens[i] != NULL; i++)
+    sound_info->num_ignore_tokens++;
+
   sound_info->base_prefixes = base_prefixes;
   sound_info->ext1_suffixes = ext1_suffixes;
   sound_info->ext2_suffixes = ext2_suffixes;
   sound_info->ext3_suffixes = ext3_suffixes;
+  sound_info->ignore_tokens = ignore_tokens;
 
   sound_info->num_property_mapping_entries = 0;
 
@@ -1862,8 +1893,10 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   sound_info->load_artwork = Load_WAV;
   sound_info->free_artwork = FreeSound;
 
+#if 0
   num_sounds = sound_info->num_file_list_entries;
   Sound = (SoundInfo **)sound_info->artwork_list;
+#endif
 }
 
 static MusicInfo *Load_MOD(char *filename)
@@ -2007,6 +2040,8 @@ void PlaySoundExt(int nr, int volume, int stereo_position, int state)
   else if (stereo_position > SOUND_MAX_RIGHT)
     stereo_position = SOUND_MAX_RIGHT;
 
+  memset(&snd_ctrl, 0, sizeof(SoundControl));  /* to make valgrind happy */
+
   snd_ctrl.active = TRUE;
   snd_ctrl.nr = nr;
   snd_ctrl.volume = volume;
@@ -2061,6 +2096,8 @@ void StopSoundExt(int nr, int state)
   if (!audio.sound_available)
     return;
 
+  memset(&snd_ctrl, 0, sizeof(SoundControl));  /* to make valgrind happy */
+
   snd_ctrl.active = FALSE;
   snd_ctrl.nr = nr;
   snd_ctrl.state = state;
@@ -2076,6 +2113,10 @@ static void ReloadCustomSounds()
 
   LoadArtworkConfig(sound_info);
   ReloadCustomArtworkList(sound_info);
+
+#if 0
+  num_sounds = getSoundListSize();
+#endif
 }
 
 static void ReloadCustomMusic()