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 qbyte data[4]; // variable sized
39 unsigned int channels;
43 #define SFXFLAG_NONE 0
44 #define SFXFLAG_SILENTLYMISSING (1 << 0) // if the sfx is missing and loaded with complain = false
45 #define SFXFLAG_USED (1 << 1)
46 #define SFXFLAG_STREAMED (1 << 2) // informative only. You shouldn't need to know that
48 typedef struct snd_fetcher_s snd_fetcher_t;
53 unsigned int flags; // cf SFXFLAG_* defines
57 const snd_fetcher_t *fetcher;
58 void *fetcher_data; // Per-sfx data for the sound fetching functions
64 int samples; // mono samples in buffer
65 int samplepos; // in mono samples
66 unsigned char *buffer;
67 int bufferlength; // used only by certain drivers
71 #define CHANNELFLAG_NONE 0
72 #define CHANNELFLAG_FORCELOOP (1 << 0) // force looping even if the sound is not looped
73 #define CHANNELFLAG_LOCALSOUND (1 << 1) // non-game sound (ex: menu sound)
74 #define CHANNELFLAG_PAUSED (1 << 2)
78 sfx_t *sfx; // sfx number
79 unsigned int flags; // cf CHANNELFLAG_* defines
80 int leftvol; // 0-255 volume
81 int rightvol; // 0-255 volume
82 int end; // end time in global paintsamples
83 int lastptime; // last time this channel was painted
84 int pos; // sample position in sfx
85 int looping; // where to loop, -1 = no looping
86 int entnum; // to allow overriding a specific sound
88 vec3_t origin; // origin of sound effect
89 vec_t dist_mult; // distance multiplier (attenuation/clipK)
90 int master_vol; // 0-255 master volume
91 void *fetcher_data; // Per-channel data for the sound fetching function
94 typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples);
95 typedef void (*snd_fetcher_end_t) (channel_t* ch);
98 snd_fetcher_getsb_t getsb;
99 snd_fetcher_end_t end;
103 void S_Startup (void);
104 void S_Shutdown (void);
105 // S_StartSound returns the channel index, or -1 if an error occurred
106 int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
107 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
108 void S_StopChannel (unsigned int channel_ind);
109 void S_PauseChannel (unsigned int channel_ind, qboolean toggle);
110 void S_LoopChannel (unsigned int channel_ind, qboolean toggle);
111 void S_StopSound (int entnum, int entchannel);
112 void S_StopAllSounds(qboolean clear);
113 void S_PauseGameSounds (void);
114 void S_ResumeGameSounds (void);
115 void S_SetChannelVolume (unsigned int ch_ind, float fvol);
116 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
117 void S_ExtraUpdate (void);
119 sfx_t *S_GetCached(const char *name, qboolean stdpath);
120 sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean stdpath);
121 void S_TouchSound (const char *sample, qboolean stdpath);
122 void S_ClearUsed (void);
123 void S_PurgeUnused (void);
124 void S_PaintChannels(int endtime);
125 void S_InitPaintChannels (void);
127 // initializes cycling through a DMA buffer and returns information on it
128 qboolean SNDDMA_Init(void);
130 // gets the current DMA position
131 int SNDDMA_GetDMAPos(void);
133 // shutdown the DMA xfer.
134 void SNDDMA_Shutdown(void);
136 extern size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* in_format, qbyte *out_data, const char* sfxname);
138 // ====================================================================
139 // User-setable variables
140 // ====================================================================
142 // LordHavoc: increased from 128 to 516 (4 for NUM_AMBIENTS)
143 #define MAX_CHANNELS 516
144 // LordHavoc: increased maximum sound channels from 8 to 128
145 #define MAX_DYNAMIC_CHANNELS 128
148 extern channel_t channels[MAX_CHANNELS];
149 // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
150 // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
151 // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
153 extern unsigned int total_channels;
156 // Fake dma is a synchronous faking of the DMA progress used for
157 // isolating performance in the renderer. The fakedma_updates is
158 // number of times S_Update() is called per second.
161 extern qboolean fakedma;
162 extern int fakedma_updates;
163 extern int paintedtime;
164 extern int soundtime;
165 extern vec3_t listener_vieworigin;
166 extern vec3_t listener_viewforward;
167 extern vec3_t listener_viewleft;
168 extern vec3_t listener_viewup;
169 extern volatile dma_t *shm;
170 extern vec_t sound_nominal_clip_dist;
172 extern cvar_t bgmvolume;
173 extern cvar_t volume;
174 extern cvar_t snd_swapstereo;
176 extern cvar_t cdaudioinitialized;
177 extern cvar_t snd_initialized;
178 extern cvar_t snd_streaming;
180 extern int snd_blocked;
182 void S_LocalSound (const char *s, qboolean stdpath);
183 qboolean S_LoadSound (sfx_t *s, qboolean complain);
184 void S_UnloadSound(sfx_t *s);
186 void SND_InitScaletable (void);
187 void SNDDMA_Submit(void);
189 void *S_LockBuffer(void);
190 void S_UnlockBuffer(void);