projects
/
rocksndiamonds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rnd-20020424-1-src
[rocksndiamonds.git]
/
src
/
libgame
/
sound.c
diff --git
a/src/libgame/sound.c
b/src/libgame/sound.c
index e5aa69e224e5ae8105bd9e54d9416532a5afbeb8..744c4bd8900c0aaa0947b0a1ac64d42126f494ca 100644
(file)
--- a/
src/libgame/sound.c
+++ b/
src/libgame/sound.c
@@
-24,12
+24,9
@@
#include "setup.h"
#include "setup.h"
+static SoundInfo **Sound = NULL;
+static MusicInfo **Music = NULL;
static int num_sounds = 0, num_music = 0;
static int num_sounds = 0, num_music = 0;
-static struct SampleInfo *Sound = NULL;
-#if defined(TARGET_SDL)
-static int num_mods = 0;
-static struct SampleInfo *Mod = NULL;
-#endif
/* ========================================================================= */
/* ========================================================================= */
@@
-39,7
+36,7
@@
static int playing_sounds = 0;
static struct SoundControl playlist[MAX_SOUNDS_PLAYING];
static struct SoundControl emptySoundControl =
{
static struct SoundControl playlist[MAX_SOUNDS_PLAYING];
static struct SoundControl emptySoundControl =
{
- -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
0,0L,0L
,NULL
+ -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE, 0,0, 0
,NULL
};
#if defined(PLATFORM_UNIX)
};
#if defined(PLATFORM_UNIX)
@@
-178,7
+175,7
@@
void InitPlaylist(void)
{
int i;
{
int i;
- for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
+ for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
playlist[i] = emptySoundControl;
playing_sounds = 0;
}
playlist[i] = emptySoundControl;
playing_sounds = 0;
}
@@
-207,9
+204,9
@@
void SoundServer(void)
InitPlaylist();
stereo_volume[PSND_MAX_LEFT2RIGHT] = 0;
InitPlaylist();
stereo_volume[PSND_MAX_LEFT2RIGHT] = 0;
- for(i=0;
i<PSND_MAX_LEFT2RIGHT;
i++)
+ for(i=0;
i<PSND_MAX_LEFT2RIGHT;
i++)
stereo_volume[i] =
stereo_volume[i] =
- (int)sqrt((float)(PSND_MAX_LEFT2RIGHT
*PSND_MAX_LEFT2RIGHT-i*
i));
+ (int)sqrt((float)(PSND_MAX_LEFT2RIGHT
* PSND_MAX_LEFT2RIGHT - i *
i));
#if defined(PLATFORM_HPUX)
InitAudioDevice_HPUX();
#if defined(PLATFORM_HPUX)
InitAudioDevice_HPUX();
@@
-230,7
+227,7
@@
void SoundServer(void)
if (snd_ctrl.reload_sounds || snd_ctrl.reload_music)
{
if (snd_ctrl.reload_sounds || snd_ctrl.reload_music)
{
- for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
+ for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
playlist[i] = emptySoundControl;
playing_sounds = 0;
playlist[i] = emptySoundControl;
playing_sounds = 0;
@@
-251,16
+248,20
@@
void SoundServer(void)
if (!playing_sounds)
continue;
if (!playing_sounds)
continue;
- for(i=0;i<MAX_SOUNDS_PLAYING;i++)
- if (snd_ctrl.stop_all_sounds || playlist[i].nr == snd_ctrl.nr)
- playlist[i].fade_sound = TRUE;
+ if (snd_ctrl.music)
+ playlist[audio.music_channel].fade_sound = TRUE;
+ else
+ for(i=0; i<MAX_SOUNDS_PLAYING; i++)
+ if (snd_ctrl.stop_all_sounds ||
+ (i != audio.music_channel && playlist[i].nr == snd_ctrl.nr))
+ playlist[i].fade_sound = TRUE;
}
else if (snd_ctrl.stop_all_sounds)
{
if (!playing_sounds)
continue;
}
else if (snd_ctrl.stop_all_sounds)
{
if (!playing_sounds)
continue;
- for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
+ for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
playlist[i] = emptySoundControl;
playing_sounds = 0;
playlist[i] = emptySoundControl;
playing_sounds = 0;
@@
-271,12
+272,20
@@
void SoundServer(void)
if (!playing_sounds)
continue;
if (!playing_sounds)
continue;
- for(i=0;i<MAX_SOUNDS_PLAYING;i++)
- if (playlist[i].nr == snd_ctrl.nr)
+ if (snd_ctrl.music)
+ {
+ playlist[audio.music_channel] = emptySoundControl;
+ playing_sounds--;
+ }
+
+ for(i=0; i<MAX_SOUNDS_PLAYING; i++)
+ {
+ if (i != audio.music_channel && playlist[i].nr == snd_ctrl.nr)
{
playlist[i] = emptySoundControl;
playing_sounds--;
}
{
playlist[i] = emptySoundControl;
playing_sounds--;
}
+ }
if (!playing_sounds)
close(audio.device_fd);
if (!playing_sounds)
close(audio.device_fd);
@@
-325,20
+334,20
@@
void SoundServer(void)
continue;
/* get pointer and size of the actual sound sample */
continue;
/* get pointer and size of the actual sound sample */
- sample_ptr = playlist[i].data_ptr
+
playlist[i].playingpos;
- sample_size =
-
MIN(max_sample_size,playlist[i].data_len-
playlist[i].playingpos);
+ sample_ptr = playlist[i].data_ptr
+
playlist[i].playingpos;
+ sample_size =
MIN(max_sample_size,
+
playlist[i].data_len -
playlist[i].playingpos);
playlist[i].playingpos += sample_size;
/* fill the first mixing buffer with original sample */
playlist[i].playingpos += sample_size;
/* fill the first mixing buffer with original sample */
- memcpy(premix_first_buffer,
sample_ptr,
sample_size);
+ memcpy(premix_first_buffer,
sample_ptr,
sample_size);
/* are we about to restart a looping sound? */
/* are we about to restart a looping sound? */
- if (playlist[i].loop && sample_size
<
max_sample_size)
+ if (playlist[i].loop && sample_size
<
max_sample_size)
{
{
- playlist[i].playingpos = max_sample_size
-
sample_size;
- memcpy(premix_first_buffer
+
sample_size,
- playlist[i].data_ptr,
max_sample_size-
sample_size);
+ playlist[i].playingpos = max_sample_size
-
sample_size;
+ memcpy(premix_first_buffer
+
sample_size,
+ playlist[i].data_ptr,
max_sample_size -
sample_size);
sample_size = max_sample_size;
}
sample_size = max_sample_size;
}
@@
-349,7
+358,7
@@
void SoundServer(void)
/* adjust volume of actual sound sample */
if (playlist[i].volume != PSND_MAX_VOLUME)
/* adjust volume of actual sound sample */
if (playlist[i].volume != PSND_MAX_VOLUME)
- for(j=0;
j<sample_size;
j++)
+ for(j=0;
j<sample_size;
j++)
premix_first_buffer[j] =
(playlist[i].volume * (int)premix_first_buffer[j])
>> PSND_MAX_VOLUME_BITS;
premix_first_buffer[j] =
(playlist[i].volume * (int)premix_first_buffer[j])
>> PSND_MAX_VOLUME_BITS;
@@
-358,10
+367,10
@@
void SoundServer(void)
if (stereo)
{
int middle_pos = PSND_MAX_LEFT2RIGHT/2;
if (stereo)
{
int middle_pos = PSND_MAX_LEFT2RIGHT/2;
- int left_volume
= stereo_volume[middle_pos
+playlist[i].stereo];
- int right_volume = stereo_volume[middle_pos-playlist[i].stereo];
+ int left_volume
= stereo_volume[middle_pos
+playlist[i].stereo];
+ int right_volume = stereo_volume[middle_pos
-playlist[i].stereo];
- for(j=0;
j<sample_size;
j++)
+ for(j=0;
j<sample_size;
j++)
{
premix_left_buffer[j] =
(left_volume * (int)premix_first_buffer[j])
{
premix_left_buffer[j] =
(left_volume * (int)premix_first_buffer[j])
@@
-487,7
+496,9
@@
static void sound_handler(struct SoundControl snd_ctrl)
return;
for (i=0; i<MAX_SOUNDS_PLAYING; i++)
return;
for (i=0; i<MAX_SOUNDS_PLAYING; i++)
- if ((snd_ctrl.stop_all_sounds || playlist[i].nr == snd_ctrl.nr) &&
+ if ((snd_ctrl.stop_all_sounds ||
+ (i != audio.music_channel && playlist[i].nr == snd_ctrl.nr) ||
+ (i == audio.music_channel && snd_ctrl.music)) &&
!playlist[i].fade_sound)
{
playlist[i].fade_sound = TRUE;
!playlist[i].fade_sound)
{
playlist[i].fade_sound = TRUE;
@@
-506,7
+517,7
@@
static void sound_handler(struct SoundControl snd_ctrl)
{
if (!playing_sounds)
return;
{
if (!playing_sounds)
return;
- SoundServer_StopSound(snd_ctrl
.nr
);
+ SoundServer_StopSound(snd_ctrl);
}
for (i=0; i<MAX_SOUNDS_PLAYING; i++)
}
for (i=0; i<MAX_SOUNDS_PLAYING; i++)
@@
-534,12
+545,15
@@
static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl)
{
int i, k;
{
int i, k;
+ if (snd_ctrl.music)
+ snd_ctrl.nr = snd_ctrl.nr % num_music;
+
/* if playlist is full, remove oldest sound */
/* if playlist is full, remove oldest sound */
- if (playing_sounds
==
MAX_SOUNDS_PLAYING)
+ if (playing_sounds
==
MAX_SOUNDS_PLAYING)
{
{
- int longest
=0, longest_nr=
0;
+ int longest
= 0, longest_nr =
0;
- for
(i=0;i<MAX_SOUNDS_PLAYING;
i++)
+ for
(i=0; i<MAX_SOUNDS_PLAYING;
i++)
{
#if !defined(PLATFORM_MSDOS)
int actual = 100 * playlist[i].playingpos / playlist[i].data_len;
{
#if !defined(PLATFORM_MSDOS)
int actual = 100 * playlist[i].playingpos / playlist[i].data_len;
@@
-547,10
+561,10
@@
static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl)
int actual = playlist[i].playingpos;
#endif
int actual = playlist[i].playingpos;
#endif
- if (
!playlist[i].loop && actual>
longest)
+ if (
i != audio.music_channel && !playlist[i].loop && actual >
longest)
{
{
- longest
=
actual;
- longest_nr
=
i;
+ longest
=
actual;
+ longest_nr
=
i;
}
}
#if defined(PLATFORM_MSDOS)
}
}
#if defined(PLATFORM_MSDOS)
@@
-562,18
+576,17
@@
static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl)
}
/* check if sound is already being played (and how often) */
}
/* check if sound is already being played (and how often) */
- for(k=0,i=0;i<MAX_SOUNDS_PLAYING;i++)
- {
- if (playlist[i].nr == snd_ctrl.nr)
+ for (k=0,i=0; i<MAX_SOUNDS_PLAYING; i++)
+ if (i != audio.music_channel && playlist[i].nr == snd_ctrl.nr)
k++;
k++;
- }
/* restart loop sounds only if they are just fading out */
/* restart loop sounds only if they are just fading out */
- if (k
>=
1 && snd_ctrl.loop)
+ if (k
>=
1 && snd_ctrl.loop)
{
{
- for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
+ for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
{
{
- if (playlist[i].nr == snd_ctrl.nr && playlist[i].fade_sound)
+ if (i != audio.music_channel && playlist[i].nr == snd_ctrl.nr &&
+ playlist[i].fade_sound)
{
playlist[i].fade_sound = FALSE;
playlist[i].volume = PSND_MAX_VOLUME;
{
playlist[i].fade_sound = FALSE;
playlist[i].volume = PSND_MAX_VOLUME;
@@
-584,20
+597,23
@@
static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl)
#endif
}
}
#endif
}
}
+
return;
}
/* don't play sound more than n times simultaneously (with n == 2 for now) */
return;
}
/* don't play sound more than n times simultaneously (with n == 2 for now) */
- if (k
>=
2)
+ if (k
>=
2)
{
{
- int longest
=0, longest_nr=
0;
+ int longest
= 0, longest_nr =
0;
/* look for oldest equal sound */
/* look for oldest equal sound */
- for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
+ for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
{
int actual;
{
int actual;
- if (!playlist[i].active || playlist[i].nr != snd_ctrl.nr)
+ if (!playlist[i].active ||
+ i == audio.music_channel ||
+ playlist[i].nr != snd_ctrl.nr)
continue;
#if !defined(PLATFORM_MSDOS)
continue;
#if !defined(PLATFORM_MSDOS)
@@
-605,10
+621,10
@@
static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl)
#else
actual = playlist[i].playingpos;
#endif
#else
actual = playlist[i].playingpos;
#endif
- if (actual
>=
longest)
+ if (actual
>=
longest)
{
{
- longest
=
actual;
- longest_nr
=
i;
+ longest
=
actual;
+ longest_nr
=
i;
}
}
}
}
@@
-620,18
+636,27
@@
static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl)
playing_sounds--;
}
playing_sounds--;
}
- /*
neuen Sound in Liste packen
*/
- for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
+ /*
add new sound to playlist
*/
+ for(i=0;
i<MAX_SOUNDS_PLAYING;
i++)
{
{
- if (!playlist[i].active)
+ if (!playlist[i].active ||
+ (snd_ctrl.music && i == audio.music_channel))
{
{
+ SoundInfo *snd_info =
+ (snd_ctrl.music ? Music[snd_ctrl.nr] : Sound[snd_ctrl.nr]);
+
+ snd_ctrl.data_ptr = snd_info->data_ptr;
+ snd_ctrl.data_len = snd_info->data_len;
+
playlist[i] = snd_ctrl;
playing_sounds++;
#if defined(PLATFORM_MSDOS)
playlist[i] = snd_ctrl;
playing_sounds++;
#if defined(PLATFORM_MSDOS)
- playlist[i].voice = allocate_voice(Sound[snd_ctrl.nr].sample_ptr);
- if(snd_ctrl.loop)
+ playlist[i].voice = allocate_voice(playlist[i].data_ptr);
+
+ if (snd_ctrl.loop)
voice_set_playmode(playlist[i].voice, PLAYMODE_LOOP);
voice_set_playmode(playlist[i].voice, PLAYMODE_LOOP);
+
voice_set_volume(playlist[i].voice, snd_ctrl.volume);
voice_set_pan(playlist[i].voice, snd_ctrl.stereo);
voice_start(playlist[i].voice);
voice_set_volume(playlist[i].voice, snd_ctrl.volume);
voice_set_pan(playlist[i].voice, snd_ctrl.stereo);
voice_start(playlist[i].voice);
@@
-658,15
+683,18
@@
void SoundServer_FadeSound(int nr)
#if !defined(PLATFORM_WIN32)
#if defined(PLATFORM_MSDOS)
#if !defined(PLATFORM_WIN32)
#if defined(PLATFORM_MSDOS)
-static void SoundServer_StopSound(
int nr
)
+static void SoundServer_StopSound(
struct SoundControl snd_ctrl
)
{
{
+ int nr = snd_ctrl.nr;
int i;
if (!playing_sounds)
return;
int i;
if (!playing_sounds)
return;
- for(i=0;i<MAX_SOUNDS_PLAYING;i++)
- if (playlist[i].nr == nr)
+ for(i=0; i<MAX_SOUNDS_PLAYING; i++)
+ {
+ if ((i == audio.music_channel && snd_ctrl.music) ||
+ (i != audio.music_channel && playlist[i].nr == nr))
{
#if defined(PLATFORM_MSDOS)
voice_set_volume(playlist[i].voice, 0);
{
#if defined(PLATFORM_MSDOS)
voice_set_volume(playlist[i].voice, 0);
@@
-675,6
+703,7
@@
static void SoundServer_StopSound(int nr)
playlist[i] = emptySoundControl;
playing_sounds--;
}
playlist[i] = emptySoundControl;
playing_sounds--;
}
+ }
#if !defined(PLATFORM_MSDOS)
if (!playing_sounds)
#if !defined(PLATFORM_MSDOS)
if (!playing_sounds)
@@
-940,10
+969,9
@@
void ReloadMusic()
#define CHUNK_ID_LEN 4 /* IFF style chunk id length */
#define WAV_HEADER_SIZE 16 /* size of WAV file header */
#define CHUNK_ID_LEN 4 /* IFF style chunk id length */
#define WAV_HEADER_SIZE 16 /* size of WAV file header */
-static
boolean LoadSoundExt(char *sound_name, boolean is_music
)
+static
SoundInfo *Load_WAV(char *filename
)
{
{
- struct SampleInfo *snd_info;
- char *filename;
+ SoundInfo *snd_info;
#if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS)
byte sound_header_buffer[WAV_HEADER_SIZE];
char chunk_name[CHUNK_ID_LEN + 1];
#if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS)
byte sound_header_buffer[WAV_HEADER_SIZE];
char chunk_name[CHUNK_ID_LEN + 1];
@@
-953,39
+981,35
@@
static boolean LoadSoundExt(char *sound_name, boolean is_music)
#endif
if (!audio.sound_available)
#endif
if (!audio.sound_available)
- return
FALSE
;
+ return
NULL
;
- num_sounds++;
- Sound = checked_realloc(Sound, num_sounds * sizeof(struct SampleInfo));
+ snd_info = checked_calloc(sizeof(SoundInfo));
- snd_info = &Sound[num_sounds - 1];
- snd_info->data_len = 0;
- snd_info->data_ptr = NULL;
-#if 0
- snd_info->name = sound_name;
-#endif
+#if defined(TARGET_SDL)
- if (is_music)
- filename = getPath2(options.music_directory, sound_name);
- else
- filename = getStringCopy(sound_name);
+ if ((snd_info->data_ptr = Mix_LoadWAV(filename)) == NULL)
+ {
+ Error(ERR_WARN, "cannot read sound file '%s'", filename);
+ free(snd_info);
+ return NULL;
+ }
-#
if defined(TARGET_SDL
)
+#
elif defined(TARGET_ALLEGRO
)
- if ((snd_info->
mix_chunk = Mix_LoadWAV
(filename)) == NULL)
+ if ((snd_info->
data_ptr = load_sample
(filename)) == NULL)
{
Error(ERR_WARN, "cannot read sound file '%s'", filename);
{
Error(ERR_WARN, "cannot read sound file '%s'", filename);
- free(
filename
);
- return
FALSE
;
+ free(
snd_info
);
+ return
NULL
;
}
}
-#el
if defined(PLATFORM_UNIX)
+#el
se /* PLATFORM_UNIX */
if ((file = fopen(filename, MODE_READ)) == NULL)
{
Error(ERR_WARN, "cannot open sound file '%s'", filename);
if ((file = fopen(filename, MODE_READ)) == NULL)
{
Error(ERR_WARN, "cannot open sound file '%s'", filename);
- free(
filename
);
- return
FALSE
;
+ free(
snd_info
);
+ return
NULL
;
}
/* read chunk id "RIFF" */
}
/* read chunk id "RIFF" */
@@
-994,8
+1018,8
@@
static boolean LoadSoundExt(char *sound_name, boolean is_music)
{
Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename);
fclose(file);
{
Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename);
fclose(file);
- free(
filename
);
- return
FALSE
;
+ free(
snd_info
);
+ return
NULL
;
}
/* read "RIFF" type id "WAVE" */
}
/* read "RIFF" type id "WAVE" */
@@
-1004,17
+1028,12
@@
static boolean LoadSoundExt(char *sound_name, boolean is_music)
{
Error(ERR_WARN, "missing 'WAVE' type ID of sound file '%s'", filename);
fclose(file);
{
Error(ERR_WARN, "missing 'WAVE' type ID of sound file '%s'", filename);
fclose(file);
- free(
filename
);
- return
FALSE
;
+ free(
snd_info
);
+ return
NULL
;
}
while (getFileChunk(file, chunk_name, &chunk_size, BYTE_ORDER_LITTLE_ENDIAN))
{
}
while (getFileChunk(file, chunk_name, &chunk_size, BYTE_ORDER_LITTLE_ENDIAN))
{
-#if 0
- printf("DEBUG: file '%s', chunk id '%s', chunk size '%d' [%d]\n",
- filename, chunk_name, chunk_size, feof(file));
-#endif
-
if (strcmp(chunk_name, "fmt ") == 0)
{
/* read header information */
if (strcmp(chunk_name, "fmt ") == 0)
{
/* read header information */
@@
-1035,8
+1054,9
@@
static boolean LoadSoundExt(char *sound_name, boolean is_music)
{
Error(ERR_WARN,"cannot read 'data' chunk of sound file '%s'",filename);
fclose(file);
{
Error(ERR_WARN,"cannot read 'data' chunk of sound file '%s'",filename);
fclose(file);
- free(filename);
- return FALSE;
+ free(snd_info->data_ptr);
+ free(snd_info);
+ return NULL;
}
/* check for odd number of sample bytes (data chunk is word aligned) */
}
/* check for odd number of sample bytes (data chunk is word aligned) */
@@
-1052,116
+1072,119
@@
static boolean LoadSoundExt(char *sound_name, boolean is_music)
if (snd_info->data_ptr == NULL)
{
Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename);
if (snd_info->data_ptr == NULL)
{
Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename);
- free(
filename
);
- return
FALSE
;
+ free(
snd_info
);
+ return
NULL
;
}
for (i=0; i<snd_info->data_len; i++)
}
for (i=0; i<snd_info->data_len; i++)
- snd_info->data_ptr[i] = snd_info->data_ptr[i] ^ 0x80;
+ ((byte *)snd_info->data_ptr)[i] = ((byte *)snd_info->data_ptr)[i] ^ 0x80;
+
+#endif /* PLATFORM_UNIX */
-#else /* PLATFORM_MSDOS */
+ snd_info->type = SND_TYPE_WAV;
+ snd_info->source_filename = getStringCopy(filename);
- snd_info->sample_ptr = load_sample(filename);
- if (!snd_info->sample_ptr)
+ return snd_info;
+}
+
+SoundInfo *LoadCustomSound(char *basename)
+{
+ char *filename = getCustomSoundFilename(basename);
+
+ if (filename == NULL)
{
{
- Error(ERR_WARN, "cannot
read sound file '%s'", fil
ename);
+ Error(ERR_WARN, "cannot
find sound file '%s'", bas
ename);
return FALSE;
}
return FALSE;
}
-#endif
-
- free(filename);
-
- return TRUE;
+ return Load_WAV(filename);
}
}
-
boolean LoadSound(char *sound_name
)
+
void InitSoundList(int num_list_entries
)
{
{
- return LoadSoundExt(sound_name, FALSE);
+ Sound = checked_calloc(num_list_entries * sizeof(SoundInfo *));
+ num_sounds = num_list_entries;
}
}
-
boolean LoadCustomSound(char *basename
)
+
void LoadSoundToList(char *basename, int list_pos
)
{
{
- char *filename = getCustomSoundFilename(basename);
+ if (Sound == NULL || list_pos >= num_sounds)
+ return;
- if (filename == NULL)
- {
- Error(ERR_WARN, "cannot find sound file '%s' -- no sounds", filename);
- return FALSE;
- }
+ if (Sound[list_pos])
+ FreeSound(Sound[list_pos]);
-
return LoadSound(fil
ename);
+
Sound[list_pos] = LoadCustomSound(bas
ename);
}
}
-
boolean LoadMod(char *mod_
name)
+
static MusicInfo *Load_MOD(char *file
name)
{
#if defined(TARGET_SDL)
{
#if defined(TARGET_SDL)
- struct SampleInfo *mod_info;
- char *filename;
+ MusicInfo *mod_info;
- num_mods++;
- Mod = checked_realloc(Mod, num_mods * sizeof(struct SampleInfo));
-
- mod_info = &Mod[num_mods - 1];
- mod_info->name = mod_name;
+ if (!audio.sound_available)
+ return NULL;
-
filename = getPath2(options.music_directory, mod_info->name
);
+
mod_info = checked_calloc(sizeof(MusicInfo)
);
- if ((mod_info->
mix_music
= Mix_LoadMUS(filename)) == NULL)
+ if ((mod_info->
data_ptr
= Mix_LoadMUS(filename)) == NULL)
{
{
- Error(ERR_WARN, "cannot read music file '%s'
-- no music
", filename);
- free(
filename
);
- return
FALSE
;
+ Error(ERR_WARN, "cannot read music file '%s'", filename);
+ free(
mod_info
);
+ return
NULL
;
}
}
- free(filename);
+ mod_info->type = MUS_TYPE_MOD;
+ mod_info->source_filename = getStringCopy(filename);
- return
TRUE
;
+ return
mod_info
;
#else
#else
- return
FALSE
;
+ return
NULL
;
#endif
}
#endif
}
-
int Load
Music(void)
+
void LoadCustom
Music(void)
{
{
+ char *music_directory = getCustomMusicDirectory();
DIR *dir;
struct dirent *dir_entry;
DIR *dir;
struct dirent *dir_entry;
- int num_wav_music = 0;
- int num_mod_music = 0;
if (!audio.sound_available)
if (!audio.sound_available)
- return
0
;
+ return;
- if ((dir = opendir(
options.
music_directory)) == NULL)
+ if ((dir = opendir(music_directory)) == NULL)
{
{
- Error(ERR_WARN, "cannot read music directory '%s'",
- options.music_directory);
+ Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
audio.music_available = FALSE;
audio.music_available = FALSE;
- return
0
;
+ return;
}
while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
{
}
while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
{
- char *filename = dir_entry->d_name;
+ char *basename = dir_entry->d_name;
+ char *filename = getPath2(music_directory, basename);
+ MusicInfo *mus_info = NULL;
- if (FileIsSound(filename) && LoadSoundExt(filename, TRUE))
- num_wav_music++;
- else if (FileIsMusic(filename) && LoadMod(filename))
- num_mod_music++;
+ if (FileIsSound(filename))
+ mus_info = Load_WAV(filename);
+ else if (FileIsMusic(filename))
+ mus_info = Load_MOD(filename);
+
+ free(filename);
+
+ if (mus_info)
+ {
+ num_music++;
+ Music = checked_realloc(Music, num_music * sizeof(MusicInfo *));
+ Music[num_music -1] = mus_info;
+ }
}
closedir(dir);
}
closedir(dir);
- if (num_
wav_music == 0 && num_mod_
music == 0)
+ if (num_music == 0)
Error(ERR_WARN, "cannot find any valid music files in directory '%s'",
Error(ERR_WARN, "cannot find any valid music files in directory '%s'",
- options.music_directory);
-
- num_music = (num_mod_music > 0 ? num_mod_music : num_wav_music);
-
- audio.mods_available = (num_mod_music > 0);
- audio.music_available = (num_music > 0);
-
- return num_music;
+ music_directory);
}
void PlayMusic(int nr)
}
void PlayMusic(int nr)
@@
-1169,23
+1192,23
@@
void PlayMusic(int nr)
if (!audio.music_available)
return;
if (!audio.music_available)
return;
- if (!audio.mods_available)
- nr = num_sounds - num_music + nr;
-
#if defined(TARGET_SDL)
#if defined(TARGET_SDL)
- if (audio.mods_available) /* play MOD music */
+
+ if (Music[nr]->type == MUS_TYPE_MOD)
{
{
- Mix_PlayMusic(M
od[nr].mix_music
, -1);
+ Mix_PlayMusic(M
usic[nr]->data_ptr
, -1);
Mix_VolumeMusic(SOUND_MAX_VOLUME); /* must be _after_ Mix_PlayMusic()! */
}
else /* play WAV music loop */
{
Mix_Volume(audio.music_channel, SOUND_MAX_VOLUME);
Mix_VolumeMusic(SOUND_MAX_VOLUME); /* must be _after_ Mix_PlayMusic()! */
}
else /* play WAV music loop */
{
Mix_Volume(audio.music_channel, SOUND_MAX_VOLUME);
- Mix_PlayChannel(audio.music_channel,
Sound[nr].mix_chunk
, -1);
+ Mix_PlayChannel(audio.music_channel,
Music[nr]->data_ptr
, -1);
}
}
+
#else
#else
- audio.music_nr = nr;
- PlaySoundLoop(nr);
+
+ PlaySoundMusic(nr);
+
#endif
}
#endif
}
@@
-1204,7
+1227,12
@@
void PlaySoundLoop(int nr)
PlaySoundExt(nr, PSND_MAX_VOLUME, PSND_MIDDLE, PSND_LOOP);
}
PlaySoundExt(nr, PSND_MAX_VOLUME, PSND_MIDDLE, PSND_LOOP);
}
-void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
+void PlaySoundMusic(int nr)
+{
+ PlaySoundExt(nr, PSND_MAX_VOLUME, PSND_MIDDLE, PSND_MUSIC);
+}
+
+void PlaySoundExt(int nr, int volume, int stereo, boolean loop_type)
{
struct SoundControl snd_ctrl = emptySoundControl;
{
struct SoundControl snd_ctrl = emptySoundControl;
@@
-1213,27
+1241,31
@@
void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
audio.sound_deactivated)
return;
audio.sound_deactivated)
return;
- if (volume
<
PSND_MIN_VOLUME)
+ if (volume
<
PSND_MIN_VOLUME)
volume = PSND_MIN_VOLUME;
volume = PSND_MIN_VOLUME;
- else if (volume
>
PSND_MAX_VOLUME)
+ else if (volume
>
PSND_MAX_VOLUME)
volume = PSND_MAX_VOLUME;
volume = PSND_MAX_VOLUME;
- if (stereo
<
PSND_MAX_LEFT)
+ if (stereo
<
PSND_MAX_LEFT)
stereo = PSND_MAX_LEFT;
stereo = PSND_MAX_LEFT;
- else if (stereo
>
PSND_MAX_RIGHT)
+ else if (stereo
>
PSND_MAX_RIGHT)
stereo = PSND_MAX_RIGHT;
snd_ctrl.nr = nr;
snd_ctrl.volume = volume;
snd_ctrl.stereo = stereo;
stereo = PSND_MAX_RIGHT;
snd_ctrl.nr = nr;
snd_ctrl.volume = volume;
snd_ctrl.stereo = stereo;
- snd_ctrl.loop = loop;
+ snd_ctrl.loop = (loop_type != PSND_NO_LOOP);
+ snd_ctrl.music = (loop_type == PSND_MUSIC);
snd_ctrl.active = TRUE;
snd_ctrl.active = TRUE;
+
+#if 0
snd_ctrl.data_ptr = Sound[nr].data_ptr;
snd_ctrl.data_len = Sound[nr].data_len;
snd_ctrl.data_ptr = Sound[nr].data_ptr;
snd_ctrl.data_len = Sound[nr].data_len;
+#endif
#if defined(TARGET_SDL)
Mix_Volume(-1, SOUND_MAX_VOLUME);
#if defined(TARGET_SDL)
Mix_Volume(-1, SOUND_MAX_VOLUME);
- Mix_PlayChannel(-1, Sound[nr]
.mix_chunk, (loop
? -1 : 0));
+ Mix_PlayChannel(-1, Sound[nr]
->data_ptr, (loop_type
? -1 : 0));
#elif defined(PLATFORM_UNIX)
if (audio.soundserver_pid == 0) /* we are child process */
return;
#elif defined(PLATFORM_UNIX)
if (audio.soundserver_pid == 0) /* we are child process */
return;
@@
-1251,16
+1283,14
@@
void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
void FadeMusic(void)
{
void FadeMusic(void)
{
-#if defined(TARGET_SDL)
if (!audio.sound_available)
return;
if (!audio.sound_available)
return;
- if (audio.mods_available)
- Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
- else
- Mix_FadeOutChannel(audio.music_channel, SOUND_FADING_INTERVAL);
+#if defined(TARGET_SDL)
+ Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
+ Mix_FadeOutChannel(audio.music_channel, SOUND_FADING_INTERVAL);
#else
#else
-
FadeSound(audio.music_nr
);
+
StopSoundExt(-1, SSND_FADE_MUSIC
);
#endif
}
#endif
}
@@
-1272,7
+1302,7
@@
void FadeSound(int nr)
void FadeSounds()
{
FadeMusic();
void FadeSounds()
{
FadeMusic();
- StopSoundExt(-1, SSND_FADE_ALL
_SOUNDS
);
+ StopSoundExt(-1, SSND_FADE_ALL);
}
void StopMusic(void)
}
void StopMusic(void)
@@
-1281,12
+1311,10
@@
void StopMusic(void)
if (!audio.sound_available)
return;
if (!audio.sound_available)
return;
- if (audio.mods_available)
- Mix_HaltMusic();
- else
- Mix_HaltChannel(audio.music_channel);
+ Mix_HaltMusic();
+ Mix_HaltChannel(audio.music_channel);
#else
#else
- StopSound
(audio.music_nr
);
+ StopSound
Ext(-1, SSND_STOP_MUSIC
);
#endif
}
#endif
}
@@
-1297,7
+1325,7
@@
void StopSound(int nr)
void StopSounds()
{
void StopSounds()
{
- StopSoundExt(-1, SSND_STOP_ALL
_SOUNDS
);
+ StopSoundExt(-1, SSND_STOP_ALL);
}
void StopSoundExt(int nr, int method)
}
void StopSoundExt(int nr, int method)
@@
-1307,27
+1335,30
@@
void StopSoundExt(int nr, int method)
if (!audio.sound_available)
return;
if (!audio.sound_available)
return;
- if (
SSND_FADING(method)
)
+ if (
method & SSND_FADING
)
snd_ctrl.fade_sound = TRUE;
snd_ctrl.fade_sound = TRUE;
- if (
SSND_ALL(method)
)
+ if (
method & SSND_ALL
)
snd_ctrl.stop_all_sounds = TRUE;
else
{
snd_ctrl.stop_all_sounds = TRUE;
else
{
- snd_ctrl.nr = nr;
snd_ctrl.stop_sound = TRUE;
snd_ctrl.stop_sound = TRUE;
+ snd_ctrl.nr = nr;
}
}
+ if (method & SSND_MUSIC)
+ snd_ctrl.music = TRUE;
+
#if defined(TARGET_SDL)
#if defined(TARGET_SDL)
- if (
SSND_FADING(method)
)
+ if (
method & SSND_FADING
)
{
int i;
for (i=0; i<audio.channels; i++)
{
int i;
for (i=0; i<audio.channels; i++)
- if (i != audio.music_channel || snd_ctrl.
stop_all_sounds
)
+ if (i != audio.music_channel || snd_ctrl.
music
)
Mix_FadeOutChannel(i, SOUND_FADING_INTERVAL);
Mix_FadeOutChannel(i, SOUND_FADING_INTERVAL);
- if (snd_ctrl.
stop_all_sounds
)
+ if (snd_ctrl.
music
)
Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
}
else
Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
}
else
@@
-1335,9
+1366,9
@@
void StopSoundExt(int nr, int method)
int i;
for (i=0; i<audio.channels; i++)
int i;
for (i=0; i<audio.channels; i++)
- if (i != audio.music_channel || snd_ctrl.
stop_all_sounds
)
+ if (i != audio.music_channel || snd_ctrl.
music
)
Mix_HaltChannel(i);
Mix_HaltChannel(i);
- if (snd_ctrl.
stop_all_sounds
)
+ if (snd_ctrl.
music
)
Mix_HaltMusic();
}
Mix_HaltMusic();
}
@@
-1410,21
+1441,71
@@
void InitReloadMusic(char *set_name)
#endif
}
#endif
}
-void FreeSound
s(int num_sounds
)
+void FreeSound
(SoundInfo *sound
)
{
{
- int i;
+ if (sound == NULL)
+ return;
- if (!audio.sound_available)
+ if (sound->data_ptr)
+ {
+#if defined(TARGET_SDL)
+ Mix_FreeChunk(sound->data_ptr);
+#elif defined(TARGET_ALLEGRO)
+ destroy_sample(sound->data_ptr);
+#else /* PLATFORM_UNIX */
+ free(sound->data_ptr);
+#endif
+ }
+
+ free(sound);
+}
+
+void FreeMusic(MusicInfo *music)
+{
+ if (music == NULL)
return;
return;
- for(i=0; i<num_sounds; i++)
+ if (music->data_ptr)
+ {
#if defined(TARGET_SDL)
#if defined(TARGET_SDL)
- free(Sound[i].mix_chunk);
-#elif !defined(PLATFORM_MSDOS)
- free(Sound[i].data_ptr);
-#else
- destroy_sample(Sound[i].sample_ptr);
+ if (music->type == MUS_TYPE_MOD)
+ Mix_FreeMusic(music->data_ptr);
+ else
+ Mix_FreeChunk(music->data_ptr);
+#elif defined(TARGET_ALLEGRO)
+ destroy_sample(music->data_ptr);
+#else /* PLATFORM_UNIX */
+ free(music->data_ptr);
#endif
#endif
+ }
+
+ free(music);
+}
+
+void FreeAllSounds()
+{
+ int i;
+
+ if (Sound == NULL)
+ return;
+
+ for(i=0; i<num_sounds; i++)
+ FreeSound(Sound[i]);
+
+ free(Sound);
+}
+
+void FreeAllMusic()
+{
+ int i;
+
+ if (Music == NULL)
+ return;
+
+ for(i=0; i<num_music; i++)
+ FreeMusic(Music[i]);
+
+ free(Music);
}
/* THE STUFF ABOVE IS ONLY USED BY THE MAIN PROCESS */
}
/* THE STUFF ABOVE IS ONLY USED BY THE MAIN PROCESS */