1 /*
2 Copyright (C) 1997-2001 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 // snd_loc.h -- private sound functions
21 
22 
23 #include "../client/snd_openal.h"
24 
25 // !!! if this is changed, the asm code must change !!!
26 typedef struct
27 {
28 	int			left;
29 	int			right;
30 } portable_samplepair_t;
31 
32 
33 // a playsound_t will be generated by each call to S_StartSound,
34 // when the mixer reaches playsound->begin, the playsound will
35 // be assigned to a channel
36 typedef struct playsound_s
37 {
38 	struct playsound_s	*prev, *next;
39 	sfx_t		*sfx;
40 	float		volume;
41 	float		attenuation;
42 	int			entnum;
43 	int			entchannel;
44 	qboolean	fixed_origin;	// use origin field instead of entnum's origin
45 	vec3_t		origin;
46 	uint32		begin;			// begin on this sample
47 } playsound_t;
48 
49 typedef struct
50 {
51 	int			channels;
52 	int			samples;				// mono samples in buffer
53 	int			submission_chunk;		// don't mix less than this #
54 	int			samplepos;				// in mono samples
55 	int			samplebits;
56 	int			speed;
57 	byte		*buffer;
58 } dma_t;
59 
60 // !!! if this is changed, the asm code must change !!!
61 typedef struct
62 {
63 	sfx_t		*sfx;			// sfx number
64 	int			leftvol;		// 0-255 volume
65 	int			rightvol;		// 0-255 volume
66 	int			end;			// end time in global paintsamples
67 	int 		pos;			// sample position in sfx
68 	int			looping;		// where to loop, -1 = no looping OBSOLETE?
69 	int			entnum;			// to allow overriding a specific sound
70 	int			entchannel;		//
71 	vec3_t		origin;			// only use if fixed_origin is set
72 	vec_t		dist_mult;		// distance multiplier (attenuation/clipK)
73 	int			master_vol;		// 0-255 master volume
74 	qboolean	fixed_origin;	// use origin instead of fetching entnum's origin
75 	qboolean	autosound;		// from an entity->sound, cleared each frame
76 } channel_t;
77 
78 typedef struct
79 {
80 	int			rate;
81 	int			width;
82 	int			channels;
83 	int			loopstart;
84 	int			samples;
85 	int			dataofs;		// chunk starts this many bytes from file start
86 } wavinfo_t;
87 
88 
89 /*
90 ====================================================================
91 
92   SYSTEM SPECIFIC FUNCTIONS
93 
94 ====================================================================
95 */
96 
97 // initializes cycling through a DMA buffer and returns information on it
98 qboolean SNDDMA_Init(int fullInit);
99 
100 // gets the current DMA position
101 int		SNDDMA_GetDMAPos(void);
102 
103 // shutdown the DMA xfer.
104 void	SNDDMA_Shutdown(void);
105 
106 void	SNDDMA_BeginPainting (void);
107 
108 void	SNDDMA_Submit(void);
109 
110 //====================================================================
111 
112 #define	MAX_CHANNELS			32
113 extern	channel_t   channels[MAX_CHANNELS];
114 
115 extern	int		paintedtime;
116 extern	int		s_rawend;
117 extern	vec3_t	listener_origin;
118 extern	vec3_t	listener_forward;
119 extern	vec3_t	listener_right;
120 extern	vec3_t	listener_up;
121 extern	dma_t	dma;
122 extern	playsound_t	s_pendingplays;
123 
124 #define	MAX_RAW_SAMPLES	8192
125 extern	portable_samplepair_t	s_rawsamples[MAX_RAW_SAMPLES];
126 
127 extern cvar_t	*s_volume;
128 extern cvar_t	*s_nosound;
129 extern cvar_t	*s_loadas8bit;
130 extern cvar_t	*s_khz;
131 extern cvar_t	*s_testsound;
132 extern cvar_t	*s_primary;
133 
134 wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength);
135 
136 void S_InitScaletable (void);
137 
138 sfxcache_t *S_LoadSound (sfx_t *s);
139 
140 void S_IssuePlaysound (playsound_t *ps);
141 
142 void S_PaintChannels(int endtime);
143 
144 // picks a channel based on priorities, empty slots, number of channels
145 channel_t *S_PickChannel(int entnum, int entchannel);
146 
147 // spatializes a channel
148 void S_Spatialize(channel_t *ch);
149 
150 #define		SOUND_FULLVOLUME	80.0f
151 #define		SOUND_LOOPATTENUATE	0.003f
152 
153 #ifdef USE_OPENAL
154 qboolean S_OpenAL_LoadSound (sfx_t *sfx);
155 extern cvar_t	*s_openal_device;
156 #endif
157 
158 //OpenAL
159 /*#define	MAX_OPENAL_BUFFERS 1024
160 #define MAX_OPENAL_SOURCES 128
161 
162 #define OPENAL_SCALE_VALUE 0.010f
163 
164 qboolean OpenAL_Init (void);
165 
166 #ifdef USE_OPENAL
167 extern uint32 openAlMaxSources;
168 extern uint32 openAlMaxBuffers;
169 
170 qboolean AL_Attenuated (int i);
171 void OpenAL_Shutdown (void);
172 
173 void OpenAL_DestroyBuffers (void);
174 ALint OpenAL_GetFreeBuffer (void);
175 ALint OpenAL_GetFreeSource (void);
176 
177 void OpenAL_FreeAlIndexes (int index);
178 int OpenAL_GetFreeAlIndex (void);
179 
180 void OpenAL_CheckForError (void);
181 
182 typedef struct OpenALBuffer_s
183 {
184 	ALuint buffer;
185 	ALboolean inuse;
186 } OpenALBuffer_t;
187 
188 typedef struct alindex_s
189 {
190 	qboolean	inuse;
191 	qboolean	loopsound;
192 	qboolean	fixed_origin;
193 	vec3_t		origin;
194 	int			entnum;
195 	int			sourceIndex;
196 	int			lastloopframe;
197 	float		attenuation;
198 	char		soundname[MAX_QPATH];
199 } alindex_t;
200 
201 extern OpenALBuffer_t	g_Buffers[MAX_OPENAL_BUFFERS];
202 extern ALuint			g_Sources[MAX_OPENAL_SOURCES];
203 extern alindex_t		alindex[MAX_OPENAL_SOURCES];*/
204 
205 extern	cvar_t	*s_openal_extensions;
206 extern	cvar_t	*s_openal_eax;
207