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;
38 qbyte data[4]; // variable sized
45 unsigned int channels;
49 #define SFXFLAG_SILENTLYMISSING (1 << 0) // if the sfx is missing and loaded with complain = false
50 #define SFXFLAG_USED (1 << 1)
52 typedef struct snd_fetcher_s snd_fetcher_t;
57 unsigned int flags; // cf SFXFLAG_* defines
61 const snd_fetcher_t *fetcher;
62 void *fetcher_data; // Per-sfx data for the sound fetching functions
68 int samples; // mono samples in buffer
69 int samplepos; // in mono samples
70 unsigned char *buffer;
71 int bufferlength; // used only by certain drivers
76 sfx_t *sfx; // sfx number
77 int forceloop; // force looping even if the sound is not looped
78 int leftvol; // 0-255 volume
79 int rightvol; // 0-255 volume
80 int end; // end time in global paintsamples
81 int lastptime; // last time this channel was painted
82 int pos; // sample position in sfx
83 int looping; // where to loop, -1 = no looping
84 int entnum; // to allow overriding a specific sound
86 vec3_t origin; // origin of sound effect
87 vec_t dist_mult; // distance multiplier (attenuation/clipK)
88 int master_vol; // 0-255 master volume
89 void *fetcher_data; // Per-channel data for the sound fetching function
92 typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples);
93 typedef void (*snd_fetcher_end_t) (channel_t* ch);
96 snd_fetcher_getsb_t getsb;
97 snd_fetcher_end_t end;
101 void S_Startup (void);
102 void S_Shutdown (void);
103 void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
104 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
105 void S_StopSound (int entnum, int entchannel);
106 void S_StopAllSounds(qboolean clear);
107 void S_ClearBuffer (void);
108 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
109 void S_ExtraUpdate (void);
111 sfx_t *S_GetCached(const char *name);
112 sfx_t *S_PrecacheSound (char *sample, int complain);
113 void S_TouchSound (char *sample);
114 void S_ClearUsed (void);
115 void S_PurgeUnused (void);
116 void S_PaintChannels(int endtime);
117 void S_InitPaintChannels (void);
119 // initializes cycling through a DMA buffer and returns information on it
120 qboolean SNDDMA_Init(void);
122 // gets the current DMA position
123 int SNDDMA_GetDMAPos(void);
125 // shutdown the DMA xfer.
126 void SNDDMA_Shutdown(void);
128 extern size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* in_format, qbyte *out_data, const char* sfxname);
130 // ====================================================================
131 // User-setable variables
132 // ====================================================================
134 // LordHavoc: increased from 128 to 516 (4 for NUM_AMBIENTS)
135 #define MAX_CHANNELS 516
136 // LordHavoc: increased maximum sound channels from 8 to 128
137 #define MAX_DYNAMIC_CHANNELS 128
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
145 extern unsigned int total_channels;
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.
153 extern qboolean fakedma;
154 extern int fakedma_updates;
155 extern int paintedtime;
156 extern int soundtime;
157 extern vec3_t listener_vieworigin;
158 extern vec3_t listener_viewforward;
159 extern vec3_t listener_viewleft;
160 extern vec3_t listener_viewup;
161 extern volatile dma_t *shm;
162 extern volatile dma_t sn;
163 extern vec_t sound_nominal_clip_dist;
165 extern cvar_t loadas8bit;
166 extern cvar_t bgmvolume;
167 extern cvar_t volume;
168 extern cvar_t snd_swapstereo;
170 extern cvar_t cdaudioinitialized;
171 extern cvar_t snd_initialized;
172 extern cvar_t snd_streaming;
174 extern int snd_blocked;
176 void S_LocalSound (char *s);
177 qboolean S_LoadSound (sfx_t *s, int complain);
178 void S_UnloadSound(sfx_t *s);
180 void SND_InitScaletable (void);
181 void SNDDMA_Submit(void);
183 void S_AmbientOff (void);
184 void S_AmbientOn (void);
186 void *S_LockBuffer(void);
187 void S_UnlockBuffer(void);
189 // add some data to the tail of the rawsamples queue
190 void S_RawSamples_Enqueue(short *samples, unsigned int length);
191 // read and remove some data from the head of the rawsamples queue
192 void S_RawSamples_Dequeue(int *samples, unsigned int length);
193 // empty the rawsamples queue
194 void S_RawSamples_ClearQueue(void);
195 // returns how much more data the queue wants, or 0 if it is already full enough
196 int S_RawSamples_QueueWantsMore(void);
198 // resamples one sound buffer into another, while changing the length
199 void S_ResampleBuffer16Stereo(short *input, int inputlength, short *output, int outputlength);
201 // returns the rate that the rawsamples system is running at
202 int S_RawSamples_SampleRate(void);