1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 // 21 // snd_local.h 22 // Private sound functions 23 // 24 25 #include "../client/cl_local.h" 26 27 #define MAX_SFX (MAX_CS_SOUNDS*2) 28 #define MAX_CHANNELS 128 29 #define MAX_PLAYSOUNDS 128 30 31 // only begin attenuating sound volumes when outside the FULLVOLUME range 32 #define SOUND_FULLVOLUME 80.0f 33 #define SOUND_LOOPATTENUATE 0.003f 34 35 typedef struct sfxCache_s { 36 int alFormat; 37 uint32 alBufferNum; 38 39 int length; 40 int loopStart; 41 int speed; // not needed, because converted on load? 42 int width; 43 int stereo; 44 45 byte data[1]; // variable sized 46 } sfxCache_t; 47 48 typedef struct sfx_s { 49 char name[MAX_QPATH]; 50 uint32 touchFrame; // 0 = free 51 sfxCache_t *cache; 52 char *trueName; 53 54 uint32 hashValue; 55 struct sfx_s *hashNext; 56 } sfx_t; 57 58 // playsound types let the mixer(s) know to play locally, or to spatialize for a fixed/entity origin/velocity 59 typedef enum psndType_s { 60 PSND_ENTITY, 61 PSND_FIXED, 62 PSND_LOCAL, 63 } psndType_t; 64 65 // a playSound_t will be generated by each call to Snd_StartSound, when the mixer 66 // reaches playsound->begin, the playsound will be assigned to a channel 67 typedef struct playSound_s { 68 struct playSound_s *prev, *next; 69 70 sfx_t *sfx; 71 72 psndType_t type; 73 74 int volume; 75 float attenuation; 76 77 int entNum; 78 entChannel_t entChannel; 79 80 vec3_t origin; 81 82 int beginTime; // begin on this sample 83 } playSound_t; 84 85 typedef struct wavInfo_s { 86 int rate; 87 int width; 88 int channels; 89 int loopStart; 90 int samples; 91 int dataOfs; // chunk starts this many bytes from file start 92 } wavInfo_t; 93 94 typedef struct channel_s { 95 sfx_t *sfx; // sfx number 96 97 psndType_t psType; 98 99 int entNum; // to allow overriding a specific sound 100 entChannel_t entChannel; 101 102 qBool alLooping; 103 int alLoopEntNum; 104 int alLoopFrame; 105 qBool alRawPlaying; // don't stop playing until all buffers are processed 106 qBool alRawStream; // raw stream channels are locked from being used until done 107 uint32 alSourceNum; 108 int alStartTime; 109 float alVolume; 110 111 vec3_t origin; 112 113 int masterVol; // 0-255 master volume 114 int leftVol; // 0-255 volume 115 int rightVol; // 0-255 volume 116 117 int endTime; // end time in global paintsamples 118 int position; // sample position in sfx 119 120 float distMult; // distance multiplier (attenuation/clipK) 121 122 qBool autoSound; // from an entity->sound, cleared each frame 123 } channel_t; 124 125 // ========================================================================== 126 127 // 128 // snd_main.c 129 // 130 extern qBool snd_isActive; 131 extern qBool snd_isDMA; 132 extern qBool snd_isAL; 133 134 extern uint32 snd_registrationFrame; 135 136 extern playSound_t snd_playSounds[MAX_PLAYSOUNDS]; 137 extern playSound_t snd_freePlays; 138 extern playSound_t snd_pendingPlays; 139 140 extern cVar_t *s_show; 141 extern cVar_t *s_loadas8bit; 142 extern cVar_t *s_volume; 143 144 extern cVar_t *s_khz; 145 extern cVar_t *s_mixahead; 146 extern cVar_t *s_testsound; 147 extern cVar_t *s_primary; 148 149 extern cVar_t *al_allowExtensions; 150 extern cVar_t *al_device; 151 extern cVar_t *al_dopplerFactor; 152 extern cVar_t *al_dopplerVelocity; 153 extern cVar_t *al_driver; 154 extern cVar_t *al_errorCheck; 155 extern cVar_t *al_ext_eax2; 156 extern cVar_t *al_gain; 157 extern cVar_t *al_minDistance; 158 extern cVar_t *al_maxDistance; 159 extern cVar_t *al_rollOffFactor; 160 161 sfxCache_t *Snd_LoadSound (sfx_t *s); 162 163 void Snd_FreePlaysound (playSound_t *ps); 164 165 // 166 // snd_dma.c 167 // 168 typedef struct audioDma_s { 169 int channels; 170 int samples; // mono samples in buffer 171 int submissionChunk; // don't mix less than this # 172 int samplePos; // in mono samples 173 int sampleBits; 174 int speed; 175 byte *buffer; 176 } audioDMA_t; 177 178 extern audioDMA_t snd_audioDMA; 179 extern int snd_dmaPaintedTime; 180 181 qBool DMASnd_Init (void); 182 void DMASnd_Shutdown (void); 183 184 void DMASnd_StopAllSounds (void); 185 void DMASnd_RawSamples (int samples, int rate, int width, int channels, byte *data); 186 187 void DMASnd_Update (refDef_t *rd); 188 189 // 190 // snd_openal.c 191 // 192 typedef struct audioAL_s { 193 // Static information (never changes after initialization) 194 const char *extensionString; 195 const char *rendererString; 196 const char *vendorString; 197 const char *versionString; 198 199 const char *deviceName; 200 201 int numChannels; 202 203 // Dynamic information 204 int frameCount; 205 } audioAL_t; 206 207 extern audioAL_t snd_audioAL; 208 209 void ALSnd_Activate (qBool active); 210 211 void ALSnd_CreateBuffer (sfxCache_t *sc, int width, int channels, byte *data, int size, int frequency); 212 void ALSnd_DeleteBuffer (sfxCache_t *sc); 213 214 void ALSnd_StopAllSounds (void); 215 216 channel_t *ALSnd_RawStart (void); 217 void ALSnd_RawSamples (struct channel_s *rawChannel, int samples, int rate, int width, int channels, byte *data); 218 void ALSnd_RawStop (channel_t *rawChannel); 219 void ALSnd_RawShutdown (void); 220 221 void ALSnd_Update (refDef_t *rd); 222 223 qBool ALSnd_Init (void); 224 void ALSnd_Shutdown (void); 225 226 /* 227 ============================================================================= 228 229 SYSTEM SPECIFIC FUNCTIONS 230 231 ============================================================================= 232 */ 233 234 qBool SndImp_Init (void); // initializes cycling through a DMA buffer and returns information on it 235 int SndImp_GetDMAPos (void); // gets the current DMA position 236 void SndImp_BeginPainting (void); 237 void SndImp_Submit (void); 238 void SndImp_Shutdown (void); 239