static long max_sample_size = 0;
static long fragment_size = DEFAULT_AUDIO_FRAGMENT_SIZE;
int sample_rate = DEFAULT_AUDIO_SAMPLE_RATE;
- boolean stereo = TRUE;
+ static boolean stereo = TRUE;
if (playing_sounds ||
(audio.device_fd = OpenAudioDevice(audio.device_name)) >= 0)
static boolean LoadSoundExt(char *sound_name, boolean is_music)
{
struct SampleInfo *snd_info;
- char filename[256];
+ char *filename;
#if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS)
byte sound_header_buffer[WAV_HEADER_SIZE];
char chunk[CHUNK_ID_LEN + 1];
snd_info = &Sound[num_sounds - 1];
snd_info->name = sound_name;
- sprintf(filename, "%s/%s/%s", options.ro_base_directory,
- (is_music ? MUSIC_DIRECTORY : SOUNDS_DIRECTORY), snd_info->name);
+ filename = getPath2((is_music ? options.music_directory :
+ options.sounds_directory), snd_info->name);
#if defined(TARGET_SDL)
if ((snd_info->mix_chunk = Mix_LoadWAV(filename)) == NULL)
{
Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename);
+ free(filename);
return FALSE;
}
if ((file = fopen(filename, MODE_READ)) == NULL)
{
Error(ERR_WARN, "cannot open sound file '%s' -- no sounds", filename);
+ free(filename);
return FALSE;
}
{
Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename);
fclose(file);
+ free(filename);
return FALSE;
}
{
Error(ERR_WARN, "missing 'WAVE' chunk of sound file '%s'", filename);
fclose(file);
+ free(filename);
return FALSE;
}
{
Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename);
fclose(file);
+ free(filename);
return FALSE;
}
{
Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename);
fclose(file);
+ free(filename);
return FALSE;
}
#endif
+ free(filename);
+
return TRUE;
}
{
#if defined(TARGET_SDL)
struct SampleInfo *mod_info;
- char filename[256];
+ char *filename;
num_mods++;
Mod = checked_realloc(Mod, num_mods * sizeof(struct SampleInfo));
mod_info = &Mod[num_mods - 1];
mod_info->name = mod_name;
- sprintf(filename, "%s/%s/%s", options.ro_base_directory,
- MUSIC_DIRECTORY, mod_info->name);
+ filename = getPath2(options.music_directory, mod_info->name);
if ((mod_info->mix_music = Mix_LoadMUS(filename)) == NULL)
{
Error(ERR_WARN, "cannot read music file '%s' -- no music", filename);
+ free(filename);
return FALSE;
}
+ free(filename);
+
return TRUE;
#else
return FALSE;
{
DIR *dir;
struct dirent *dir_entry;
- char *music_directory = getPath2(options.ro_base_directory, MUSIC_DIRECTORY);
int num_wav_music = 0;
int num_mod_music = 0;
if (!audio.sound_available)
return 0;
- if ((dir = opendir(music_directory)) == NULL)
+ if ((dir = opendir(options.music_directory)) == NULL)
{
- Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+ Error(ERR_WARN, "cannot read music directory '%s'",
+ options.music_directory);
audio.music_available = FALSE;
- free(music_directory);
return 0;
}
{
char *filename = dir_entry->d_name;
- if (strlen(filename) > 4 &&
- strcmp(&filename[strlen(filename) - 4], ".wav") == 0)
- {
- if (LoadSoundExt(filename, TRUE))
- num_wav_music++;
- }
- else if (strlen(filename) > 4 &&
- (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 ||
- strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 ||
- strncmp(filename, "mod.", 4) == 0 ||
- strncmp(filename, "MOD.", 4) == 0))
- {
- if (LoadMod(filename))
- num_mod_music++;
- }
+ if (FileIsSound(filename) && LoadSoundExt(filename, TRUE))
+ num_wav_music++;
+ else if (FileIsMusic(filename) && LoadMod(filename))
+ num_mod_music++;
}
closedir(dir);
if (num_wav_music == 0 && num_mod_music == 0)
Error(ERR_WARN, "cannot find any valid music files in directory '%s'",
- music_directory);
-
- free(music_directory);
+ options.music_directory);
num_music = (num_mod_music > 0 ? num_mod_music : num_wav_music);