1 /* 2 Copyright (C) 1996-1997 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 // sound.h -- client sound i/o functions 21 22 #ifndef __SOUND__ 23 #define __SOUND__ 24 25 #define DEFAULT_SOUND_PACKET_VOLUME 255 26 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0 27 28 // !!! if this is changed, it much be changed in asm_i386.h too !!! 29 typedef struct 30 { 31 int left; 32 int right; 33 } portable_samplepair_t; 34 35 typedef struct sfx_s 36 { 37 char name[MAX_QPATH]; 38 cache_user_t cache; 39 } sfx_t; 40 41 // !!! if this is changed, it much be changed in asm_i386.h too !!! 42 typedef struct 43 { 44 int length; 45 int loopstart; 46 int speed; 47 int width; 48 int stereo; 49 union { 50 byte b[1]; 51 unsigned char uc[1]; 52 signed char sc[1]; 53 short s[1]; 54 signed short ss[1]; 55 } data; // variable sized 56 } sfxcache_t; 57 58 typedef struct 59 { 60 qboolean gamealive; 61 qboolean soundalive; 62 qboolean splitbuffer; 63 int channels; 64 int samples; // mono samples in buffer 65 int submission_chunk; // don't mix less than this # 66 int samplepos; // in mono samples 67 int samplebits; 68 int speed; 69 unsigned char *buffer; 70 } dma_t; 71 72 // !!! if this is changed, it much be changed in asm_i386.h too !!! 73 typedef struct 74 { 75 sfx_t *sfx; // sfx number 76 int leftvol; // 0-255 volume 77 int rightvol; // 0-255 volume 78 int end; // end time in global paintsamples 79 int pos; // sample position in sfx 80 int looping; // where to loop, -1 = no looping 81 int entnum; // to allow overriding a specific sound 82 int entchannel; // 83 vec3_t origin; // origin of sound effect 84 vec_t dist_mult; // distance multiplier (attenuation/clipK) 85 int master_vol; // 0-255 master volume 86 } channel_t; 87 88 typedef struct 89 { 90 int rate; 91 int width; 92 int channels; 93 int loopstart; 94 int samples; 95 int dataofs; // chunk starts this many bytes from file start 96 } wavinfo_t; 97 98 void S_Init (void); 99 void S_Startup (void); 100 void S_Shutdown (void); 101 void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); 102 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); 103 void S_StopSound (int entnum, int entchannel); 104 void S_StopAllSounds(qboolean clear); 105 void S_ClearBuffer (void); 106 void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up); 107 void S_ExtraUpdate (void); 108 109 sfx_t *S_PrecacheSound (const char *sample); 110 void S_TouchSound (const char *sample); 111 void S_ClearPrecache (void); 112 void S_BeginPrecaching (void); 113 void S_EndPrecaching (void); 114 void S_PaintChannels(int endtime); 115 void S_InitPaintChannels (void); 116 117 // picks a channel based on priorities, empty slots, number of channels 118 channel_t *SND_PickChannel(int entnum, int entchannel); 119 120 // spatializes a channel 121 void SND_Spatialize(channel_t *ch); 122 123 // initializes cycling through a DMA buffer and returns information on it 124 qboolean SNDDMA_Init(void); 125 126 // gets the current DMA position 127 int SNDDMA_GetDMAPos(void); 128 129 // shutdown the DMA xfer. 130 void SNDDMA_Shutdown(void); 131 132 // ==================================================================== 133 // User-setable variables 134 // ==================================================================== 135 136 #define MAX_CHANNELS 128 137 #define MAX_DYNAMIC_CHANNELS 8 138 139 140 extern channel_t channels[MAX_CHANNELS]; 141 // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds 142 // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc 143 // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds 144 145 extern int total_channels; 146 147 // 148 // Fake dma is a synchronous faking of the DMA progress used for 149 // isolating performance in the renderer. The fakedma_updates is 150 // number of times S_Update() is called per second. 151 // 152 153 extern qboolean fakedma; 154 extern int fakedma_updates; 155 extern int paintedtime; 156 extern vec3_t listener_origin; 157 extern vec3_t listener_forward; 158 extern vec3_t listener_right; 159 extern vec3_t listener_up; 160 extern volatile dma_t *shm; 161 extern volatile dma_t sn; 162 extern vec_t sound_nominal_clip_dist; 163 164 extern cvar_t loadas8bit; 165 extern cvar_t bgmvolume; 166 extern cvar_t volume; 167 168 extern qboolean snd_initialized; 169 170 extern int snd_blocked; 171 172 void S_LocalSound (const char *s); 173 sfxcache_t *S_LoadSound (sfx_t *s); 174 175 wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength); 176 177 void SND_InitScaletable (void); 178 void SNDDMA_Submit(void); 179 180 void S_AmbientOff (void); 181 void S_AmbientOn (void); 182 183 #endif 184