rnd-20070302-1-src
[rocksndiamonds.git] / src / libgame / sound.c
index 8fb94919cff281bdc887a241aecf1225ab9f076c..51b62efc7a5572a24176b56f31f2a8d0d1eaadcd 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-* (c) 1994-2002 Artsoft Entertainment                      *
+* (c) 1994-2006 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
 #define SAME_SOUND_NR(x,y)             ((x).nr == (y).nr)
 #define SAME_SOUND_DATA(x,y)           ((x).data_ptr == (y).data_ptr)
 
-#if 0
-struct SoundHeader_SUN
-{
-  unsigned long magic;
-  unsigned long hdr_size;
-  unsigned long data_size;
-  unsigned long encoding;
-  unsigned long sample_rate;
-  unsigned long channels;
-};
-
-struct SoundHeader_8SVX
-{
-  char magic_FORM[4];
-  unsigned long chunk_size;
-  char magic_8SVX[4];
-};
-#endif
-
 #if defined(AUDIO_UNIX_NATIVE)
 struct SoundHeader_WAV
 {
@@ -151,16 +132,8 @@ typedef struct SoundControl SoundControl;
 static struct ArtworkListInfo *sound_info = NULL;
 static struct ArtworkListInfo *music_info = NULL;
 
-#if 0
-static SoundInfo **Sound = NULL;
-#endif
-
 static MusicInfo **Music_NoConf = NULL;
 
-#if 0
-static int num_sounds = 0;
-#endif
-
 static int num_music_noconf = 0;
 static int stereo_volume[SOUND_MAX_LEFT2RIGHT + 1];
 
@@ -237,7 +210,7 @@ static boolean TestAudioDevices(void)
   int i;
 
   /* look for available audio devices, starting with preferred ones */
-  for (i=0; i<sizeof(audio_device_name)/sizeof(char *); i++)
+  for (i = 0; i < sizeof(audio_device_name)/sizeof(char *); i++)
     if ((audio_device_fd = OpenAudioDevice(audio_device_name[i])) >= 0)
       break;
 
@@ -271,11 +244,6 @@ static boolean ForkAudioProcess(void)
   if (audio.mixer_pid == 0)            /* we are the child process */
     audio.mixer_pid = getpid();
 
-#if 0
-  printf("PID: %d [%s]\n", getpid(),(IS_CHILD_PROCESS() ? "child" : "parent"));
-  Delay(10000 * 0);
-#endif
-
   if (IS_CHILD_PROCESS())
     Mixer_Main();                      /* this function never returns */
   else
@@ -569,8 +537,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 +546,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 ||
@@ -645,7 +608,7 @@ void Mixer_InitChannels()
 {
   int i;
 
-  for(i=0; i<audio.num_channels; i++)
+  for (i = 0; i < audio.num_channels; i++)
     mixer[i].active = FALSE;
   mixer_active_channels = 0;
 }
@@ -836,22 +799,6 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
   int num_sounds = getSoundListSize();
   int num_music  = getMusicListSize();
 
-#if 0
-  if (IS_MUSIC(snd_ctrl))
-    printf("NEW MUSIC %d ARRIVED [%d/%d] [%d ACTIVE CHANNELS]\n",
-          snd_ctrl.nr, num_music, num_music_noconf, mixer_active_channels);
-  else
-    printf("NEW SOUND %d ARRIVED [%d] [%d ACTIVE CHANNELS]\n",
-          snd_ctrl.nr, num_sounds, mixer_active_channels);
-#endif
-
-#if 0
-  /* !!! TEST ONLY !!! */
-  if (IS_MUSIC(snd_ctrl))
-    snd_ctrl.nr = 0;
-#endif
-
-#if 1
   if (IS_MUSIC(snd_ctrl))
   {
     if (snd_ctrl.nr >= num_music)      /* invalid music */
@@ -862,7 +809,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
@@ -876,32 +823,6 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
     snd_info = getSoundInfoEntryFromSoundID(snd_ctrl.nr);
   }
 
-  /*
-  if (snd_ctrl.nr >= (IS_MUSIC(snd_ctrl) ? num_music : num_sounds))
-    return;
-  */
-#else
-  if (IS_MUSIC(snd_ctrl))
-  {
-    if (num_music_noconf == 0)
-      return;
-
-    snd_ctrl.nr = snd_ctrl.nr % num_music_noconf;
-  }
-  else if (snd_ctrl.nr >= num_sounds)
-    return;
-#endif
-
-#if 0
-#if 1
-  snd_info = (IS_MUSIC(snd_ctrl) ? getMusicInfoEntryFromMusicID(snd_ctrl.nr) :
-             getSoundInfoEntryFromSoundID(snd_ctrl.nr));
-#else
-  snd_info = (IS_MUSIC(snd_ctrl) ? Music_NoConf[snd_ctrl.nr] :
-             getSoundInfoEntryFromSoundID(snd_ctrl.nr));
-#endif
-#endif
-
   if (snd_info == NULL)
     return;
 
@@ -915,10 +836,6 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
   /* play music samples on a dedicated music channel */
   if (IS_MUSIC(snd_ctrl))
   {
-#if 0
-    printf("::: slot %d, ptr 0x%08x\n", snd_ctrl.nr, snd_ctrl.data_ptr);
-#endif
-
     Mixer_StopMusicChannel();
 
     mixer[audio.music_channel] = snd_ctrl;
@@ -928,25 +845,17 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
   }
 
   /* check if (and how often) this sound sample is already playing */
-  for (k=0, i=audio.first_sound_channel; i<audio.num_channels; i++)
+  for (k = 0, i = audio.first_sound_channel; i < audio.num_channels; i++)
     if (mixer[i].active && SAME_SOUND_DATA(mixer[i], snd_ctrl))
       k++;
 
-#if 0
-  printf("SOUND %d [CURRENTLY PLAYING %d TIMES]\n", snd_ctrl.nr, k);
-#endif
-
   /* reset expiration delay for already playing loop sounds */
   if (k > 0 && IS_LOOP(snd_ctrl))
   {
-    for(i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
     {
       if (mixer[i].active && SAME_SOUND_DATA(mixer[i], snd_ctrl))
       {
-#if 0
-       printf("RESETTING EXPIRATION FOR SOUND %d\n", snd_ctrl.nr);
-#endif
-
        if (IS_FADING(mixer[i]))
          Mixer_UnFadeChannel(i);
 
@@ -956,21 +865,12 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
 
        Mixer_SetChannelProperties(i);
        Mixer_ResetChannelExpiration(i);
-
-#if 0
-       printf("RESETTING VOLUME/STEREO FOR SOUND %d TO %d/%d\n",
-              snd_ctrl.nr, snd_ctrl.volume, snd_ctrl.stereo_position);
-#endif
       }
     }
 
     return;
   }
 
-#if 0
-  printf("PLAYING NEW SOUND %d\n", snd_ctrl.nr);
-#endif
-
   /* don't play sound more than n times simultaneously (with n == 2 for now) */
   if (k >= 2)
   {
@@ -978,7 +878,7 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
     int longest = 0, longest_nr = audio.first_sound_channel;
 
     /* look for oldest equal sound */
-    for(i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
     {
       int playing_time = playing_current - mixer[i].playing_starttime;
       int actual;
@@ -1009,12 +909,12 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
   if (mixer_active_channels ==
       audio.num_channels - (mixer[audio.music_channel].active ? 0 : 1))
   {
-    for (i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
     {
       if (!mixer[i].active)
       {
-       Error(ERR_RETURN, "Mixer_InsertSound: Channel %d inactive", i);
-       Error(ERR_RETURN, "Mixer_InsertSound: This should never happen!");
+       Error(ERR_INFO, "Mixer_InsertSound: Channel %d inactive", i);
+       Error(ERR_INFO, "Mixer_InsertSound: This should never happen!");
 
        mixer_active_channels--;
       }
@@ -1031,15 +931,15 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
 #if 0
 #if DEBUG
     /* print some debugging information about audio channel usage */
-    for (i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
     {
-      Error(ERR_RETURN, "Mixer_InsertSound: %d [%d]: %ld (%ld)",
+      Error(ERR_INFO, "Mixer_InsertSound: %d [%d]: %ld (%ld)",
            i, mixer[i].active, mixer[i].data_len, (long)mixer[i].data_ptr);
     }
 #endif
 #endif
 
-    for (i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
     {
       int playing_time = playing_current - mixer[i].playing_starttime;
       int actual = 1000 * playing_time / mixer[i].data_len;
@@ -1055,18 +955,10 @@ static void Mixer_InsertSound(SoundControl snd_ctrl)
   }
 
   /* add the new sound to the mixer */
-  for(i=audio.first_sound_channel; i<audio.num_channels; i++)
+  for (i = audio.first_sound_channel; i < audio.num_channels; i++)
   {
-#if 0
-    printf("CHECKING CHANNEL %d FOR SOUND %d ...\n", i, snd_ctrl.nr);
-#endif
-
     if (!mixer[i].active)
     {
-#if 0
-      printf("ADDING NEW SOUND %d TO MIXER\n", snd_ctrl.nr);
-#endif
-
 #if defined(AUDIO_UNIX_NATIVE)
       if (snd_info->data_len == 0)
       {
@@ -1095,14 +987,14 @@ static void HandleSoundRequest(SoundControl snd_ctrl)
 #endif
 
   /* deactivate channels that have expired since the last request */
-  for (i=0; i<audio.num_channels; i++)
+  for (i = 0; i < audio.num_channels; i++)
     if (mixer[i].active && Mixer_ChannelExpired(i))
       Mixer_StopChannel(i);
 
   if (IS_RELOADING(snd_ctrl))          /* load new sound or music files */
   {
     Mixer_StopMusicChannel();
-    for(i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
       Mixer_StopChannel(i);
 
 #if defined(AUDIO_UNIX_NATIVE)
@@ -1123,7 +1015,7 @@ static void HandleSoundRequest(SoundControl snd_ctrl)
       return;
     }
 
-    for(i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
       if (SAME_SOUND_NR(mixer[i], snd_ctrl) || ALL_SOUNDS(snd_ctrl))
        Mixer_FadeChannel(i);
   }
@@ -1135,7 +1027,7 @@ static void HandleSoundRequest(SoundControl snd_ctrl)
       return;
     }
 
-    for(i=audio.first_sound_channel; i<audio.num_channels; i++)
+    for (i = audio.first_sound_channel; i < audio.num_channels; i++)
       if (SAME_SOUND_NR(mixer[i], snd_ctrl) || ALL_SOUNDS(snd_ctrl))
        Mixer_StopChannel(i);
 
@@ -1173,7 +1065,7 @@ void StartMixer(void)
     return;
 
   /* initialize stereo position conversion information */
-  for(i=0; i<=SOUND_MAX_LEFT2RIGHT; i++)
+  for (i = 0; i <= SOUND_MAX_LEFT2RIGHT; i++)
     stereo_volume[i] =
       (int)sqrt((float)(SOUND_MAX_LEFT2RIGHT * SOUND_MAX_LEFT2RIGHT - i * i));
 
@@ -1200,11 +1092,11 @@ static void CopySampleToMixingBuffer(SoundControl *snd_ctrl,
   {
     byte *sample_ptr = (byte *)snd_ctrl->data_ptr + num_channels * sample_pos;
 
-    for (i=0; i<num_output_channels; i++)
+    for (i = 0; i < num_output_channels; i++)
     {
       int offset = (snd_ctrl->num_channels == 1 ? 0 : i);
 
-      for (j=0; j<sample_size; j++)
+      for (j = 0; j < sample_size; j++)
        buffer_ptr[output_stepsize * j + i] =
          ((short)(sample_ptr[stepsize * j + offset] ^ 0x80)) << 8;
     }
@@ -1213,11 +1105,11 @@ static void CopySampleToMixingBuffer(SoundControl *snd_ctrl,
   {
     short *sample_ptr= (short *)snd_ctrl->data_ptr + num_channels * sample_pos;
 
-    for (i=0; i<num_output_channels; i++)
+    for (i = 0; i < num_output_channels; i++)
     {
       int offset = (snd_ctrl->num_channels == 1 ? 0 : i);
 
-      for (j=0; j<sample_size; j++)
+      for (j = 0; j < sample_size; j++)
        buffer_ptr[output_stepsize * j + i] =
          sample_ptr[stepsize * j + offset];
     }
@@ -1258,7 +1150,7 @@ static void Mixer_Main_DSP()
   memset(premix_last_buffer, 0,
         max_sample_size * num_output_channels * sizeof(long));
 
-  for(i=0; i<audio.num_channels; i++)
+  for (i = 0; i < audio.num_channels; i++)
   {
     void *sample_ptr;
     int sample_len;
@@ -1309,7 +1201,7 @@ static void Mixer_Main_DSP()
 
     /* adjust volume of actual sound sample */
     if (mixer[i].volume != SOUND_MAX_VOLUME)
-      for(j=0; j<sample_size * num_output_channels; j++)
+      for (j = 0; j < sample_size * num_output_channels; j++)
        premix_first_buffer[j] =
          mixer[i].volume * (long)premix_first_buffer[j] / SOUND_MAX_VOLUME;
 
@@ -1319,7 +1211,7 @@ static void Mixer_Main_DSP()
       int left_volume  = SOUND_VOLUME_LEFT(mixer[i].stereo_position);
       int right_volume = SOUND_VOLUME_RIGHT(mixer[i].stereo_position);
 
-      for(j=0; j<sample_size; j++)
+      for (j = 0; j < sample_size; j++)
       {
        premix_first_buffer[2 * j + 0] =
          left_volume  * premix_first_buffer[2 * j + 0] / SOUND_MAX_LEFT2RIGHT;
@@ -1329,7 +1221,7 @@ static void Mixer_Main_DSP()
     }
 
     /* fill the last mixing buffer with stereo or mono sound */
-    for(j=0; j<sample_size * num_output_channels; j++)
+    for (j = 0; j < sample_size * num_output_channels; j++)
       premix_last_buffer[j] += premix_first_buffer[j];
 
     /* delete completed sound entries from the mixer */
@@ -1345,7 +1237,7 @@ static void Mixer_Main_DSP()
   }
 
   /* prepare final playing buffer according to system audio format */
-  for(i=0; i<max_sample_size * num_output_channels; i++)
+  for (i = 0; i < max_sample_size * num_output_channels; i++)
   {
     /* cut off at 17 bit value */
     if (premix_last_buffer[i] < -65535)
@@ -1408,22 +1300,20 @@ static int Mixer_Main_SimpleAudio(SoundControl snd_ctrl)
 
   /* adjust volume of actual sound sample */
   if (mixer[i].volume != SOUND_MAX_VOLUME)
-    for(j=0; j<sample_size; j++)
+    for (j = 0; j < sample_size; j++)
       premix_first_buffer[j] =
        mixer[i].volume * (long)premix_first_buffer[j] / SOUND_MAX_VOLUME;
 
   /* might be needed for u-law /dev/audio */
-#if 1
-  for(j=0; j<sample_size; j++)
+  for (j = 0; j < sample_size; j++)
     playing_buffer[j] =
       linear_to_ulaw(premix_first_buffer[j]);
-#endif
 
   /* delete completed sound entries from the mixer */
   if (mixer[i].playing_pos >= mixer[i].data_len)
     Mixer_StopChannel(i);
 
-  for(i=0; i<sample_size; i++)
+  for (i = 0; i < sample_size; i++)
     playing_buffer[i] = (premix_first_buffer[i] >> 8) ^ 0x80;
 
   /* finally play the sound fragment */
@@ -1449,7 +1339,7 @@ void Mixer_Main()
   FD_ZERO(&mixer_fdset); 
   FD_SET(audio.mixer_pipe[0], &mixer_fdset);
 
-  while(1)     /* wait for sound playing commands from client */
+  while (1)    /* wait for sound playing commands from client */
   {
     struct timeval delay = { 0, 0 };
 
@@ -1643,10 +1533,6 @@ static void *Load_WAV(char *filename)
   if (!audio.sound_available)
     return NULL;
 
-#if 0
-  printf("loading WAV file '%s'\n", filename);
-#endif
-
   snd_info = checked_calloc(sizeof(SoundInfo));
 
 #if defined(TARGET_SDL)
@@ -1682,7 +1568,7 @@ static void *Load_WAV(char *filename)
 
   /* read chunk id "RIFF" */
   getFileChunkLE(file, chunk_name, &chunk_size);
-  if (strcmp(chunk_name, "RIFF") != 0)
+  if (!strEqual(chunk_name, "RIFF"))
   {
     Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename);
     fclose(file);
@@ -1692,7 +1578,7 @@ static void *Load_WAV(char *filename)
 
   /* read "RIFF" type id "WAVE" */
   getFileChunkLE(file, chunk_name, NULL);
-  if (strcmp(chunk_name, "WAVE") != 0)
+  if (!strEqual(chunk_name, "WAVE"))
   {
     Error(ERR_WARN, "missing 'WAVE' type ID of sound file '%s'", filename);
     fclose(file);
@@ -1702,7 +1588,7 @@ static void *Load_WAV(char *filename)
 
   while (getFileChunkLE(file, chunk_name, &chunk_size))
   {
-    if (strcmp(chunk_name, "fmt ") == 0)
+    if (strEqual(chunk_name, "fmt "))
     {
       if (chunk_size < WAV_HEADER_SIZE)
       {
@@ -1766,7 +1652,7 @@ static void *Load_WAV(char *filename)
       printf("  Significant bits per sample: %d'\n", header.bits_per_sample);
 #endif
     }
-    else if (strcmp(chunk_name, "data") == 0)
+    else if (strEqual(chunk_name, "data"))
     {
       data_byte_len = chunk_size;
 
@@ -1822,11 +1708,11 @@ static void *Load_WAV(char *filename)
     int i;
 
     if (snd_ctrl->format == AUDIO_FORMAT_U8)
-      for (i=0; i<sample_size; i++)
+      for (i = 0; i < sample_size; i++)
        *buffer_ptr++ =
          ((short)(((byte *)sample_ptr)[i] ^ 0x80)) << 8;
     else       /* AUDIO_FORMAT_S16 */
-      for (i=0; i<sample_size; i++)
+      for (i = 0; i < sample_size; i++)
        *buffer_ptr++ =
          ((short *)sample_ptr)[i];
   }
@@ -1868,13 +1754,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;
@@ -1893,7 +1775,7 @@ void LoadCustomMusic_NoConf(void)
     return;
 
   if (last_music_directory != NULL &&
-      strcmp(last_music_directory, music_directory) == 0)
+      strEqual(last_music_directory, music_directory))
     return;    /* old and new music directory are the same */
 
   if (last_music_directory != NULL)
@@ -1910,7 +1792,7 @@ void LoadCustomMusic_NoConf(void)
   }
 
   if (draw_init_text)
-    DrawInitText("Loading music:", 120, FC_GREEN);
+    DrawInitText("Loading music", 120, FC_GREEN);
 
   while ((dir_entry = readdir(dir)) != NULL)   /* loop until last dir entry */
   {
@@ -1920,11 +1802,12 @@ void LoadCustomMusic_NoConf(void)
     boolean music_already_used = FALSE;
     int i;
 
-    for (i=0; i < num_music; i++)
+    /* skip all music files that are configured in music config file */
+    for (i = 0; i < num_music; i++)
     {
       struct FileInfo *music = getMusicListEntry(i);
 
-      if (strcmp(basename, music->filename) == 0)
+      if (strEqual(basename, music->filename))
       {
        music_already_used = TRUE;
        break;
@@ -1934,20 +1817,13 @@ void LoadCustomMusic_NoConf(void)
     if (music_already_used)
       continue;
 
-#if 0
-    if (FileIsSound(basename) || FileIsMusic(basename))
-      printf("DEBUG: loading music '%s' ...\n", basename);
-#endif
-
     if (draw_init_text)
       DrawInitText(basename, 150, FC_YELLOW);
 
     filename = getPath2(music_directory, basename);
 
-    if (FileIsSound(basename))
-      mus_info = Load_WAV(filename);
-    else if (FileIsMusic(basename))
-      mus_info = Load_MOD(filename);
+    if (FileIsMusic(basename))
+      mus_info = Load_WAV_or_MOD(filename);
 
     free(filename);
 
@@ -1963,10 +1839,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 +1914,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)
@@ -2063,7 +1935,7 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   sound_info->dynamic_file_list = NULL;
 
   sound_info->num_suffix_list_entries = 0;
-  for (i=0; config_suffix_list[i].token != NULL; i++)
+  for (i = 0; config_suffix_list[i].token != NULL; i++)
     sound_info->num_suffix_list_entries++;
 
   sound_info->suffix_list = config_suffix_list;
@@ -2071,23 +1943,23 @@ void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries,
   /* ---------- initialize base prefix and suffixes lists ---------- */
 
   sound_info->num_base_prefixes = 0;
-  for (i=0; base_prefixes[i] != NULL; i++)
+  for (i = 0; base_prefixes[i] != NULL; i++)
     sound_info->num_base_prefixes++;
 
   sound_info->num_ext1_suffixes = 0;
-  for (i=0; ext1_suffixes[i] != NULL; i++)
+  for (i = 0; ext1_suffixes[i] != NULL; i++)
     sound_info->num_ext1_suffixes++;
 
   sound_info->num_ext2_suffixes = 0;
-  for (i=0; ext2_suffixes[i] != NULL; i++)
+  for (i = 0; ext2_suffixes[i] != NULL; i++)
     sound_info->num_ext2_suffixes++;
 
   sound_info->num_ext3_suffixes = 0;
-  for (i=0; ext3_suffixes[i] != NULL; i++)
+  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++)
+  for (i = 0; ignore_tokens[i] != NULL; i++)
     sound_info->num_ignore_tokens++;
 
   sound_info->base_prefixes = base_prefixes;
@@ -2114,15 +1986,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
 }
 
 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)
@@ -2143,7 +2010,7 @@ void InitMusicList(struct ConfigInfo *config_list, int num_file_list_entries,
   music_info->dynamic_file_list = NULL;
 
   music_info->num_suffix_list_entries = 0;
-  for (i=0; config_suffix_list[i].token != NULL; i++)
+  for (i = 0; config_suffix_list[i].token != NULL; i++)
     music_info->num_suffix_list_entries++;
 
   music_info->suffix_list = config_suffix_list;
@@ -2151,23 +2018,23 @@ void InitMusicList(struct ConfigInfo *config_list, int num_file_list_entries,
   /* ---------- initialize base prefix and suffixes lists ---------- */
 
   music_info->num_base_prefixes = 0;
-  for (i=0; base_prefixes[i] != NULL; i++)
+  for (i = 0; base_prefixes[i] != NULL; i++)
     music_info->num_base_prefixes++;
 
   music_info->num_ext1_suffixes = 0;
-  for (i=0; ext1_suffixes[i] != NULL; i++)
+  for (i = 0; ext1_suffixes[i] != NULL; i++)
     music_info->num_ext1_suffixes++;
 
   music_info->num_ext2_suffixes = 0;
-  for (i=0; ext2_suffixes[i] != NULL; i++)
+  for (i = 0; ext2_suffixes[i] != NULL; i++)
     music_info->num_ext2_suffixes++;
 
   music_info->num_ext3_suffixes = 0;
-  for (i=0; ext3_suffixes[i] != NULL; i++)
+  for (i = 0; ext3_suffixes[i] != NULL; i++)
     music_info->num_ext3_suffixes++;
 
   music_info->num_ignore_tokens = 0;
-  for (i=0; ignore_tokens[i] != NULL; i++)
+  for (i = 0; ignore_tokens[i] != NULL; i++)
     music_info->num_ignore_tokens++;
 
   music_info->base_prefixes = base_prefixes;
@@ -2316,30 +2183,24 @@ void StopSoundExt(int nr, int state)
 static void ReloadCustomSounds()
 {
 #if 0
-  printf("DEBUG: reloading sounds '%s' ...\n", artwork.snd_current_identifier);
+  printf("::: reloading sounds '%s' ...\n", artwork.snd_current_identifier);
 #endif
 
   LoadArtworkConfig(sound_info);
   ReloadCustomArtworkList(sound_info);
-
-#if 0
-  num_sounds = getSoundListSize();
-#endif
 }
 
 static void ReloadCustomMusic()
 {
 #if 0
-  printf("DEBUG: reloading music '%s' ...\n", artwork.mus_current_identifier);
+  printf("::: reloading music '%s' ...\n", artwork.mus_current_identifier);
 #endif
 
   LoadArtworkConfig(music_info);
   ReloadCustomArtworkList(music_info);
 
-#if 1
   /* load all music files from directory not defined in "musicinfo.conf" */
   LoadCustomMusic_NoConf();
-#endif
 }
 
 void InitReloadCustomSounds(char *set_identifier)
@@ -2386,8 +2247,7 @@ void FreeSound(void *ptr)
 #endif
   }
 
-  if (sound->source_filename)
-    free(sound->source_filename);
+  checked_free(sound->source_filename);
 
   free(sound);
 }
@@ -2423,7 +2283,7 @@ static void FreeAllMusic_NoConf()
   if (Music_NoConf == NULL)
     return;
 
-  for(i=0; i < num_music_noconf; i++)
+  for (i = 0; i < num_music_noconf; i++)
     FreeMusic(Music_NoConf[i]);
 
   free(Music_NoConf);