Odamex
Setting the Standard in Multiplayer Doom
common/s_sound.h
Go to the documentation of this file.
00001 // Emacs style mode select   -*- C++ -*- 
00002 //-----------------------------------------------------------------------------
00003 //
00004 // $Id: s_sound.h 1857 2010-09-05 13:14:01Z spleen $
00005 //
00006 // Copyright (C) 1993-1996 by id Software, Inc.
00007 // Copyright (C) 2006-2010 by The Odamex Team.
00008 //
00009 // This program is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // DESCRIPTION:
00020 //      The not so system specific sound interface.
00021 //
00022 //-----------------------------------------------------------------------------
00023 
00024 
00025 #ifndef __S_SOUND__
00026 #define __S_SOUND__
00027 
00028 #include <string>
00029 
00030 #include "m_fixed.h"
00031 
00032 
00033 #define MAX_SNDNAME                     63
00034 
00035 //joek - choco goodness below
00036 // when to clip out sounds
00037 // Does not fit the large outdoor areas.
00038 #define S_CLIPPING_DIST         (1200*0x10000)
00039 
00040 
00041 class AActor;
00042 
00043 //
00044 // SoundFX struct.
00045 //
00046 typedef struct sfxinfo_struct sfxinfo_t;
00047 
00048 struct sfxinfo_struct
00049 {
00050         char            name[MAX_SNDNAME+1];    // [RH] Sound name defined in SNDINFO
00051         unsigned        normal;                                 // Normal sample handle
00052         unsigned        looping;                                // Looping sample handle
00053         void*           data;
00054 
00055         struct sfxinfo_struct *link;
00056 
00057         // this is checked every second to see if sound
00058         // can be thrown out (if 0, then decrement, if -1,
00059         // then throw out, if > 0, then it is in use)
00060         int             usefulness;
00061 
00062         int             lumpnum;                                // lump number of sfx
00063         unsigned int ms;                                        // [RH] length of sfx in milliseconds
00064         unsigned int next, index;                       // [RH] For hashing
00065         unsigned int frequency;                         // [RH] Preferred playback rate
00066         unsigned int length;                            // [RH] Length of the sound in bytes
00067 };
00068 
00069 // the complete set of sound effects
00070 extern sfxinfo_t *S_sfx;
00071 
00072 // [RH] Number of defined sounds
00073 extern int numsfx;
00074 
00075 // Initializes sound stuff, including volume
00076 // Sets channels, SFX and music volume,
00077 //      allocates channel buffer, sets S_sfx lookup.
00078 //
00079 void S_Init (float sfxVolume, float musicVolume);
00080 
00081 // Per level startup code.
00082 // Kills playing sounds at start of level,
00083 //      determines music if any, changes music.
00084 //
00085 void S_Stop(void);
00086 void S_Start(void);
00087 
00088 // Start sound for thing at <ent>
00089 void S_Sound (int channel, const char *name, float volume, int attenuation);
00090 void S_Sound (AActor *ent, int channel, const char *name, float volume, int attenuation);
00091 void S_Sound (fixed_t *pt, int channel, const char *name, float volume, int attenuation);
00092 void S_Sound (fixed_t x, fixed_t y, int channel, const char *name, float volume, int attenuation);
00093 void S_PlatSound (fixed_t *pt, int channel, const char *name, float volume, int attenuation); // [Russell] - Hack to stop multiple plat stop sounds
00094 void S_LoopedSound (AActor *ent, int channel, const char *name, float volume, int attenuation);
00095 void S_LoopedSound (fixed_t *pt, int channel, const char *name, float volume, int attenuation);
00096 void S_SoundID (int channel, int sfxid, float volume, int attenuation);
00097 void S_SoundID (fixed_t x, fixed_t y, int channel, int sound_id, float volume, int attenuation);
00098 void S_SoundID (AActor *ent, int channel, int sfxid, float volume, int attenuation);
00099 void S_SoundID (fixed_t *pt, int channel, int sfxid, float volume, int attenuation);
00100 void S_LoopedSoundID (AActor *ent, int channel, int sfxid, float volume, int attenuation);
00101 void S_LoopedSoundID (fixed_t *pt, int channel, int sfxid, float volume, int attenuation);
00102 
00103 // sound channels
00104 // channel 0 never willingly overrides
00105 // other channels (1-7) always override a playing sound on that channel
00106 #define CHAN_AUTO                               0
00107 #define CHAN_WEAPON                             1
00108 #define CHAN_VOICE                              2
00109 #define CHAN_ITEM                               3
00110 #define CHAN_BODY                               4
00111 #define CHAN_ANNOUNCERF                 5
00112 #define CHAN_ANNOUNCERE                 6
00113 // modifier flags
00114 //#define CHAN_NO_PHS_ADD               8       // send to all clients, not just ones in PHS (ATTN 0 will also do this)
00115 //#define CHAN_RELIABLE                 16      // send by reliable message, not datagram
00116 
00117 
00118 // sound attenuation values
00119 #define ATTN_NONE                               0       // full volume the entire level
00120 #define ATTN_NORM                               1
00121 #define ATTN_IDLE                               2
00122 #define ATTN_STATIC                             3       // diminish very rapidly with distance
00123 #define ATTN_SURROUND                   4       // like ATTN_NONE, but plays in surround sound
00124 
00125 // Stops a sound emanating from one of an entity's channels
00126 void S_StopSound (AActor *ent, int channel);
00127 void S_StopSound (fixed_t *pt, int channel);
00128 void S_StopSound (fixed_t *pt);
00129 
00130 bool S_StopSoundID (int sound_id);
00131 
00132 // Stop sound for all channels
00133 void S_StopAllChannels (void);
00134 
00135 // Is the sound playing on one of the entity's channels?
00136 bool S_GetSoundPlayingInfo (AActor *ent, int sound_id);
00137 bool S_GetSoundPlayingInfo (fixed_t *pt, int sound_id);
00138 
00139 // Moves all sounds from one mobj to another
00140 void S_RelinkSound (AActor *from, AActor *to);
00141 
00142 // Start music using <music_name>
00143 void S_StartMusic (const char *music_name);
00144 
00145 // Start music using <music_name>, and set whether looping
00146 void S_ChangeMusic (std::string music_name, int looping);
00147 
00148 // Stops the music fer sure.
00149 void S_StopMusic (void);
00150 
00151 // Stop and resume music, during game PAUSE.
00152 void S_PauseSound (void);
00153 void S_ResumeSound (void);
00154 
00155 
00156 //
00157 // Updates music & sounds
00158 //
00159 void S_UpdateSounds (void *listener);
00160 
00161 void S_SetMusicVolume (float volume);
00162 void S_SetSfxVolume (float volume);
00163 
00164 // [RH] Activates an ambient sound. Called when the thing is added to the map.
00165 //              (0-biased)
00166 void S_ActivateAmbient (AActor *mobj, int ambient);
00167 
00168 
00169 // [RH] S_sfx "maintenance" routines
00170 void S_ParseSndInfo (void);
00171 
00172 void S_HashSounds (void);
00173 int S_FindSound (const char *logicalname);
00174 int S_FindSoundByLump (int lump);
00175 int S_AddSound (char *logicalname, char *lumpname);     // Add sound by lumpname
00176 int S_AddSoundLump (char *logicalname, int lump);       // Add sound by lump index
00177 void S_ClearSoundLumps (void);
00178 
00179 void UV_SoundAvoidPlayer (AActor *mo, byte channel, const char *name, byte attenuation);
00180 
00181 // [RH] Prints sound debug info to the screen.
00182 //              Modelled after Hexen's noise cheat.
00183 void S_NoiseDebug (void);
00184 
00185 class cvar_t;
00186 extern cvar_t noisedebug;
00187 
00188 
00189 #endif
00190 
00191 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends