Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

snd_local.h (5391B)


      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 Foobar; 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 "../game/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 	char 			soundName[MAX_QPATH];
     60 	int				lastTimeUsed;
     61 	struct sfx_s	*next;
     62 } sfx_t;
     63 
     64 typedef struct {
     65 	int			channels;
     66 	int			samples;				// mono samples in buffer
     67 	int			submission_chunk;		// don't mix less than this #
     68 	int			samplebits;
     69 	int			speed;
     70 	byte		*buffer;
     71 } dma_t;
     72 
     73 #define START_SAMPLE_IMMEDIATE	0x7fffffff
     74 
     75 typedef struct loopSound_s {
     76 	vec3_t		origin;
     77 	vec3_t		velocity;
     78 	sfx_t		*sfx;
     79 	int			mergeFrame;
     80 	qboolean	active;
     81 	qboolean	kill;
     82 	qboolean	doppler;
     83 	float		dopplerScale;
     84 	float		oldDopplerScale;
     85 	int			framenum;
     86 } loopSound_t;
     87 
     88 typedef struct
     89 {
     90 	int			allocTime;
     91 	int			startSample;	// START_SAMPLE_IMMEDIATE = set immediately on next mix
     92 	int			entnum;			// to allow overriding a specific sound
     93 	int			entchannel;		// to allow overriding a specific sound
     94 	int			leftvol;		// 0-255 volume after spatialization
     95 	int			rightvol;		// 0-255 volume after spatialization
     96 	int			master_vol;		// 0-255 volume before spatialization
     97 	float		dopplerScale;
     98 	float		oldDopplerScale;
     99 	vec3_t		origin;			// only use if fixed_origin is set
    100 	qboolean	fixed_origin;	// use origin instead of fetching entnum's origin
    101 	sfx_t		*thesfx;		// sfx structure
    102 	qboolean	doppler;
    103 } channel_t;
    104 
    105 
    106 #define	WAV_FORMAT_PCM		1
    107 
    108 
    109 typedef struct {
    110 	int			format;
    111 	int			rate;
    112 	int			width;
    113 	int			channels;
    114 	int			samples;
    115 	int			dataofs;		// chunk starts this many bytes from file start
    116 } wavinfo_t;
    117 
    118 
    119 /*
    120 ====================================================================
    121 
    122   SYSTEM SPECIFIC FUNCTIONS
    123 
    124 ====================================================================
    125 */
    126 
    127 // initializes cycling through a DMA buffer and returns information on it
    128 qboolean SNDDMA_Init(void);
    129 
    130 // gets the current DMA position
    131 int		SNDDMA_GetDMAPos(void);
    132 
    133 // shutdown the DMA xfer.
    134 void	SNDDMA_Shutdown(void);
    135 
    136 void	SNDDMA_BeginPainting (void);
    137 
    138 void	SNDDMA_Submit(void);
    139 
    140 //====================================================================
    141 
    142 #define	MAX_CHANNELS			96
    143 
    144 extern	channel_t   s_channels[MAX_CHANNELS];
    145 extern	channel_t   loop_channels[MAX_CHANNELS];
    146 extern	int		numLoopChannels;
    147 
    148 extern	int		s_paintedtime;
    149 extern	int		s_rawend;
    150 extern	vec3_t	listener_forward;
    151 extern	vec3_t	listener_right;
    152 extern	vec3_t	listener_up;
    153 extern	dma_t	dma;
    154 
    155 #define	MAX_RAW_SAMPLES	16384
    156 extern	portable_samplepair_t	s_rawsamples[MAX_RAW_SAMPLES];
    157 
    158 extern cvar_t	*s_volume;
    159 extern cvar_t	*s_nosound;
    160 extern cvar_t	*s_khz;
    161 extern cvar_t	*s_show;
    162 extern cvar_t	*s_mixahead;
    163 
    164 extern cvar_t	*s_testsound;
    165 extern cvar_t	*s_separation;
    166 
    167 qboolean S_LoadSound( sfx_t *sfx );
    168 
    169 void		SND_free(sndBuffer *v);
    170 sndBuffer*	SND_malloc();
    171 void		SND_setup();
    172 
    173 void S_PaintChannels(int endtime);
    174 
    175 void S_memoryLoad(sfx_t *sfx);
    176 portable_samplepair_t *S_GetRawSamplePointer();
    177 
    178 // spatializes a channel
    179 void S_Spatialize(channel_t *ch);
    180 
    181 // adpcm functions
    182 int  S_AdpcmMemoryNeeded( const wavinfo_t *info );
    183 void S_AdpcmEncodeSound( sfx_t *sfx, short *samples );
    184 void S_AdpcmGetSamples(sndBuffer *chunk, short *to);
    185 
    186 // wavelet function
    187 
    188 #define SENTINEL_MULAW_ZERO_RUN 127
    189 #define SENTINEL_MULAW_FOUR_BIT_RUN 126
    190 
    191 void S_FreeOldestSound();
    192 
    193 #define	NXStream byte
    194 
    195 void encodeWavelet(sfx_t *sfx, short *packets);
    196 void decodeWavelet( sndBuffer *stream, short *packets);
    197 
    198 void encodeMuLaw( sfx_t *sfx, short *packets);
    199 extern short mulawToShort[256];
    200 
    201 extern short *sfxScratchBuffer;
    202 extern sfx_t *sfxScratchPointer;
    203 extern int	   sfxScratchIndex;
    204