]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - sound.h
r_refdef.vieworg and r_refdef.viewangles replaced by r_refdef.viewentitymatrix
[xonotic/darkplaces.git] / sound.h
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 typedef struct
29 {
30         int left;
31         int right;
32 } portable_samplepair_t;
33
34 typedef struct
35 {
36         int     length;
37         int     loopstart;
38         int     speed;
39         int     width;
40         int     stereo;
41         qbyte   data[1];                // variable sized
42 } sfxcache_t;
43
44 typedef struct sfx_s
45 {
46         char    name[MAX_QPATH];
47         mempool_t       *mempool;
48         sfxcache_t      *sfxcache;
49         int silentlymissing; // true if missing and loaded with complain = false
50 } sfx_t;
51
52 typedef struct
53 {
54         int                             channels;
55         int                             samples;                                // mono samples in buffer
56         int                             samplepos;                              // in mono samples
57         int                             samplebits;
58         int                             speed;
59         unsigned char   *buffer;
60         int                             bufferlength; // used only by certain drivers
61 } dma_t;
62
63 typedef struct
64 {
65         sfx_t   *sfx;                   // sfx number
66         int             forceloop;              // force looping even if the sound is not looped
67         int             leftvol;                // 0-255 volume
68         int             rightvol;               // 0-255 volume
69         int             end;                    // end time in global paintsamples
70         int     pos;                    // sample position in sfx
71         int             looping;                // where to loop, -1 = no looping
72         int             entnum;                 // to allow overriding a specific sound
73         int             entchannel;             //
74         vec3_t  origin;                 // origin of sound effect
75         vec_t   dist_mult;              // distance multiplier (attenuation/clipK)
76         int             master_vol;             // 0-255 master volume
77 } channel_t;
78
79 typedef struct
80 {
81         int             rate;
82         int             width;
83         int             channels;
84         int             loopstart;
85         int             samples;
86         int             dataofs;                // chunk starts this many bytes from file start
87 } wavinfo_t;
88
89 void S_Init (void);
90 void S_Startup (void);
91 void S_Shutdown (void);
92 void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation);
93 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
94 void S_StopSound (int entnum, int entchannel);
95 void S_StopAllSounds(qboolean clear);
96 void S_ClearBuffer (void);
97 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
98 void S_ExtraUpdate (void);
99
100 sfx_t *S_GetCached(const char *name);
101 sfx_t *S_PrecacheSound (char *sample, int complain);
102 void S_TouchSound (char *sample);
103 void S_ClearPrecache (void);
104 void S_BeginPrecaching (void);
105 void S_EndPrecaching (void);
106 void S_PaintChannels(int endtime);
107 void S_InitPaintChannels (void);
108
109 // picks a channel based on priorities, empty slots, number of channels
110 channel_t *SND_PickChannel(int entnum, int entchannel);
111
112 // spatializes a channel
113 void SND_Spatialize(channel_t *ch, int isstatic);
114
115 // initializes cycling through a DMA buffer and returns information on it
116 qboolean SNDDMA_Init(void);
117
118 // gets the current DMA position
119 int SNDDMA_GetDMAPos(void);
120
121 // shutdown the DMA xfer.
122 void SNDDMA_Shutdown(void);
123
124 // ====================================================================
125 // User-setable variables
126 // ====================================================================
127
128 // LordHavoc: increased from 128 to 516 (4 for NUM_AMBIENTS)
129 #define MAX_CHANNELS                    516
130 // LordHavoc: increased maximum sound channels from 8 to 128
131 #define MAX_DYNAMIC_CHANNELS    128
132
133
134 extern channel_t channels[MAX_CHANNELS];
135 // 0 to MAX_DYNAMIC_CHANNELS-1  = normal entity sounds
136 // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
137 // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
138
139 extern int total_channels;
140
141 //
142 // Fake dma is a synchronous faking of the DMA progress used for
143 // isolating performance in the renderer.  The fakedma_updates is
144 // number of times S_Update() is called per second.
145 //
146
147 extern qboolean fakedma;
148 extern int fakedma_updates;
149 extern int paintedtime;
150 extern int soundtime;
151 extern vec3_t listener_vieworigin;
152 extern vec3_t listener_viewforward;
153 extern vec3_t listener_viewleft;
154 extern vec3_t listener_viewup;
155 extern volatile dma_t *shm;
156 extern volatile dma_t sn;
157 extern vec_t sound_nominal_clip_dist;
158
159 extern cvar_t loadas8bit;
160 extern cvar_t bgmvolume;
161 extern cvar_t volume;
162 extern cvar_t snd_swapstereo;
163
164 extern qboolean cdaudioinitialized;
165 extern qboolean snd_initialized;
166
167 extern int snd_blocked;
168
169 void S_LocalSound (char *s);
170 sfxcache_t *S_LoadSound (sfx_t *s, int complain);
171 void S_UnloadSound(sfx_t *s);
172
173 wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength);
174
175 void SND_InitScaletable (void);
176 void SNDDMA_Submit(void);
177
178 void S_AmbientOff (void);
179 void S_AmbientOn (void);
180
181 void *S_LockBuffer(void);
182 void S_UnlockBuffer(void);
183
184 // add some data to the tail of the rawsamples queue
185 void S_RawSamples_Enqueue(short *samples, unsigned int length);
186 // read and remove some data from the head of the rawsamples queue
187 void S_RawSamples_Dequeue(int *samples, unsigned int length);
188 // empty the rawsamples queue
189 void S_RawSamples_ClearQueue(void);
190 // returns how much more data the queue wants, or 0 if it is already full enough
191 int S_RawSamples_QueueWantsMore(void);
192
193 // resamples one sound buffer into another, while changing the length
194 void S_ResampleBuffer16Stereo(short *input, int inputlength, short *output, int outputlength);
195
196 // returns the rate that the rawsamples system is running at
197 int S_RawSamples_SampleRate(void);
198
199 #endif
200