From 5cb2d9c62f782577d0a1e526b8f68e18a552894a Mon Sep 17 00:00:00 2001 From: stpohle Date: Wed, 6 Aug 2003 19:29:10 +0000 Subject: [PATCH] sound option added music can be switched on off ... music will be played randomly --- src/configuration.c | 28 ++++++++++++++- src/sound.c | 87 ++++++++++++++++++++++++++++++++++++++------- src/sound.h | 10 +++++- 3 files changed, 110 insertions(+), 15 deletions(-) diff --git a/src/configuration.c b/src/configuration.c index 724bb64..b868180 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -57,9 +57,14 @@ game_init (int argc, char **argv) map.map[0] = 0; map.map_selection = 2; bman.firewall = 0; - bman.broadcasted_chat = 0; + bman.broadcasted_chat = 1; bman.ai_players = 1; snd.inited = 0; + snd.audio_rate = 22050; + snd.audio_format = AUDIO_S16; + snd.audio_channels = 2; + snd.playmusic = 1; + snd.playsound = 1; map.bombs = GAME_SPECIAL_ITEMBOMB; map.fire = GAME_SPECIAL_ITEMFIRE; map.shoes = GAME_SPECIAL_ITEMSHOE; @@ -230,6 +235,21 @@ ReadConfig () if (!strcmp (keyword, "randomtileset")) { map.random_tileset = atoi (value); } + if(!strcmp (keyword, "sndrate")) { + snd.audio_rate = atoi (value); + } + if (!strcmp (keyword, "sndchannels")) { + snd.audio_channels = atoi (value); + } + if (!strcmp (keyword, "sndformat")) { + snd.audio_format = atoi (value); + } + if (!strcmp (keyword, "sndplaymusic")) { + snd.playmusic = atoi (value); + } + if (!strcmp (keyword, "sndplaysound")) { + snd.playsound = atoi (value); + } for (i = 0; i < MAX_SERVERENTRYS; i++) { sprintf (key2, "ip%d", i); if (!strcmp (keyword, key2)) { @@ -278,6 +298,11 @@ WriteConfig () fprintf (config, "bitsperpixel=%d\n", gfx.bpp); fprintf (config, "randomtileset=%d\n", map.random_tileset); fprintf (config, "mapselection=%d\n", map.map_selection); + fprintf (config, "sndrate=%d\n", snd.audio_rate); + fprintf (config, "sndchannels=%d\n", snd.audio_channels); + fprintf (config, "sndformat=%d\n", snd.audio_format); + fprintf (config, "sndplaymusic=%d\n", snd.playmusic); + fprintf (config, "sndplaysound=%d\n", snd.playsound); fclose (config); return 0; } @@ -411,6 +436,7 @@ configuration () break; case (2): // Sound Options + snd_options (); break; case (3): // Map Options diff --git a/src/sound.c b/src/sound.c index 1289347..81cae68 100644 --- a/src/sound.c +++ b/src/sound.c @@ -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 */ #include "sound.h" _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_* */ void snd_play (int samplenr) { #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); #endif }; @@ -21,7 +60,7 @@ void snd_music_start () { #if HAVE_SDL_MIXER - if (snd.inited && snd.music != NULL) + if (snd.inited && snd.music != NULL && snd.playmusic) Mix_PlayMusic (snd.music, -1); #endif }; @@ -41,19 +80,15 @@ void snd_init () { #if HAVE_SDL_MIXER - int audio_rate = 22050; - Uint16 audio_format = AUDIO_S16; - int audio_channels = 2; - - if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, 1024) < 0) { + if (Mix_OpenAudio (snd.audio_rate, snd.audio_format, snd.audio_channels, 1024) < 0) { d_printf ("Couldn't open audio mixer: %s\n", SDL_GetError ()); snd.inited = 0; 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", - 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_VolumeMusic (48); @@ -64,6 +99,15 @@ snd_init () }; +void +snd_shutdown () { +#if HAVE_SDL_MIXER + Mix_CloseAudio (); +#endif + return; +}; + + /* load the audio files */ void snd_load (char *tilesetname) @@ -71,8 +115,8 @@ snd_load (char *tilesetname) #if HAVE_SDL_MIXER char fullname[LEN_PATHFILENAME]; char filename[LEN_FILENAME]; - - int i; + _direntry *destart, *de, *desel; + int i, max, sel; // load samples 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 */ - 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) d_printf ("Couldn't load %s: %s\n", fullname, SDL_GetError ()); diff --git a/src/sound.h b/src/sound.h index c20130e..6f0aa92 100644 --- a/src/sound.h +++ b/src/sound.h @@ -1,4 +1,4 @@ -/* $Id: sound.h,v 1.2 2003/07/25 22:01:15 patty21 Exp $ */ +/* $Id: sound.h,v 1.3 2003/08/06 19:29:10 stpohle Exp $ */ /* include file for the sound */ #ifndef _SOUND_H_ @@ -26,6 +26,12 @@ struct __snd { Mix_Chunk *sample[SND_max]; // henqvist Mix_Music *music; // henqvist + + int audio_rate; + Uint16 audio_format; + int audio_channels; + signed char playmusic; + signed char playsound; } typedef _snd; @@ -37,5 +43,7 @@ void snd_music_stop(); void snd_init(); void snd_load(char *tilesetname); void snd_free (); +void snd_options (); +void snd_shutdown (); #endif