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