|
|
@ -1,16 +1,55 @@
|
|
|
|
/* $Id: sound.c,v 1.2 2003/07/29 23:20:14 stpohle Exp $ */
|
|
|
|
/* $Id: sound.c,v 1.3 2003/08/06 19:29:10 stpohle Exp $ */
|
|
|
|
/* sound */
|
|
|
|
/* sound */
|
|
|
|
|
|
|
|
|
|
|
|
#include "sound.h"
|
|
|
|
#include "sound.h"
|
|
|
|
|
|
|
|
|
|
|
|
_snd snd;
|
|
|
|
_snd snd;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* display the sound options */
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
snd_options () {
|
|
|
|
|
|
|
|
int menuselect = 0;
|
|
|
|
|
|
|
|
_menu menu[] = {
|
|
|
|
|
|
|
|
{1, "Music Play"},
|
|
|
|
|
|
|
|
{1, "Sound Play"},
|
|
|
|
|
|
|
|
{2, "Return To Main Menu"},
|
|
|
|
|
|
|
|
{-1, ""}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (menuselect != -1 && bman.state != GS_quit) {
|
|
|
|
|
|
|
|
if (snd.playmusic)
|
|
|
|
|
|
|
|
sprintf (menu[0].text, "Music Play ON");
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sprintf (menu[0].text, "Music Play OFF");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (snd.playsound)
|
|
|
|
|
|
|
|
sprintf (menu[1].text, "Sound Play ON");
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sprintf (menu[1].text, "Sound Play OFF");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menuselect = menu_loop ("Audio Options", menu, menuselect);
|
|
|
|
|
|
|
|
switch (menuselect) {
|
|
|
|
|
|
|
|
case (0): // Play Music
|
|
|
|
|
|
|
|
snd.playmusic = 1-snd.playmusic;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (1): // Play Sound
|
|
|
|
|
|
|
|
snd.playsound = 1-snd.playsound;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (2):
|
|
|
|
|
|
|
|
menuselect = -1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* play an soundsample SND_* */
|
|
|
|
/* play an soundsample SND_* */
|
|
|
|
void
|
|
|
|
void
|
|
|
|
snd_play (int samplenr)
|
|
|
|
snd_play (int samplenr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
if (samplenr < SND_max && snd.inited && snd.sample[samplenr] != NULL)
|
|
|
|
if (samplenr < SND_max && snd.inited && snd.sample[samplenr] != NULL && snd.playsound)
|
|
|
|
Mix_PlayChannel (-1, snd.sample[samplenr], 0);
|
|
|
|
Mix_PlayChannel (-1, snd.sample[samplenr], 0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -21,7 +60,7 @@ void
|
|
|
|
snd_music_start ()
|
|
|
|
snd_music_start ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
if (snd.inited && snd.music != NULL)
|
|
|
|
if (snd.inited && snd.music != NULL && snd.playmusic)
|
|
|
|
Mix_PlayMusic (snd.music, -1);
|
|
|
|
Mix_PlayMusic (snd.music, -1);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -41,19 +80,15 @@ void
|
|
|
|
snd_init ()
|
|
|
|
snd_init ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
int audio_rate = 22050;
|
|
|
|
if (Mix_OpenAudio (snd.audio_rate, snd.audio_format, snd.audio_channels, 1024) < 0) {
|
|
|
|
Uint16 audio_format = AUDIO_S16;
|
|
|
|
|
|
|
|
int audio_channels = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, 1024) < 0) {
|
|
|
|
|
|
|
|
d_printf ("Couldn't open audio mixer: %s\n", SDL_GetError ());
|
|
|
|
d_printf ("Couldn't open audio mixer: %s\n", SDL_GetError ());
|
|
|
|
snd.inited = 0;
|
|
|
|
snd.inited = 0;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
|
|
|
|
Mix_QuerySpec (&snd.audio_rate, &snd.audio_format, &snd.audio_channels);
|
|
|
|
d_printf ("Opened audio at %d Hz %d bit %s\n",
|
|
|
|
d_printf ("Opened audio at %d Hz %d bit %s\n",
|
|
|
|
audio_rate, (audio_format & 0xFF), (audio_channels > 1 ? "stereo" : "mono"));
|
|
|
|
snd.audio_rate, (snd.audio_format & 0xFF), (snd.audio_channels > 1 ? "stereo" : "mono"));
|
|
|
|
|
|
|
|
|
|
|
|
Mix_Volume (-1, 96);
|
|
|
|
Mix_Volume (-1, 96);
|
|
|
|
Mix_VolumeMusic (48);
|
|
|
|
Mix_VolumeMusic (48);
|
|
|
@ -64,6 +99,15 @@ snd_init ()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
snd_shutdown () {
|
|
|
|
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
|
|
|
|
Mix_CloseAudio ();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* load the audio files */
|
|
|
|
/* load the audio files */
|
|
|
|
void
|
|
|
|
void
|
|
|
|
snd_load (char *tilesetname)
|
|
|
|
snd_load (char *tilesetname)
|
|
|
@ -71,8 +115,8 @@ snd_load (char *tilesetname)
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
#if HAVE_SDL_MIXER
|
|
|
|
char fullname[LEN_PATHFILENAME];
|
|
|
|
char fullname[LEN_PATHFILENAME];
|
|
|
|
char filename[LEN_FILENAME];
|
|
|
|
char filename[LEN_FILENAME];
|
|
|
|
|
|
|
|
_direntry *destart, *de, *desel;
|
|
|
|
int i;
|
|
|
|
int i, max, sel;
|
|
|
|
|
|
|
|
|
|
|
|
// load samples
|
|
|
|
// load samples
|
|
|
|
d_printf ("Loading Audioset\n");
|
|
|
|
d_printf ("Loading Audioset\n");
|
|
|
@ -99,8 +143,25 @@ snd_load (char *tilesetname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* random selection of an sound file */
|
|
|
|
|
|
|
|
sprintf (fullname, "%s/music", bman.datapath);
|
|
|
|
|
|
|
|
desel = destart = s_getdir (fullname);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (max = 0, de = destart; de != NULL; de = de->next)
|
|
|
|
|
|
|
|
if (de->name[0] != '.' && (de->flags & DF_file) == DF_file)
|
|
|
|
|
|
|
|
max++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sel = s_random (max);
|
|
|
|
|
|
|
|
for (max = 0, de = destart; max <= sel && de != NULL; de = de->next)
|
|
|
|
|
|
|
|
if (de->name[0] != '.' && (de->flags & DF_file) == DF_file) {
|
|
|
|
|
|
|
|
desel = de;
|
|
|
|
|
|
|
|
max++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* try loading the music from the tileset or the default */
|
|
|
|
/* try loading the music from the tileset or the default */
|
|
|
|
sprintf (fullname, "%s/music/bc-by-digital_d.xm", bman.datapath);
|
|
|
|
sprintf (fullname, "%s/music/%s", bman.datapath, desel->name);
|
|
|
|
|
|
|
|
printf ("Musikdatei: %s\n", fullname);
|
|
|
|
if ((snd.music = Mix_LoadMUS (fullname)) == NULL)
|
|
|
|
if ((snd.music = Mix_LoadMUS (fullname)) == NULL)
|
|
|
|
d_printf ("Couldn't load %s: %s\n", fullname, SDL_GetError ());
|
|
|
|
d_printf ("Couldn't load %s: %s\n", fullname, SDL_GetError ());
|
|
|
|
|
|
|
|
|
|
|
|