rocksndiamonds-3.1.2
[rocksndiamonds.git] / src / libgame / sound.c
index 96165fe4ba1a00a9432b044244ea5ba7d60cc881..6eb1de14df23ca62529752743f0fd5ef64f406d5 100644 (file)
@@ -569,8 +569,7 @@ static void ReadReloadInfoFromPipe(SoundControl *snd_ctrl)
                                     &setup.override_level_sounds :
                                     &setup.override_level_music);
 
-  if (set_identifier)
-    free(set_identifier);
+  checked_free(set_identifier);
 
   set_identifier = checked_malloc(snd_ctrl->data_len);
 
@@ -579,16 +578,12 @@ static void ReadReloadInfoFromPipe(SoundControl *snd_ctrl)
 
   if (ti == NULL)
     ti = *ti_ptr = checked_calloc(sizeof(TreeInfo));
-  if (leveldir_current->fullpath != NULL)
-    free(leveldir_current->fullpath);
-  if (leveldir_current->sounds_path != NULL)
-    free(leveldir_current->sounds_path);
-  if (leveldir_current->music_path != NULL)
-    free(leveldir_current->music_path);
-  if (ti->basepath != NULL)
-    free(ti->basepath);
-  if (ti->fullpath != NULL)
-    free(ti->fullpath);
+
+  checked_free(leveldir_current->fullpath);
+  checked_free(leveldir_current->sounds_path);
+  checked_free(leveldir_current->music_path);
+  checked_free(ti->basepath);
+  checked_free(ti->fullpath);
 
   if (read(audio.mixer_pipe[0], set_identifier,
           snd_ctrl->data_len) != snd_ctrl->data_len ||
@@ -862,7 +857,7 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
       if (num_music_noconf == 0)       /* no fallback music available */
        return;
 
-      snd_ctrl.nr = (-(snd_ctrl.nr + 1)) % num_music_noconf;
+      snd_ctrl.nr = UNMAP_NOCONF_MUSIC(snd_ctrl.nr) % num_music_noconf;
       snd_info = Music_NoConf[snd_ctrl.nr];
     }
     else
@@ -1868,13 +1863,9 @@ static void *Load_MOD(char *filename)
 
 static void *Load_WAV_or_MOD(char *filename)
 {
-  char *basename = strrchr(filename, '/');
-
-  basename = (basename != NULL ? basename + 1 : filename);
-
-  if (FileIsSound(basename))
+  if (FileIsSound(filename))
     return Load_WAV(filename);
-  else if (FileIsMusic(basename))
+  else if (FileIsMusic(filename))
     return Load_MOD(filename);
   else
     return NULL;
@@ -1920,6 +1911,7 @@ void LoadCustomMusic_NoConf(void)
     boolean music_already_used = FALSE;
     int i;
 
+    /* skip all music files that are configured in music config file */
     for (i = 0; i < num_music; i++)
     {
       struct FileInfo *music = getMusicListEntry(i);
@@ -1944,10 +1936,15 @@ void LoadCustomMusic_NoConf(void)
 
     filename = getPath2(music_directory, basename);
 
+#if 1
+    if (FileIsMusic(basename))
+      mus_info = Load_WAV_or_MOD(filename);
+#else
     if (FileIsSound(basename))
       mus_info = Load_WAV(filename);
     else if (FileIsMusic(basename))
       mus_info = Load_MOD(filename);
+#endif
 
     free(filename);
 
@@ -1963,10 +1960,6 @@ void LoadCustomMusic_NoConf(void)
   closedir(dir);
 
   draw_init_text = FALSE;
-
-  if (num_music_noconf == 0)
-    Error(ERR_WARN, "cannot find any valid music files in directory '%s'",
-         music_directory);
 }
 
 int getSoundListSize()
@@ -2042,7 +2035,7 @@ struct PropertyMapping *getMusicListPropertyMapping()
 }
 
 void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
-                  struct ConfigInfo *config_suffix_list,
+                  struct ConfigTypeInfo *config_suffix_list,
                   char **base_prefixes, char **ext1_suffixes,
                   char **ext2_suffixes, char **ext3_suffixes,
                   char **ignore_tokens)
@@ -2122,7 +2115,7 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
 }
 
 void InitMusicList(struct ConfigInfo *config_list, int num_file_list_entries,
-                  struct ConfigInfo *config_suffix_list,
+                  struct ConfigTypeInfo *config_suffix_list,
                   char **base_prefixes, char **ext1_suffixes,
                   char **ext2_suffixes, char **ext3_suffixes,
                   char **ignore_tokens)
@@ -2386,8 +2379,7 @@ void FreeSound(void *ptr)
 #endif
   }
 
-  if (sound->source_filename)
-    free(sound->source_filename);
+  checked_free(sound->source_filename);
 
   free(sound);
 }