/***********************************************************
* 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
{
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];
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
if (leveldir_current == NULL) /* should never happen */
Error(ERR_EXIT, "leveldir_current == NULL");
- memset(&snd_ctrl, 0, sizeof(SoundControl)); /* to make valgrind happy */
+ clear_mem(&snd_ctrl, sizeof(SoundControl)); /* to make valgrind happy */
snd_ctrl.active = FALSE;
snd_ctrl.state = type;
&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);
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 ||
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 */
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;
/* 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;
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))
{
{
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);
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)
{
{
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--;
}
/* print some debugging information about audio channel usage */
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
/* add the new sound to the mixer */
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)
{
max_sample_size = fragment_size / (num_output_channels * sample_bytes);
/* first clear the last premixing buffer */
- memset(premix_last_buffer, 0,
- max_sample_size * num_output_channels * sizeof(long));
+ clear_mem(premix_last_buffer,
+ max_sample_size * num_output_channels * sizeof(long));
for (i = 0; i < audio.num_channels; i++)
{
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++)
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)
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)
/* 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);
/* 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);
while (getFileChunkLE(file, chunk_name, &chunk_size))
{
- if (strcmp(chunk_name, "fmt ") == 0)
+ if (strEqual(chunk_name, "fmt "))
{
if (chunk_size < WAV_HEADER_SIZE)
{
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;
struct dirent *dir_entry;
int num_music = getMusicListSize();
-#if 0
- int ii;
- for (ii = 0; ii < num_music; ii++)
- {
- struct FileInfo *music = getMusicListEntry(ii);
- printf("sound process: music %d: '%s'\n", ii, music->filename);
- }
-#endif
-
if (!audio.sound_available)
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)
}
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 */
{
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);
-#if 0
- printf("sound process: '%s'\n", music->filename);
-#endif
-
- if (strcmp(basename, music->filename) == 0)
+ if (strEqual(basename, music->filename))
{
music_already_used = TRUE;
break;
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 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);
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()
}
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)
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)
else if (stereo_position > SOUND_MAX_RIGHT)
stereo_position = SOUND_MAX_RIGHT;
- memset(&snd_ctrl, 0, sizeof(SoundControl)); /* to make valgrind happy */
+ clear_mem(&snd_ctrl, sizeof(SoundControl)); /* to make valgrind happy */
snd_ctrl.active = TRUE;
snd_ctrl.nr = nr;
if (!audio.sound_available)
return;
- memset(&snd_ctrl, 0, sizeof(SoundControl)); /* to make valgrind happy */
+ clear_mem(&snd_ctrl, sizeof(SoundControl)); /* to make valgrind happy */
snd_ctrl.active = FALSE;
snd_ctrl.nr = nr;
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)
#endif
}
- if (sound->source_filename)
- free(sound->source_filename);
+ checked_free(sound->source_filename);
free(sound);
}