| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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; |
| 37 |
int right; |
| 38 |
} portable_samplepair_t; |
| 39 |
|
| 40 |
typedef struct adpcm_state { |
| 41 |
short sample; |
| 42 |
char index; |
| 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; |
| 55 |
qboolean inMemory; |
| 56 |
qboolean soundCompressed; |
| 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; |
| 68 |
int fullsamples; |
| 69 |
int submission_chunk; |
| 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; |
| 99 |
int entnum; |
| 100 |
int entchannel; |
| 101 |
int leftvol; |
| 102 |
int rightvol; |
| 103 |
int master_vol; |
| 104 |
float dopplerScale; |
| 105 |
float oldDopplerScale; |
| 106 |
vec3_t origin; |
| 107 |
qboolean fixed_origin; |
| 108 |
sfx_t *thesfx; |
| 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; |
| 124 |
} wavinfo_t; |
| 125 |
|
| 126 |
|
| 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 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
qboolean SNDDMA_Init(void); |
| 169 |
|
| 170 |
|
| 171 |
int SNDDMA_GetDMAPos(void); |
| 172 |
|
| 173 |
|
| 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 |
|
| 227 |
void S_Spatialize(channel_t *ch); |
| 228 |
|
| 229 |
|
| 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 |
|
| 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 |
|
| 256 |
typedef enum |
| 257 |
{ |
| 258 |
SRCPRI_AMBIENT = 0, |
| 259 |
SRCPRI_ENTITY, |
| 260 |
SRCPRI_ONESHOT, |
| 261 |
SRCPRI_LOCAL, |
| 262 |
SRCPRI_STREAM |
| 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 |