2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // sound.h -- client sound i/o functions
25 #define DEFAULT_SOUND_PACKET_VOLUME 255
26 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
32 } portable_samplepair_t;
41 qbyte data[1]; // variable sized
45 #define SFXFLAG_SILENTLYMISSING (1 << 0) // if the sfx is missing and loaded with complain = false
46 #define SFXFLAG_USED (1 << 1)
53 unsigned int flags; // cf SFXFLAG_* defines
59 int samples; // mono samples in buffer
60 int samplepos; // in mono samples
63 unsigned char *buffer;
64 int bufferlength; // used only by certain drivers
69 sfx_t *sfx; // sfx number
70 int forceloop; // force looping even if the sound is not looped
71 int leftvol; // 0-255 volume
72 int rightvol; // 0-255 volume
73 int end; // end time in global paintsamples
74 int pos; // sample position in sfx
75 int looping; // where to loop, -1 = no looping
76 int entnum; // to allow overriding a specific sound
78 vec3_t origin; // origin of sound effect
79 vec_t dist_mult; // distance multiplier (attenuation/clipK)
80 int master_vol; // 0-255 master volume
90 int dataofs; // chunk starts this many bytes from file start
94 void S_Startup (void);
95 void S_Shutdown (void);
96 void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
97 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
98 void S_StopSound (int entnum, int entchannel);
99 void S_StopAllSounds(qboolean clear);
100 void S_ClearBuffer (void);
101 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
102 void S_ExtraUpdate (void);
104 sfx_t *S_GetCached(const char *name);
105 sfx_t *S_PrecacheSound (char *sample, int complain);
106 void S_TouchSound (char *sample);
107 void S_ClearUsed (void);
108 void S_PurgeUnused (void);
109 void S_PaintChannels(int endtime);
110 void S_InitPaintChannels (void);
112 // picks a channel based on priorities, empty slots, number of channels
113 channel_t *SND_PickChannel(int entnum, int entchannel);
115 // spatializes a channel
116 void SND_Spatialize(channel_t *ch, int isstatic);
118 // initializes cycling through a DMA buffer and returns information on it
119 qboolean SNDDMA_Init(void);
121 // gets the current DMA position
122 int SNDDMA_GetDMAPos(void);
124 // shutdown the DMA xfer.
125 void SNDDMA_Shutdown(void);
127 // ====================================================================
128 // User-setable variables
129 // ====================================================================
131 // LordHavoc: increased from 128 to 516 (4 for NUM_AMBIENTS)
132 #define MAX_CHANNELS 516
133 // LordHavoc: increased maximum sound channels from 8 to 128
134 #define MAX_DYNAMIC_CHANNELS 128
137 extern channel_t channels[MAX_CHANNELS];
138 // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
139 // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
140 // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
142 extern int total_channels;
145 // Fake dma is a synchronous faking of the DMA progress used for
146 // isolating performance in the renderer. The fakedma_updates is
147 // number of times S_Update() is called per second.
150 extern qboolean fakedma;
151 extern int fakedma_updates;
152 extern int paintedtime;
153 extern int soundtime;
154 extern vec3_t listener_vieworigin;
155 extern vec3_t listener_viewforward;
156 extern vec3_t listener_viewleft;
157 extern vec3_t listener_viewup;
158 extern volatile dma_t *shm;
159 extern volatile dma_t sn;
160 extern vec_t sound_nominal_clip_dist;
162 extern cvar_t loadas8bit;
163 extern cvar_t bgmvolume;
164 extern cvar_t volume;
165 extern cvar_t snd_swapstereo;
167 extern cvar_t cdaudioinitialized;
168 extern cvar_t snd_initialized;
170 extern int snd_blocked;
172 void S_LocalSound (char *s);
173 sfxcache_t *S_LoadSound (sfx_t *s, int complain);
174 void S_UnloadSound(sfx_t *s);
176 wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength);
178 void SND_InitScaletable (void);
179 void SNDDMA_Submit(void);
181 void S_AmbientOff (void);
182 void S_AmbientOn (void);
184 void *S_LockBuffer(void);
185 void S_UnlockBuffer(void);
187 // add some data to the tail of the rawsamples queue
188 void S_RawSamples_Enqueue(short *samples, unsigned int length);
189 // read and remove some data from the head of the rawsamples queue
190 void S_RawSamples_Dequeue(int *samples, unsigned int length);
191 // empty the rawsamples queue
192 void S_RawSamples_ClearQueue(void);
193 // returns how much more data the queue wants, or 0 if it is already full enough
194 int S_RawSamples_QueueWantsMore(void);
196 // resamples one sound buffer into another, while changing the length
197 void S_ResampleBuffer16Stereo(short *input, int inputlength, short *output, int outputlength);
199 // returns the rate that the rawsamples system is running at
200 int S_RawSamples_SampleRate(void);