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 // !!! if this is changed, it much be changed in asm_i386.h too !!!
29 typedef struct
30 {
31 	int left;
32 	int right;
33 } portable_samplepair_t;
34 
35 typedef struct sfx_s
36 {
37 	char 	name[MAX_QPATH];
38 	cache_user_t	cache;
39 } sfx_t;
40 
41 // !!! if this is changed, it much be changed in asm_i386.h too !!!
42 typedef struct
43 {
44 	int 	length;
45 	int 	loopstart;
46 	int 	speed;
47 	int 	width;
48 	int 	stereo;
49 	byte	data[1];		// variable sized
50 } sfxcache_t;
51 
52 typedef struct
53 {
54 	qboolean		gamealive;
55 	qboolean		soundalive;
56 	qboolean		splitbuffer;
57 	int				channels;
58 	int				samples;				// mono samples in buffer
59 	int				submission_chunk;		// don't mix less than this #
60 	int				samplepos;				// in mono samples
61 	int				samplebits;
62 	int				speed;
63 	unsigned char	*buffer;
64 } dma_t;
65 
66 // !!! if this is changed, it much be changed in asm_i386.h too !!!
67 typedef struct
68 {
69 	sfx_t	*sfx;			// sfx number
70 	int		leftvol;		// 0-255 volume
71 	int		rightvol;		// 0-255 volume
72 	int		end;			// end time in global paintsamples
73 	int 	pos;			// sample position in sfx
74 	int		looping;		// where to loop, -1 = no looping
75 	int		entnum;			// to allow overriding a specific sound
76 	int		entchannel;		//
77 	vec3_t	origin;			// origin of sound effect
78 	vec_t	dist_mult;		// distance multiplier (attenuation/clipK)
79 	int		master_vol;		// 0-255 master volume
80 } channel_t;
81 
82 typedef struct
83 {
84 	int		rate;
85 	int		width;
86 	int		channels;
87 	int		loopstart;
88 	int		samples;
89 	int		dataofs;		// chunk starts this many bytes from file start
90 } wavinfo_t;
91 
92 typedef struct //MP3 Playback - Eradicator
93 {
94 	int                     samplerate;		// Samplerate (44100, 22050, 11025)
95 	byte                    channels;		// Channels (1 = Mono, 2 = Stereo)
96 	int                     samples;		// Number of samples
97 
98 	byte                    *mp3data;		// Pointer to the compressed MP3 data from the file
99 	int                     mp3pos;			// Position in the compressed buffer
100 	int                     mp3size;		// Size of the compressed buffer
101 
102 	byte                    *rawdata;		// Pointer to the decompressed MP3 data
103 	int                     rawpos;			// Position in the decompressed buffer
104 	int                     rawsize;		// Size of the decompressed buffer
105 } mp3_t;
106 
107 
108 void S_Init (void);
109 void S_Startup (void);
110 void S_Shutdown (void);
111 void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation);
112 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
113 void S_StopSound (int entnum, int entchannel);
114 void S_StopAllSounds(qboolean clear);
115 void S_ClearBuffer (void);
116 void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up);
117 void S_ExtraUpdate (void);
118 
119 sfx_t *S_PrecacheSound (char *sample);
120 void S_TouchSound (char *sample);
121 void S_ClearPrecache (void);
122 void S_BeginPrecaching (void);
123 void S_EndPrecaching (void);
124 void S_PaintChannels(int endtime);
125 void S_InitPaintChannels (void);
126 
127 // picks a channel based on priorities, empty slots, number of channels
128 channel_t *SND_PickChannel(int entnum, int entchannel);
129 
130 // spatializes a channel
131 void SND_Spatialize(channel_t *ch);
132 
133 // initializes cycling through a DMA buffer and returns information on it
134 qboolean SNDDMA_Init(void);
135 
136 // gets the current DMA position
137 int SNDDMA_GetDMAPos(void);
138 
139 // shutdown the DMA xfer.
140 void SNDDMA_Shutdown(void);
141 
142 // ====================================================================
143 // User-setable variables
144 // ====================================================================
145 
146 #ifndef OPENAL
147 #define	MAX_CHANNELS			128
148 #else
149 #define	MAX_CHANNELS			32
150 #endif
151 #define	MAX_DYNAMIC_CHANNELS	8
152 
153 
154 extern	channel_t   channels[MAX_CHANNELS];
155 // 0 to MAX_DYNAMIC_CHANNELS-1	= normal entity sounds
156 // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
157 // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
158 
159 extern	int			total_channels;
160 
161 //
162 // Fake dma is a synchronous faking of the DMA progress used for
163 // isolating performance in the renderer.  The fakedma_updates is
164 // number of times S_Update() is called per second.
165 //
166 
167 extern qboolean 		fakedma;
168 extern int 			fakedma_updates;
169 extern int		paintedtime;
170 extern vec3_t listener_origin;
171 extern vec3_t listener_forward;
172 extern vec3_t listener_right;
173 extern vec3_t listener_up;
174 extern volatile dma_t *shm;
175 extern volatile dma_t sn;
176 extern vec_t sound_nominal_clip_dist;
177 
178 extern	cvar_t loadas8bit;
179 extern	cvar_t bgmvolume;
180 extern	cvar_t volume;
181 
182 extern qboolean	snd_initialized;
183 
184 extern int		snd_blocked;
185 
186 void S_LocalSound (char *s);
187 sfxcache_t *S_LoadSound (sfx_t *s);
188 
189 wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength);
190 
191 void SND_InitScaletable (void);
192 void SNDDMA_Submit(void);
193 
194 void S_AmbientOff (void);
195 void S_AmbientOn (void);
196 
197 #ifdef _WIN32
198 void *S_LockBuffer(void); //New Sound - Eradicator
199 void S_UnlockBuffer(void);
200 #endif
201 
202 #endif
203