From 9c38ec686f1a4592f52ee56d7ed4336299c8c5c9 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 6 Sep 2005 22:39:43 +0000 Subject: Restore -nosound, -nosfx, -nomusic Subversion-branch: /trunk/chocolate-doom Subversion-revision: 80 --- src/i_sound.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/i_system.c | 8 ++++-- 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/src/i_sound.c b/src/i_sound.c index a2cbf9c5..2075be51 100644 --- a/src/i_sound.c +++ b/src/i_sound.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: i_sound.c 79 2005-09-06 21:40:28Z fraggle $ +// $Id: i_sound.c 80 2005-09-06 22:39:43Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.16 2005/09/06 22:39:43 fraggle +// Restore -nosound, -nosfx, -nomusic +// // Revision 1.15 2005/09/06 21:40:28 fraggle // Setting music volume // @@ -80,7 +83,7 @@ //----------------------------------------------------------------------------- static const char -rcsid[] = "$Id: i_sound.c 79 2005-09-06 21:40:28Z fraggle $"; +rcsid[] = "$Id: i_sound.c 80 2005-09-06 22:39:43Z fraggle $"; #include #include @@ -105,9 +108,10 @@ rcsid[] = "$Id: i_sound.c 79 2005-09-06 21:40:28Z fraggle $"; #define NUM_CHANNELS 16 -static int sound_initialised = 0; +static boolean sound_initialised = false; static Mix_Chunk sound_chunks[NUMSFX]; + static byte *expand_sound_data(byte *data, int samplerate, int length) { byte *result = data; @@ -249,7 +253,12 @@ I_StartSound int pitch, int priority ) { - Mix_Chunk *chunk = getsfx(id); + Mix_Chunk *chunk; + + if (!sound_initialised) + return 0; + + chunk = getsfx(id); // play sound @@ -266,12 +275,17 @@ I_StartSound void I_StopSound (int handle) { + if (!sound_initialised) + return; Mix_HaltChannel(handle); } int I_SoundIsPlaying(int handle) { + if (!sound_initialised) + return false; + return Mix_Playing(handle); } @@ -320,6 +334,9 @@ I_UpdateSoundParams { int left, right; + if (!sound_initialised) + return; + left = ((254 - sep) * vol) / 15; right = ((sep) * vol) / 15; @@ -340,12 +357,16 @@ void I_ShutdownSound(void) - - - void I_InitSound() { + // If music or sound is going to play, we need to at least + // initialise SDL + + if (M_CheckParm("-nosound") + || (M_CheckParm("-nosfx") && M_CheckParm("-nomusic"))) + return; + if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Unable to set up sound.\n"); @@ -359,9 +380,14 @@ I_InitSound() Mix_AllocateChannels(NUM_CHANNELS); - sound_initialised = 1; - SDL_PauseAudio(0); + + if (M_CheckParm("-nosound") || M_CheckParm("-nosfx")) + return; + + sound_initialised = true; + + } @@ -372,8 +398,21 @@ I_InitSound() // Still no music done. // Remains. Dummies. // -void I_InitMusic(void) { } -void I_ShutdownMusic(void) { } + +static int music_initialised; + +void I_InitMusic(void) +{ + if (M_CheckParm("-nomusic") || M_CheckParm("-nosound")) + return; + + music_initialised = true; +} + +void I_ShutdownMusic(void) +{ + music_initialised = false; +} static int looping=0; static int musicdies=-1; @@ -383,6 +422,9 @@ void I_PlaySong(void *handle, int looping) Mix_Music *music = (Mix_Music *) handle; int loops; + if (!music_initialised) + return; + if (handle == NULL) return; @@ -396,16 +438,25 @@ void I_PlaySong(void *handle, int looping) void I_PauseSong (void *handle) { + if (!music_initialised) + return; + Mix_PauseMusic(); } void I_ResumeSong (void *handle) { + if (!music_initialised) + return; + Mix_ResumeMusic(); } void I_StopSong(void *handle) { + if (!music_initialised) + return; + Mix_HaltMusic(); } @@ -413,6 +464,9 @@ void I_UnRegisterSong(void *handle) { Mix_Music *music = (Mix_Music *) handle; + if (!music_initialised) + return; + if (handle == NULL) return; @@ -426,6 +480,9 @@ void *I_RegisterSong(void *data, int len) MIDI *mididata; UBYTE *mid; int midlen; + + if (!music_initialised) + return NULL; #ifdef _WIN32 sprintf(filename, "doom.mid"); @@ -475,6 +532,9 @@ void *I_RegisterSong(void *data, int len) // Is the song playing? int I_QrySongPlaying(void *handle) { + if (!music_initialised) + return false; + return Mix_PlayingMusic(); } diff --git a/src/i_system.c b/src/i_system.c index 34f46b5e..93824e04 100644 --- a/src/i_system.c +++ b/src/i_system.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: i_system.c 37 2005-08-04 18:42:15Z fraggle $ +// $Id: i_system.c 80 2005-09-06 22:39:43Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.8 2005/09/06 22:39:43 fraggle +// Restore -nosound, -nosfx, -nomusic +// // Revision 1.7 2005/08/04 18:42:15 fraggle // Silence compiler warnings // @@ -49,7 +52,7 @@ //----------------------------------------------------------------------------- static const char -rcsid[] = "$Id: i_system.c 37 2005-08-04 18:42:15Z fraggle $"; +rcsid[] = "$Id: i_system.c 80 2005-09-06 22:39:43Z fraggle $"; #include @@ -136,6 +139,7 @@ int I_GetTime (void) void I_Init (void) { I_InitSound(); + I_InitMusic(); // initialise timer -- cgit v1.2.3