From a3bdc179949956d759d1f866f86a25da44d378a3 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 8 Sep 2008 00:27:06 +0000 Subject: Move s_sound.[ch] to doom/ Subversion-branch: /branches/raven-branch Subversion-revision: 1213 --- src/Makefile.am | 1 - src/doom/Makefile.am | 1 + src/doom/s_sound.c | 671 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/doom/s_sound.h | 96 ++++++++ src/i_sdlmusic.c | 2 +- src/i_sound.c | 4 + src/s_sound.c | 675 --------------------------------------------------- src/s_sound.h | 96 -------- 8 files changed, 773 insertions(+), 773 deletions(-) create mode 100644 src/doom/s_sound.c create mode 100644 src/doom/s_sound.h delete mode 100644 src/s_sound.c delete mode 100644 src/s_sound.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 5f5f8f3e..f3ebfbbe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,6 @@ m_misc.c m_misc.h \ md5.c md5.h \ memio.c memio.h \ m_random.c m_random.h \ -s_sound.c s_sound.h \ tables.c tables.h \ v_video.c v_video.h \ v_patch.h \ diff --git a/src/doom/Makefile.am b/src/doom/Makefile.am index a24aa7f2..44162e48 100644 --- a/src/doom/Makefile.am +++ b/src/doom/Makefile.am @@ -54,6 +54,7 @@ r_segs.c r_segs.h \ r_sky.c r_sky.h \ r_state.h \ r_things.c r_things.h \ +s_sound.c s_sound.h \ sounds.c sounds.h \ st_lib.c st_lib.h \ st_stuff.c st_stuff.h \ diff --git a/src/doom/s_sound.c b/src/doom/s_sound.c new file mode 100644 index 00000000..964ed27f --- /dev/null +++ b/src/doom/s_sound.c @@ -0,0 +1,671 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 1993-1996 Id Software, Inc. +// Copyright(C) 2005 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: none +// +//----------------------------------------------------------------------------- + +#include +#include + +#include "i_sound.h" +#include "i_system.h" + +#include "doomfeatures.h" +#include "deh_str.h" + +#include "doomstat.h" +#include "doomtype.h" + +#include "sounds.h" +#include "s_sound.h" + +#include "m_random.h" +#include "m_argv.h" + +#include "p_local.h" +#include "w_wad.h" +#include "z_zone.h" + +// when to clip out sounds +// Does not fit the large outdoor areas. + +#define S_CLIPPING_DIST (1200 * FRACUNIT) + +// Distance tp origin when sounds should be maxed out. +// This should relate to movement clipping resolution +// (see BLOCKMAP handling). +// In the source code release: (160*FRACUNIT). Changed back to the +// Vanilla value of 200 (why was this changed?) + +#define S_CLOSE_DIST (200 * FRACUNIT) + +// The range over which sound attenuates + +#define S_ATTENUATOR ((S_CLIPPING_DIST - S_CLOSE_DIST) >> FRACBITS) + +// Stereo separation + +#define S_STEREO_SWING (96 * FRACUNIT) + +#define NORM_PITCH 128 +#define NORM_PRIORITY 64 +#define NORM_SEP 128 + +typedef struct +{ + // sound information (if null, channel avail.) + sfxinfo_t *sfxinfo; + + // origin of sound + mobj_t *origin; + + // handle of the sound being played + int handle; + +} channel_t; + +// The set of channels available + +static channel_t *channels; + +// Maximum volume of a sound effect. +// Internal default is max out of 0-15. + +int sfxVolume = 8; + +// Maximum volume of music. + +int musicVolume = 8; + +// Internal volume level, ranging from 0-127 + +static int snd_SfxVolume; + +// Whether songs are mus_paused + +static boolean mus_paused; + +// Music currently being played + +static musicinfo_t *mus_playing = NULL; + +// Number of channels to use + +int numChannels = 8; + +// +// Initializes sound stuff, including volume +// Sets channels, SFX and music volume, +// allocates channel buffer, sets S_sfx lookup. +// + +void S_Init(int sfxVolume, int musicVolume) +{ + int i; + + I_InitSound(); + I_InitMusic(); + + S_SetSfxVolume(sfxVolume); + S_SetMusicVolume(musicVolume); + + // Allocating the internal channels for mixing + // (the maximum numer of sounds rendered + // simultaneously) within zone memory. + channels = Z_Malloc(numChannels*sizeof(channel_t), PU_STATIC, 0); + + // Free all channels for use + for (i=0 ; isfxinfo) + { + // stop the sound playing + + if (I_SoundIsPlaying(c->handle)) + { + I_StopSound(c->handle); + } + + // check to see if other channels are playing the sound + + for (i=0; isfxinfo == channels[i].sfxinfo) + { + break; + } + } + + // degrade usefulness of sound data + + c->sfxinfo->usefulness--; + c->sfxinfo = NULL; + } +} + +// +// Per level startup code. +// Kills playing sounds at start of level, +// determines music if any, changes music. +// + +void S_Start(void) +{ + int cnum; + int mnum; + + // kill all playing sounds at start of level + // (trust me - a good idea) + for (cnum=0 ; cnumpriority >= sfxinfo->priority) + { + break; + } + } + + if (cnum == numChannels) + { + // FUCK! No lower priority. Sorry, Charlie. + return -1; + } + else + { + // Otherwise, kick out lower priority. + S_StopChannel(cnum); + } + } + + c = &channels[cnum]; + + // channel is decided to be cnum. + c->sfxinfo = sfxinfo; + c->origin = origin; + + return cnum; +} + +// +// Changes volume and stereo-separation variables +// from the norm of a sound effect to be played. +// If the sound is not audible, returns a 0. +// Otherwise, modifies parameters and returns 1. +// + +static int S_AdjustSoundParams(mobj_t *listener, mobj_t *source, + int *vol, int *sep) +{ + fixed_t approx_dist; + fixed_t adx; + fixed_t ady; + angle_t angle; + + // calculate the distance to sound origin + // and clip it if necessary + adx = abs(listener->x - source->x); + ady = abs(listener->y - source->y); + + // From _GG1_ p.428. Appox. eucledian distance fast. + approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1); + + if (gamemap != 8 && approx_dist > S_CLIPPING_DIST) + { + return 0; + } + + // angle of source to listener + angle = R_PointToAngle2(listener->x, + listener->y, + source->x, + source->y); + + if (angle > listener->angle) + { + angle = angle - listener->angle; + } + else + { + angle = angle + (0xffffffff - listener->angle); + } + + angle >>= ANGLETOFINESHIFT; + + // stereo separation + *sep = 128 - (FixedMul(S_STEREO_SWING, finesine[angle]) >> FRACBITS); + + // volume calculation + if (approx_dist < S_CLOSE_DIST) + { + *vol = snd_SfxVolume; + } + else if (gamemap == 8) + { + if (approx_dist > S_CLIPPING_DIST) + { + approx_dist = S_CLIPPING_DIST; + } + + *vol = 15+ ((snd_SfxVolume-15) + *((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) + / S_ATTENUATOR; + } + else + { + // distance effect + *vol = (snd_SfxVolume + * ((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) + / S_ATTENUATOR; + } + + return (*vol > 0); +} + +void S_StartSound(void *origin_p, int sfx_id) +{ + sfxinfo_t *sfx; + mobj_t *origin; + int rc; + int sep; + int priority; + int cnum; + int volume; + + origin = (mobj_t *) origin_p; + volume = snd_SfxVolume; + + // check for bogus sound # + if (sfx_id < 1 || sfx_id > NUMSFX) + { + I_Error("Bad sfx #: %d", sfx_id); + } + + sfx = &S_sfx[sfx_id]; + + // Initialize sound parameters + if (sfx->link) + { + priority = sfx->priority; + volume += sfx->volume; + + if (volume < 1) + { + return; + } + + if (volume > snd_SfxVolume) + { + volume = snd_SfxVolume; + } + } + else + { + priority = NORM_PRIORITY; + } + + + // Check to see if it is audible, + // and if not, modify the params + if (origin && origin != players[consoleplayer].mo) + { + rc = S_AdjustSoundParams(players[consoleplayer].mo, + origin, + &volume, + &sep); + + if (origin->x == players[consoleplayer].mo->x + && origin->y == players[consoleplayer].mo->y) + { + sep = NORM_SEP; + } + + if (!rc) + { + return; + } + } + else + { + sep = NORM_SEP; + } + + // kill old sound + S_StopSound(origin); + + // try to find a channel + cnum = S_GetChannel(origin, sfx); + + if (cnum < 0) + { + return; + } + + // increase the usefulness + if (sfx->usefulness++ < 0) + { + sfx->usefulness = 1; + } + + if (sfx->lumpnum < 0) + { + sfx->lumpnum = I_GetSfxLumpNum(sfx); + } + + channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep); +} + +// +// Stop and resume music, during game PAUSE. +// + +void S_PauseSound(void) +{ + if (mus_playing && !mus_paused) + { + I_PauseSong(); + mus_paused = true; + } +} + +void S_ResumeSound(void) +{ + if (mus_playing && mus_paused) + { + I_ResumeSong(); + mus_paused = false; + } +} + +// +// Updates music & sounds +// + +void S_UpdateSounds(mobj_t *listener) +{ + int audible; + int cnum; + int volume; + int sep; + sfxinfo_t* sfx; + channel_t* c; + + for (cnum=0; cnumsfxinfo; + + if (c->sfxinfo) + { + if (I_SoundIsPlaying(c->handle)) + { + // initialize parameters + volume = snd_SfxVolume; + sep = NORM_SEP; + + if (sfx->link) + { + volume += sfx->volume; + if (volume < 1) + { + S_StopChannel(cnum); + continue; + } + else if (volume > snd_SfxVolume) + { + volume = snd_SfxVolume; + } + } + + // check non-local sounds for distance clipping + // or modify their params + if (c->origin && listener != c->origin) + { + audible = S_AdjustSoundParams(listener, + c->origin, + &volume, + &sep); + + if (!audible) + { + S_StopChannel(cnum); + } + else + { + I_UpdateSoundParams(c->handle, volume, sep); + } + } + } + else + { + // if channel is allocated but sound has stopped, + // free it + S_StopChannel(cnum); + } + } + } +} + +void S_SetMusicVolume(int volume) +{ + if (volume < 0 || volume > 127) + { + I_Error("Attempt to set music volume at %d", + volume); + } + + I_SetMusicVolume(volume); +} + +void S_SetSfxVolume(int volume) +{ + if (volume < 0 || volume > 127) + { + I_Error("Attempt to set sfx volume at %d", volume); + } + + snd_SfxVolume = volume; +} + +// +// Starts some music with the music id found in sounds.h. +// + +void S_StartMusic(int m_id) +{ + S_ChangeMusic(m_id, false); +} + +void S_ChangeMusic(int musicnum, int looping) +{ + musicinfo_t *music = NULL; + char namebuf[9]; + void *handle; + + if (musicnum <= mus_None || musicnum >= NUMMUSIC) + { + I_Error("Bad music number %d", musicnum); + } + else + { + music = &S_music[musicnum]; + } + + if (mus_playing == music) + { + return; + } + + // shutdown old music + S_StopMusic(); + + // get lumpnum if neccessary + if (!music->lumpnum) + { + sprintf(namebuf, "d_%s", DEH_String(music->name)); + music->lumpnum = W_GetNumForName(namebuf); + } + + music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); + + handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum)); + music->handle = handle; + I_PlaySong(handle, looping); + + mus_playing = music; +} + +boolean S_MusicPlaying(void) +{ + return I_MusicIsPlaying(); +} + +void S_StopMusic(void) +{ + if (mus_playing) + { + if (mus_paused) + { + I_ResumeSong(); + } + + I_StopSong(); + I_UnRegisterSong(mus_playing->handle); + W_ReleaseLumpNum(mus_playing->lumpnum); + mus_playing->data = NULL; + mus_playing = NULL; + } +} + diff --git a/src/doom/s_sound.h b/src/doom/s_sound.h new file mode 100644 index 00000000..d2af9e88 --- /dev/null +++ b/src/doom/s_sound.h @@ -0,0 +1,96 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 1993-1996 Id Software, Inc. +// Copyright(C) 2005 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// The not so system specific sound interface. +// +//----------------------------------------------------------------------------- + + +#ifndef __S_SOUND__ +#define __S_SOUND__ + +#include "p_mobj.h" +#include "sounds.h" + +// +// Initializes sound stuff, including volume +// Sets channels, SFX and music volume, +// allocates channel buffer, sets S_sfx lookup. +// + +void S_Init(int sfxVolume, int musicVolume); + + +// Shut down sound + +void S_Shutdown(void); + + + +// +// Per level startup code. +// Kills playing sounds at start of level, +// determines music if any, changes music. +// + +void S_Start(void); + +// +// Start sound for thing at +// using from sounds.h +// + +void S_StartSound(void *origin, int sound_id); + +// Stop sound for thing at +void S_StopSound(mobj_t *origin); + + +// Start music using from sounds.h +void S_StartMusic(int music_id); + +// Start music using from sounds.h, +// and set whether looping +void S_ChangeMusic(int music_id, int looping); + +// query if music is playing +boolean S_MusicPlaying(void); + +// Stops the music fer sure. +void S_StopMusic(void); + +// Stop and resume music, during game PAUSE. +void S_PauseSound(void); +void S_ResumeSound(void); + + +// +// Updates music & sounds +// +void S_UpdateSounds(mobj_t *listener); + +void S_SetMusicVolume(int volume); +void S_SetSfxVolume(int volume); + + +#endif + diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c index 3acccde6..e2086598 100644 --- a/src/i_sdlmusic.c +++ b/src/i_sdlmusic.c @@ -35,8 +35,8 @@ #include "mus2mid.h" #include "deh_str.h" +#include "i_sound.h" #include "m_misc.h" -#include "s_sound.h" #include "w_wad.h" #include "z_zone.h" diff --git a/src/i_sound.c b/src/i_sound.c index 3f057c62..c44219fb 100644 --- a/src/i_sound.c +++ b/src/i_sound.c @@ -42,6 +42,10 @@ #define DEFAULT_MUSIC_DEVICE SNDDEVICE_NONE #endif +// Sound sample rate to use for digital output (Hz) + +int snd_samplerate = 44100; + // Low-level sound and music modules we are using static sound_module_t *sound_module; diff --git a/src/s_sound.c b/src/s_sound.c deleted file mode 100644 index 1dc575a3..00000000 --- a/src/s_sound.c +++ /dev/null @@ -1,675 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. -// -// DESCRIPTION: none -// -//----------------------------------------------------------------------------- - -#include -#include - -#include "i_sound.h" -#include "i_system.h" - -#include "doomfeatures.h" -#include "deh_str.h" - -#include "doomstat.h" -#include "doomtype.h" - -#include "sounds.h" -#include "s_sound.h" - -#include "m_random.h" -#include "m_argv.h" - -#include "p_local.h" -#include "w_wad.h" -#include "z_zone.h" - -// when to clip out sounds -// Does not fit the large outdoor areas. - -#define S_CLIPPING_DIST (1200 * FRACUNIT) - -// Distance tp origin when sounds should be maxed out. -// This should relate to movement clipping resolution -// (see BLOCKMAP handling). -// In the source code release: (160*FRACUNIT). Changed back to the -// Vanilla value of 200 (why was this changed?) - -#define S_CLOSE_DIST (200 * FRACUNIT) - -// The range over which sound attenuates - -#define S_ATTENUATOR ((S_CLIPPING_DIST - S_CLOSE_DIST) >> FRACBITS) - -// Stereo separation - -#define S_STEREO_SWING (96 * FRACUNIT) - -#define NORM_PITCH 128 -#define NORM_PRIORITY 64 -#define NORM_SEP 128 - -typedef struct -{ - // sound information (if null, channel avail.) - sfxinfo_t *sfxinfo; - - // origin of sound - mobj_t *origin; - - // handle of the sound being played - int handle; - -} channel_t; - -// The set of channels available - -static channel_t *channels; - -// Maximum volume of a sound effect. -// Internal default is max out of 0-15. - -int sfxVolume = 8; - -// Maximum volume of music. - -int musicVolume = 8; - -// Sound sample rate to use for digital output (Hz) - -int snd_samplerate = 44100; - -// Internal volume level, ranging from 0-127 - -static int snd_SfxVolume; - -// Whether songs are mus_paused - -static boolean mus_paused; - -// Music currently being played - -static musicinfo_t *mus_playing = NULL; - -// Number of channels to use - -int numChannels = 8; - -// -// Initializes sound stuff, including volume -// Sets channels, SFX and music volume, -// allocates channel buffer, sets S_sfx lookup. -// - -void S_Init(int sfxVolume, int musicVolume) -{ - int i; - - I_InitSound(); - I_InitMusic(); - - S_SetSfxVolume(sfxVolume); - S_SetMusicVolume(musicVolume); - - // Allocating the internal channels for mixing - // (the maximum numer of sounds rendered - // simultaneously) within zone memory. - channels = Z_Malloc(numChannels*sizeof(channel_t), PU_STATIC, 0); - - // Free all channels for use - for (i=0 ; isfxinfo) - { - // stop the sound playing - - if (I_SoundIsPlaying(c->handle)) - { - I_StopSound(c->handle); - } - - // check to see if other channels are playing the sound - - for (i=0; isfxinfo == channels[i].sfxinfo) - { - break; - } - } - - // degrade usefulness of sound data - - c->sfxinfo->usefulness--; - c->sfxinfo = NULL; - } -} - -// -// Per level startup code. -// Kills playing sounds at start of level, -// determines music if any, changes music. -// - -void S_Start(void) -{ - int cnum; - int mnum; - - // kill all playing sounds at start of level - // (trust me - a good idea) - for (cnum=0 ; cnumpriority >= sfxinfo->priority) - { - break; - } - } - - if (cnum == numChannels) - { - // FUCK! No lower priority. Sorry, Charlie. - return -1; - } - else - { - // Otherwise, kick out lower priority. - S_StopChannel(cnum); - } - } - - c = &channels[cnum]; - - // channel is decided to be cnum. - c->sfxinfo = sfxinfo; - c->origin = origin; - - return cnum; -} - -// -// Changes volume and stereo-separation variables -// from the norm of a sound effect to be played. -// If the sound is not audible, returns a 0. -// Otherwise, modifies parameters and returns 1. -// - -static int S_AdjustSoundParams(mobj_t *listener, mobj_t *source, - int *vol, int *sep) -{ - fixed_t approx_dist; - fixed_t adx; - fixed_t ady; - angle_t angle; - - // calculate the distance to sound origin - // and clip it if necessary - adx = abs(listener->x - source->x); - ady = abs(listener->y - source->y); - - // From _GG1_ p.428. Appox. eucledian distance fast. - approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1); - - if (gamemap != 8 && approx_dist > S_CLIPPING_DIST) - { - return 0; - } - - // angle of source to listener - angle = R_PointToAngle2(listener->x, - listener->y, - source->x, - source->y); - - if (angle > listener->angle) - { - angle = angle - listener->angle; - } - else - { - angle = angle + (0xffffffff - listener->angle); - } - - angle >>= ANGLETOFINESHIFT; - - // stereo separation - *sep = 128 - (FixedMul(S_STEREO_SWING, finesine[angle]) >> FRACBITS); - - // volume calculation - if (approx_dist < S_CLOSE_DIST) - { - *vol = snd_SfxVolume; - } - else if (gamemap == 8) - { - if (approx_dist > S_CLIPPING_DIST) - { - approx_dist = S_CLIPPING_DIST; - } - - *vol = 15+ ((snd_SfxVolume-15) - *((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) - / S_ATTENUATOR; - } - else - { - // distance effect - *vol = (snd_SfxVolume - * ((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) - / S_ATTENUATOR; - } - - return (*vol > 0); -} - -void S_StartSound(void *origin_p, int sfx_id) -{ - sfxinfo_t *sfx; - mobj_t *origin; - int rc; - int sep; - int priority; - int cnum; - int volume; - - origin = (mobj_t *) origin_p; - volume = snd_SfxVolume; - - // check for bogus sound # - if (sfx_id < 1 || sfx_id > NUMSFX) - { - I_Error("Bad sfx #: %d", sfx_id); - } - - sfx = &S_sfx[sfx_id]; - - // Initialize sound parameters - if (sfx->link) - { - priority = sfx->priority; - volume += sfx->volume; - - if (volume < 1) - { - return; - } - - if (volume > snd_SfxVolume) - { - volume = snd_SfxVolume; - } - } - else - { - priority = NORM_PRIORITY; - } - - - // Check to see if it is audible, - // and if not, modify the params - if (origin && origin != players[consoleplayer].mo) - { - rc = S_AdjustSoundParams(players[consoleplayer].mo, - origin, - &volume, - &sep); - - if (origin->x == players[consoleplayer].mo->x - && origin->y == players[consoleplayer].mo->y) - { - sep = NORM_SEP; - } - - if (!rc) - { - return; - } - } - else - { - sep = NORM_SEP; - } - - // kill old sound - S_StopSound(origin); - - // try to find a channel - cnum = S_GetChannel(origin, sfx); - - if (cnum < 0) - { - return; - } - - // increase the usefulness - if (sfx->usefulness++ < 0) - { - sfx->usefulness = 1; - } - - if (sfx->lumpnum < 0) - { - sfx->lumpnum = I_GetSfxLumpNum(sfx); - } - - channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep); -} - -// -// Stop and resume music, during game PAUSE. -// - -void S_PauseSound(void) -{ - if (mus_playing && !mus_paused) - { - I_PauseSong(); - mus_paused = true; - } -} - -void S_ResumeSound(void) -{ - if (mus_playing && mus_paused) - { - I_ResumeSong(); - mus_paused = false; - } -} - -// -// Updates music & sounds -// - -void S_UpdateSounds(mobj_t *listener) -{ - int audible; - int cnum; - int volume; - int sep; - sfxinfo_t* sfx; - channel_t* c; - - for (cnum=0; cnumsfxinfo; - - if (c->sfxinfo) - { - if (I_SoundIsPlaying(c->handle)) - { - // initialize parameters - volume = snd_SfxVolume; - sep = NORM_SEP; - - if (sfx->link) - { - volume += sfx->volume; - if (volume < 1) - { - S_StopChannel(cnum); - continue; - } - else if (volume > snd_SfxVolume) - { - volume = snd_SfxVolume; - } - } - - // check non-local sounds for distance clipping - // or modify their params - if (c->origin && listener != c->origin) - { - audible = S_AdjustSoundParams(listener, - c->origin, - &volume, - &sep); - - if (!audible) - { - S_StopChannel(cnum); - } - else - { - I_UpdateSoundParams(c->handle, volume, sep); - } - } - } - else - { - // if channel is allocated but sound has stopped, - // free it - S_StopChannel(cnum); - } - } - } -} - -void S_SetMusicVolume(int volume) -{ - if (volume < 0 || volume > 127) - { - I_Error("Attempt to set music volume at %d", - volume); - } - - I_SetMusicVolume(volume); -} - -void S_SetSfxVolume(int volume) -{ - if (volume < 0 || volume > 127) - { - I_Error("Attempt to set sfx volume at %d", volume); - } - - snd_SfxVolume = volume; -} - -// -// Starts some music with the music id found in sounds.h. -// - -void S_StartMusic(int m_id) -{ - S_ChangeMusic(m_id, false); -} - -void S_ChangeMusic(int musicnum, int looping) -{ - musicinfo_t *music = NULL; - char namebuf[9]; - void *handle; - - if (musicnum <= mus_None || musicnum >= NUMMUSIC) - { - I_Error("Bad music number %d", musicnum); - } - else - { - music = &S_music[musicnum]; - } - - if (mus_playing == music) - { - return; - } - - // shutdown old music - S_StopMusic(); - - // get lumpnum if neccessary - if (!music->lumpnum) - { - sprintf(namebuf, "d_%s", DEH_String(music->name)); - music->lumpnum = W_GetNumForName(namebuf); - } - - music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC); - - handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum)); - music->handle = handle; - I_PlaySong(handle, looping); - - mus_playing = music; -} - -boolean S_MusicPlaying(void) -{ - return I_MusicIsPlaying(); -} - -void S_StopMusic(void) -{ - if (mus_playing) - { - if (mus_paused) - { - I_ResumeSong(); - } - - I_StopSong(); - I_UnRegisterSong(mus_playing->handle); - W_ReleaseLumpNum(mus_playing->lumpnum); - mus_playing->data = NULL; - mus_playing = NULL; - } -} - diff --git a/src/s_sound.h b/src/s_sound.h deleted file mode 100644 index d2af9e88..00000000 --- a/src/s_sound.h +++ /dev/null @@ -1,96 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. -// -// DESCRIPTION: -// The not so system specific sound interface. -// -//----------------------------------------------------------------------------- - - -#ifndef __S_SOUND__ -#define __S_SOUND__ - -#include "p_mobj.h" -#include "sounds.h" - -// -// Initializes sound stuff, including volume -// Sets channels, SFX and music volume, -// allocates channel buffer, sets S_sfx lookup. -// - -void S_Init(int sfxVolume, int musicVolume); - - -// Shut down sound - -void S_Shutdown(void); - - - -// -// Per level startup code. -// Kills playing sounds at start of level, -// determines music if any, changes music. -// - -void S_Start(void); - -// -// Start sound for thing at -// using from sounds.h -// - -void S_StartSound(void *origin, int sound_id); - -// Stop sound for thing at -void S_StopSound(mobj_t *origin); - - -// Start music using from sounds.h -void S_StartMusic(int music_id); - -// Start music using from sounds.h, -// and set whether looping -void S_ChangeMusic(int music_id, int looping); - -// query if music is playing -boolean S_MusicPlaying(void); - -// Stops the music fer sure. -void S_StopMusic(void); - -// Stop and resume music, during game PAUSE. -void S_PauseSound(void); -void S_ResumeSound(void); - - -// -// Updates music & sounds -// -void S_UpdateSounds(mobj_t *listener); - -void S_SetMusicVolume(int volume); -void S_SetSfxVolume(int volume); - - -#endif - -- cgit v1.2.3