Debian Codegraph @

code/client/snd_local.h

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // snd_local.h -- private sound definations
23
24
25 #include "../qcommon/q_shared.h"
26 #include "../qcommon/qcommon.h"
27 #include "snd_public.h"
28
29 #define PAINTBUFFER_SIZE 4096 // this is in samples
30
31 #define SND_CHUNK_SIZE 1024 // samples
32 #define SND_CHUNK_SIZE_FLOAT (SND_CHUNK_SIZE/2) // floats
33 #define SND_CHUNK_SIZE_BYTE (SND_CHUNK_SIZE*2) // floats
34
35 typedef struct {
36 int left; // the final values will be clamped to +/- 0x00ffff00 and shifted down
37 int right;
38 } portable_samplepair_t;
39
40 typedef struct adpcm_state {
41 short sample; /* Previous output value */
42 char index; /* Index into stepsize table */
43 } adpcm_state_t;
44
45 typedef struct sndBuffer_s {
46 short sndChunk[SND_CHUNK_SIZE];
47 struct sndBuffer_s *next;
48 int size;
49 adpcm_state_t adpcm;
50 } sndBuffer;
51
52 typedef struct sfx_s {
53 sndBuffer *soundData;
54 qboolean defaultSound; // couldn't be loaded, so use buzz
55 qboolean inMemory; // not in Memory
56 qboolean soundCompressed; // not in Memory
57 int soundCompressionMethod;
58 int soundLength;
59 int soundChannels;
60 char soundName[MAX_QPATH];
61 int lastTimeUsed;
62 struct sfx_s *next;
63 } sfx_t;
64
65 typedef struct {
66 int channels;
67 int samples; // mono samples in buffer
68 int fullsamples; // samples with all channels in buffer (samples divided by channels)
69 int submission_chunk; // don't mix less than this #
70 int samplebits;
71 int isfloat;
72 int speed;
73 byte *buffer;
74 } dma_t;
75
76 #define START_SAMPLE_IMMEDIATE 0x7fffffff
77
78 #define MAX_DOPPLER_SCALE 50.0f //arbitrary
79
80 #define THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f)
81
82 typedef struct loopSound_s {
83 vec3_t origin;
84 vec3_t velocity;
85 sfx_t *sfx;
86 int mergeFrame;
87 qboolean active;
88 qboolean kill;
89 qboolean doppler;
90 float dopplerScale;
91 float oldDopplerScale;
92 int framenum;
93 } loopSound_t;
94
95 typedef struct
96 {
97 int allocTime;
98 int startSample; // START_SAMPLE_IMMEDIATE = set immediately on next mix
99 int entnum; // to allow overriding a specific sound
100 int entchannel; // to allow overriding a specific sound
101 int leftvol; // 0-255 volume after spatialization
102 int rightvol; // 0-255 volume after spatialization
103 int master_vol; // 0-255 volume before spatialization
104 float dopplerScale;
105 float oldDopplerScale;
106 vec3_t origin; // only use if fixed_origin is set
107 qboolean fixed_origin; // use origin instead of fetching entnum's origin
108 sfx_t *thesfx; // sfx structure
109 qboolean doppler;
110 qboolean fullVolume;
111 } channel_t;
112
113
114 #define WAV_FORMAT_PCM 1
115
116
117 typedef struct {
118 int format;
119 int rate;
120 int width;
121 int channels;
122 int samples;
123 int dataofs; // chunk starts this many bytes from file start
124 } wavinfo_t;
125
126 // Interface between Q3 sound "api" and the sound backend
127 typedef struct
128 {
129 void (*Shutdown)(void);
130 void (*StartSound)( vec3_t origin, int entnum, int entchannel, sfxHandle_t sfx );
131 void (*StartLocalSound)( sfxHandle_t sfx, int channelNum );
132 void (*StartBackgroundTrack)( const char *intro, const char *loop );
133 void (*StopBackgroundTrack)( void );
134 void (*RawSamples)(int stream, int samples, int rate, int width, int channels, const byte *data, float volume, int entityNum);
135 void (*StopAllSounds)( void );
136 void (*ClearLoopingSounds)( qboolean killall );
137 void (*AddLoopingSound)( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx );
138 void (*AddRealLoopingSound)( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx );
139 void (*StopLoopingSound)(int entityNum );
140 void (*Respatialize)( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater );
141 void (*UpdateEntityPosition)( int entityNum, const vec3_t origin );
142 void (*Update)( void );
143 void (*DisableSounds)( void );
144 void (*BeginRegistration)( void );
145 sfxHandle_t (*RegisterSound)( const char *sample, qboolean compressed );
146 void (*ClearSoundBuffer)( void );
147 void (*SoundInfo)( void );
148 void (*SoundList)( void );
149 #ifdef USE_VOIP
150 void (*StartCapture)( void );
151 int (*AvailableCaptureSamples)( void );
152 void (*Capture)( int samples, byte *data );
153 void (*StopCapture)( void );
154 void (*MasterGain)( float gain );
155 #endif
156 } soundInterface_t;
157
158
159 /*
160 ====================================================================
161
162 SYSTEM SPECIFIC FUNCTIONS
163
164 ====================================================================
165 */
166
167 // initializes cycling through a DMA buffer and returns information on it
168 qboolean SNDDMA_Init(void);
169
170 // gets the current DMA position
171 int SNDDMA_GetDMAPos(void);
172
173 // shutdown the DMA xfer.
174 void SNDDMA_Shutdown(void);
175
176 void SNDDMA_BeginPainting (void);
177
178 void SNDDMA_Submit(void);
179
180 #ifdef USE_VOIP
181 void SNDDMA_StartCapture(void);
182 int SNDDMA_AvailableCaptureSamples(void);
183 void SNDDMA_Capture(int samples, byte *data);
184 void SNDDMA_StopCapture(void);
185 void SNDDMA_MasterGain(float val);
186 #endif
187
188
189 //====================================================================
190
191 #define MAX_CHANNELS 96
192
193 extern channel_t s_channels[MAX_CHANNELS];
194 extern channel_t loop_channels[MAX_CHANNELS];
195 extern int numLoopChannels;
196
197 extern int s_paintedtime;
198 extern vec3_t listener_forward;
199 extern vec3_t listener_right;
200 extern vec3_t listener_up;
201 extern dma_t dma;
202
203 #define MAX_RAW_SAMPLES 16384
204 #define MAX_RAW_STREAMS (MAX_CLIENTS * 2 + 1)
205 extern portable_samplepair_t s_rawsamples[MAX_RAW_STREAMS][MAX_RAW_SAMPLES];
206 extern int s_rawend[MAX_RAW_STREAMS];
207
208 extern cvar_t *s_volume;
209 extern cvar_t *s_musicVolume;
210 extern cvar_t *s_muted;
211 extern cvar_t *s_doppler;
212
213 extern cvar_t *s_testsound;
214
215 qboolean S_LoadSound( sfx_t *sfx );
216
217 void SND_free(sndBuffer *v);
218 sndBuffer* SND_malloc( void );
219 void SND_setup( void );
220 void SND_shutdown(void);
221
222 void S_PaintChannels(int endtime);
223
224 void S_memoryLoad(sfx_t *sfx);
225
226 // spatializes a channel
227 void S_Spatialize(channel_t *ch);
228
229 // adpcm functions
230 int S_AdpcmMemoryNeeded( const wavinfo_t *info );
231 void S_AdpcmEncodeSound( sfx_t *sfx, short *samples );
232 void S_AdpcmGetSamples(sndBuffer *chunk, short *to);
233
234 // wavelet function
235
236 #define SENTINEL_MULAW_ZERO_RUN 127
237 #define SENTINEL_MULAW_FOUR_BIT_RUN 126
238
239 void S_FreeOldestSound( void );
240
241 #define NXStream byte
242
243 void encodeWavelet(sfx_t *sfx, short *packets);
244 void decodeWavelet( sndBuffer *stream, short *packets);
245
246 void encodeMuLaw( sfx_t *sfx, short *packets);
247 extern short mulawToShort[256];
248
249 extern short *sfxScratchBuffer;
250 extern sfx_t *sfxScratchPointer;
251 extern int sfxScratchIndex;
252
253 qboolean S_Base_Init( soundInterface_t *si );
254
255 // OpenAL stuff
256 typedef enum
257 {
258 SRCPRI_AMBIENT = 0, // Ambient sound effects
259 SRCPRI_ENTITY, // Entity sound effects
260 SRCPRI_ONESHOT, // One-shot sounds
261 SRCPRI_LOCAL, // Local sounds
262 SRCPRI_STREAM // Streams (music, cutscenes)
263 } alSrcPriority_t;
264
265 typedef int srcHandle_t;
266
267 qboolean S_AL_Init( soundInterface_t *si );
268
269 #ifdef idppc_altivec
270 void S_PaintChannelFrom16_altivec( portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE], int snd_vol, channel_t *ch, const sfx_t *sc, int count, int sampleOffset, int bufferOffset );
271 #endif