1/* 2Copyright (C) 1996-1997 Id Software, Inc. 3 4This program is free software; you can redistribute it and/or 5modify it under the terms of the GNU General Public License 6as published by the Free Software Foundation; either version 2 7of the License, or (at your option) any later version. 8 9This program is distributed in the hope that it will be useful, 10but WITHOUT ANY WARRANTY; without even the implied warranty of 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13See the GNU General Public License for more details. 14 15You should have received a copy of the GNU General Public License 16along with this program; if not, write to the Free Software 17Foundation, 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 !!! 29typedef struct 30{ 31 int left; 32 int right; 33} portable_samplepair_t; 34 35typedef 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 !!! 42typedef 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 58typedef 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 !!! 73typedef 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 88typedef 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 98void S_Init (void); 99void S_Startup (void); 100void S_Shutdown (void); 101void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); 102void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); 103void S_StopSound (int entnum, int entchannel); 104void S_StopAllSounds(qboolean clear); 105void S_ClearBuffer (void); 106void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up); 107void S_ExtraUpdate (void); 108 109sfx_t *S_PrecacheSound (const char *sample); 110void S_TouchSound (const char *sample); 111void S_ClearPrecache (void); 112void S_BeginPrecaching (void); 113void S_EndPrecaching (void); 114void S_PaintChannels(int endtime); 115void S_InitPaintChannels (void); 116 117// picks a channel based on priorities, empty slots, number of channels 118channel_t *SND_PickChannel(int entnum, int entchannel); 119 120// spatializes a channel 121void SND_Spatialize(channel_t *ch); 122 123// initializes cycling through a DMA buffer and returns information on it 124qboolean SNDDMA_Init(void); 125 126// gets the current DMA position 127int SNDDMA_GetDMAPos(void); 128 129// shutdown the DMA xfer. 130void SNDDMA_Shutdown(void); 131 132// ==================================================================== 133// User-setable variables 134// ==================================================================== 135 136#define MAX_CHANNELS 128 137#define MAX_DYNAMIC_CHANNELS 8 138 139 140extern 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 145extern 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 153extern qboolean fakedma; 154extern int fakedma_updates; 155extern int paintedtime; 156extern vec3_t listener_origin; 157extern vec3_t listener_forward; 158extern vec3_t listener_right; 159extern vec3_t listener_up; 160extern volatile dma_t *shm; 161extern volatile dma_t sn; 162extern vec_t sound_nominal_clip_dist; 163 164extern cvar_t loadas8bit; 165extern cvar_t bgmvolume; 166extern cvar_t volume; 167 168extern qboolean snd_initialized; 169 170extern int snd_blocked; 171 172void S_LocalSound (const char *s); 173sfxcache_t *S_LoadSound (sfx_t *s); 174 175wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength); 176 177void SND_InitScaletable (void); 178void SNDDMA_Submit(void); 179 180void S_AmbientOff (void); 181void S_AmbientOn (void); 182 183#endif 184