Allow auxiliary effect slot 0 when (un)setting the source auxiliary send
[openal-soft.git] / OpenAL32 / alExtension.c
blob54371ff468b81cec147dae442cab2cf470c4f7a9
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
21 #include <stdlib.h>
22 #include <string.h>
23 #include <ctype.h>
24 #include "alExtension.h"
25 #include "alError.h"
26 #include "alMain.h"
27 #include "alFilter.h"
28 #include "alEffect.h"
29 #include "alAuxEffectSlot.h"
30 #include "AL/al.h"
31 #include "AL/alc.h"
33 static ALfunction function[]= {
34 { "alEnable", (ALvoid *) alEnable },
35 { "alDisable", (ALvoid *) alDisable },
36 { "alIsEnabled", (ALvoid *) alIsEnabled },
37 { "alGetString", (ALvoid *) alGetString },
38 { "alGetBooleanv", (ALvoid *) alGetBooleanv },
39 { "alGetIntegerv", (ALvoid *) alGetIntegerv },
40 { "alGetFloatv", (ALvoid *) alGetFloatv },
41 { "alGetDoublev", (ALvoid *) alGetDoublev },
42 { "alGetBoolean", (ALvoid *) alGetBoolean },
43 { "alGetInteger", (ALvoid *) alGetInteger },
44 { "alGetFloat", (ALvoid *) alGetFloat },
45 { "alGetDouble", (ALvoid *) alGetDouble },
46 { "alGetError", (ALvoid *) alGetError },
47 { "alIsExtensionPresent", (ALvoid *) alIsExtensionPresent },
48 { "alGetProcAddress", (ALvoid *) alGetProcAddress },
49 { "alGetEnumValue", (ALvoid *) alGetEnumValue },
50 { "alListenerf", (ALvoid *) alListenerf },
51 { "alListener3f", (ALvoid *) alListener3f },
52 { "alListenerfv", (ALvoid *) alListenerfv },
53 { "alListeneri", (ALvoid *) alListeneri },
54 { "alListener3i", (ALvoid *) alListener3i },
55 { "alListeneriv", (ALvoid *) alListeneriv },
56 { "alGetListenerf", (ALvoid *) alGetListenerf },
57 { "alGetListener3f", (ALvoid *) alGetListener3f },
58 { "alGetListenerfv", (ALvoid *) alGetListenerfv },
59 { "alGetListeneri", (ALvoid *) alGetListeneri },
60 { "alGetListener3i", (ALvoid *) alGetListener3i },
61 { "alGetListeneriv", (ALvoid *) alGetListeneriv },
62 { "alGenSources", (ALvoid *) alGenSources },
63 { "alDeleteSources", (ALvoid *) alDeleteSources },
64 { "alIsSource", (ALvoid *) alIsSource },
65 { "alSourcef", (ALvoid *) alSourcef },
66 { "alSource3f", (ALvoid *) alSource3f },
67 { "alSourcefv", (ALvoid *) alSourcefv },
68 { "alSourcei", (ALvoid *) alSourcei },
69 { "alSource3i", (ALvoid *) alSource3i },
70 { "alSourceiv", (ALvoid *) alSourceiv },
71 { "alGetSourcef", (ALvoid *) alGetSourcef },
72 { "alGetSource3f", (ALvoid *) alGetSource3f },
73 { "alGetSourcefv", (ALvoid *) alGetSourcefv },
74 { "alGetSourcei", (ALvoid *) alGetSourcei },
75 { "alGetSource3i", (ALvoid *) alGetSource3i },
76 { "alGetSourceiv", (ALvoid *) alGetSourceiv },
77 { "alSourcePlayv", (ALvoid *) alSourcePlayv },
78 { "alSourceStopv", (ALvoid *) alSourceStopv },
79 { "alSourceRewindv", (ALvoid *) alSourceRewindv },
80 { "alSourcePausev", (ALvoid *) alSourcePausev },
81 { "alSourcePlay", (ALvoid *) alSourcePlay },
82 { "alSourceStop", (ALvoid *) alSourceStop },
83 { "alSourceRewind", (ALvoid *) alSourceRewind },
84 { "alSourcePause", (ALvoid *) alSourcePause },
85 { "alSourceQueueBuffers", (ALvoid *) alSourceQueueBuffers },
86 { "alSourceUnqueueBuffers", (ALvoid *) alSourceUnqueueBuffers },
87 { "alGenBuffers", (ALvoid *) alGenBuffers },
88 { "alDeleteBuffers", (ALvoid *) alDeleteBuffers },
89 { "alIsBuffer", (ALvoid *) alIsBuffer },
90 { "alBufferData", (ALvoid *) alBufferData },
91 { "alBufferf", (ALvoid *) alBufferf },
92 { "alBuffer3f", (ALvoid *) alBuffer3f },
93 { "alBufferfv", (ALvoid *) alBufferfv },
94 { "alBufferi", (ALvoid *) alBufferi },
95 { "alBuffer3i", (ALvoid *) alBuffer3i },
96 { "alBufferiv", (ALvoid *) alBufferiv },
97 { "alGetBufferf", (ALvoid *) alGetBufferf },
98 { "alGetBuffer3f", (ALvoid *) alGetBuffer3f },
99 { "alGetBufferfv", (ALvoid *) alGetBufferfv },
100 { "alGetBufferi", (ALvoid *) alGetBufferi },
101 { "alGetBuffer3i", (ALvoid *) alGetBuffer3i },
102 { "alGetBufferiv", (ALvoid *) alGetBufferiv },
103 { "alDopplerFactor", (ALvoid *) alDopplerFactor },
104 { "alDopplerVelocity", (ALvoid *) alDopplerVelocity },
105 { "alSpeedOfSound", (ALvoid *) alSpeedOfSound },
106 { "alDistanceModel", (ALvoid *) alDistanceModel },
108 { "alGenFilters", (ALvoid *) alGenFilters },
109 { "alDeleteFilters", (ALvoid *) alDeleteFilters },
110 { "alIsFilter", (ALvoid *) alIsFilter },
111 { "alFilteri", (ALvoid *) alFilteri },
112 { "alFilteriv", (ALvoid *) alFilteriv },
113 { "alFilterf", (ALvoid *) alFilterf },
114 { "alFilterfv", (ALvoid *) alFilterfv },
115 { "alGetFilteri", (ALvoid *) alGetFilteri },
116 { "alGetFilteriv", (ALvoid *) alGetFilteriv },
117 { "alGetFilterf", (ALvoid *) alGetFilterf },
118 { "alGetFilterfv", (ALvoid *) alGetFilterfv },
120 { "alGenEffects", (ALvoid *) alGenEffects },
121 { "alDeleteEffects", (ALvoid *) alDeleteEffects },
122 { "alIsEffect", (ALvoid *) alIsEffect },
123 { "alEffecti", (ALvoid *) alEffecti },
124 { "alEffectiv", (ALvoid *) alEffectiv },
125 { "alEffectf", (ALvoid *) alEffectf },
126 { "alEffectfv", (ALvoid *) alEffectfv },
127 { "alGetEffecti", (ALvoid *) alGetEffecti },
128 { "alGetEffectiv", (ALvoid *) alGetEffectiv },
129 { "alGetEffectf", (ALvoid *) alGetEffectf },
130 { "alGetEffectfv", (ALvoid *) alGetEffectfv },
132 { "alGenAuxiliaryEffectSlots", (ALvoid *) alGenAuxiliaryEffectSlots },
133 { "alDeleteAuxiliaryEffectSlots",(ALvoid *) alDeleteAuxiliaryEffectSlots},
134 { "alIsAuxiliaryEffectSlot", (ALvoid *) alIsAuxiliaryEffectSlot },
135 { "alAuxiliaryEffectSloti", (ALvoid *) alAuxiliaryEffectSloti },
136 { "alAuxiliaryEffectSlotiv", (ALvoid *) alAuxiliaryEffectSlotiv },
137 { "alAuxiliaryEffectSlotf", (ALvoid *) alAuxiliaryEffectSlotf },
138 { "alAuxiliaryEffectSlotfv", (ALvoid *) alAuxiliaryEffectSlotfv },
139 { "alGetAuxiliaryEffectSloti", (ALvoid *) alGetAuxiliaryEffectSloti },
140 { "alGetAuxiliaryEffectSlotiv", (ALvoid *) alGetAuxiliaryEffectSlotiv},
141 { "alGetAuxiliaryEffectSlotf", (ALvoid *) alGetAuxiliaryEffectSlotf },
142 { "alGetAuxiliaryEffectSlotfv", (ALvoid *) alGetAuxiliaryEffectSlotfv},
144 { NULL, (ALvoid *) NULL } };
146 static ALenums enumeration[]={
147 // Types
148 { (ALchar *)"AL_INVALID", AL_INVALID },
149 { (ALchar *)"AL_NONE", AL_NONE },
150 { (ALchar *)"AL_FALSE", AL_FALSE },
151 { (ALchar *)"AL_TRUE", AL_TRUE },
153 // Source and Listener Properties
154 { (ALchar *)"AL_SOURCE_RELATIVE", AL_SOURCE_RELATIVE },
155 { (ALchar *)"AL_CONE_INNER_ANGLE", AL_CONE_INNER_ANGLE },
156 { (ALchar *)"AL_CONE_OUTER_ANGLE", AL_CONE_OUTER_ANGLE },
157 { (ALchar *)"AL_PITCH", AL_PITCH },
158 { (ALchar *)"AL_POSITION", AL_POSITION },
159 { (ALchar *)"AL_DIRECTION", AL_DIRECTION },
160 { (ALchar *)"AL_VELOCITY", AL_VELOCITY },
161 { (ALchar *)"AL_LOOPING", AL_LOOPING },
162 { (ALchar *)"AL_BUFFER", AL_BUFFER },
163 { (ALchar *)"AL_GAIN", AL_GAIN },
164 { (ALchar *)"AL_MIN_GAIN", AL_MIN_GAIN },
165 { (ALchar *)"AL_MAX_GAIN", AL_MAX_GAIN },
166 { (ALchar *)"AL_ORIENTATION", AL_ORIENTATION },
167 { (ALchar *)"AL_REFERENCE_DISTANCE", AL_REFERENCE_DISTANCE },
168 { (ALchar *)"AL_ROLLOFF_FACTOR", AL_ROLLOFF_FACTOR },
169 { (ALchar *)"AL_CONE_OUTER_GAIN", AL_CONE_OUTER_GAIN },
170 { (ALchar *)"AL_MAX_DISTANCE", AL_MAX_DISTANCE },
171 { (ALchar *)"AL_SEC_OFFSET", AL_SEC_OFFSET },
172 { (ALchar *)"AL_SAMPLE_OFFSET", AL_SAMPLE_OFFSET },
173 { (ALchar *)"AL_BYTE_OFFSET", AL_BYTE_OFFSET },
174 { (ALchar *)"AL_SOURCE_TYPE", AL_SOURCE_TYPE },
175 { (ALchar *)"AL_STATIC", AL_STATIC },
176 { (ALchar *)"AL_STREAMING", AL_STREAMING },
177 { (ALchar *)"AL_UNDETERMINED", AL_UNDETERMINED },
178 { (ALchar *)"AL_METERS_PER_UNIT", AL_METERS_PER_UNIT },
180 // Source EFX Properties
181 { (ALchar *)"AL_DIRECT_FILTER", AL_DIRECT_FILTER },
182 { (ALchar *)"AL_AUXILIARY_SEND_FILTER", AL_AUXILIARY_SEND_FILTER },
183 { (ALchar *)"AL_AIR_ABSORPTION_FACTOR", AL_AIR_ABSORPTION_FACTOR },
184 { (ALchar *)"AL_ROOM_ROLLOFF_FACTOR", AL_ROOM_ROLLOFF_FACTOR },
185 { (ALchar *)"AL_CONE_OUTER_GAINHF", AL_CONE_OUTER_GAINHF },
186 { (ALchar *)"AL_DIRECT_FILTER_GAINHF_AUTO", AL_DIRECT_FILTER_GAINHF_AUTO },
187 { (ALchar *)"AL_AUXILIARY_SEND_FILTER_GAIN_AUTO", AL_AUXILIARY_SEND_FILTER_GAIN_AUTO },
188 { (ALchar *)"AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO", AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO},
191 // Source State information
192 { (ALchar *)"AL_SOURCE_STATE", AL_SOURCE_STATE },
193 { (ALchar *)"AL_INITIAL", AL_INITIAL },
194 { (ALchar *)"AL_PLAYING", AL_PLAYING },
195 { (ALchar *)"AL_PAUSED", AL_PAUSED },
196 { (ALchar *)"AL_STOPPED", AL_STOPPED },
198 // Queue information
199 { (ALchar *)"AL_BUFFERS_QUEUED", AL_BUFFERS_QUEUED },
200 { (ALchar *)"AL_BUFFERS_PROCESSED", AL_BUFFERS_PROCESSED },
202 // Buffer Formats
203 { (ALchar *)"AL_FORMAT_MONO8", AL_FORMAT_MONO8 },
204 { (ALchar *)"AL_FORMAT_MONO16", AL_FORMAT_MONO16 },
205 { (ALchar *)"AL_FORMAT_STEREO8", AL_FORMAT_STEREO8 },
206 { (ALchar *)"AL_FORMAT_STEREO16", AL_FORMAT_STEREO16 },
207 { (ALchar *)"AL_FORMAT_MONO_IMA4", AL_FORMAT_MONO_IMA4 },
208 { (ALchar *)"AL_FORMAT_STEREO_IMA4", AL_FORMAT_STEREO_IMA4 },
209 { (ALchar *)"AL_FORMAT_QUAD8", AL_FORMAT_QUAD8 },
210 { (ALchar *)"AL_FORMAT_QUAD16", AL_FORMAT_QUAD16 },
212 // Buffer attributes
213 { (ALchar *)"AL_FREQUENCY", AL_FREQUENCY },
214 { (ALchar *)"AL_BITS", AL_BITS },
215 { (ALchar *)"AL_CHANNELS", AL_CHANNELS },
216 { (ALchar *)"AL_SIZE", AL_SIZE },
218 // Buffer States (not supported yet)
219 { (ALchar *)"AL_UNUSED", AL_UNUSED },
220 { (ALchar *)"AL_PENDING", AL_PENDING },
221 { (ALchar *)"AL_PROCESSED", AL_PROCESSED },
223 // AL Error Messages
224 { (ALchar *)"AL_NO_ERROR", AL_NO_ERROR },
225 { (ALchar *)"AL_INVALID_NAME", AL_INVALID_NAME },
226 { (ALchar *)"AL_INVALID_ENUM", AL_INVALID_ENUM },
227 { (ALchar *)"AL_INVALID_VALUE", AL_INVALID_VALUE },
228 { (ALchar *)"AL_INVALID_OPERATION", AL_INVALID_OPERATION },
229 { (ALchar *)"AL_OUT_OF_MEMORY", AL_OUT_OF_MEMORY },
231 // Context strings
232 { (ALchar *)"AL_VENDOR", AL_VENDOR },
233 { (ALchar *)"AL_VERSION", AL_VERSION },
234 { (ALchar *)"AL_RENDERER", AL_RENDERER },
235 { (ALchar *)"AL_EXTENSIONS", AL_EXTENSIONS },
237 // Global states
238 { (ALchar *)"AL_DOPPLER_FACTOR", AL_DOPPLER_FACTOR },
239 { (ALchar *)"AL_DOPPLER_VELOCITY", AL_DOPPLER_VELOCITY },
240 { (ALchar *)"AL_DISTANCE_MODEL", AL_DISTANCE_MODEL },
241 { (ALchar *)"AL_SPEED_OF_SOUND", AL_SPEED_OF_SOUND },
243 // Distance Models
244 { (ALchar *)"AL_INVERSE_DISTANCE", AL_INVERSE_DISTANCE },
245 { (ALchar *)"AL_INVERSE_DISTANCE_CLAMPED", AL_INVERSE_DISTANCE_CLAMPED },
246 { (ALchar *)"AL_LINEAR_DISTANCE", AL_LINEAR_DISTANCE },
247 { (ALchar *)"AL_LINEAR_DISTANCE_CLAMPED", AL_LINEAR_DISTANCE_CLAMPED },
248 { (ALchar *)"AL_EXPONENT_DISTANCE", AL_EXPONENT_DISTANCE },
249 { (ALchar *)"AL_EXPONENT_DISTANCE_CLAMPED", AL_EXPONENT_DISTANCE_CLAMPED },
251 // Filter types
252 { (ALchar *)"AL_FILTER_TYPE", AL_FILTER_TYPE },
253 { (ALchar *)"AL_FILTER_NULL", AL_FILTER_NULL },
254 { (ALchar *)"AL_FILTER_LOWPASS", AL_FILTER_LOWPASS },
255 { (ALchar *)"AL_FILTER_HIGHPASS", AL_FILTER_HIGHPASS },
256 { (ALchar *)"AL_FILTER_BANDPASS", AL_FILTER_BANDPASS },
258 // Filter params
259 { (ALchar *)"AL_LOWPASS_GAIN", AL_LOWPASS_GAIN },
260 { (ALchar *)"AL_LOWPASS_GAINHF", AL_LOWPASS_GAINHF },
262 // Effect types
263 { (ALchar *)"AL_EFFECT_TYPE", AL_EFFECT_TYPE },
264 { (ALchar *)"AL_EFFECT_NULL", AL_EFFECT_NULL },
265 { (ALchar *)"AL_EFFECT_REVERB", AL_EFFECT_REVERB },
266 { (ALchar *)"AL_EFFECT_CHORUS", AL_EFFECT_CHORUS },
267 { (ALchar *)"AL_EFFECT_DISTORTION", AL_EFFECT_DISTORTION },
268 { (ALchar *)"AL_EFFECT_ECHO", AL_EFFECT_ECHO },
269 { (ALchar *)"AL_EFFECT_FLANGER", AL_EFFECT_FLANGER },
270 { (ALchar *)"AL_EFFECT_FREQUENCY_SHIFTER", AL_EFFECT_FREQUENCY_SHIFTER },
271 { (ALchar *)"AL_EFFECT_VOCAL_MORPHER", AL_EFFECT_VOCAL_MORPHER },
272 { (ALchar *)"AL_EFFECT_PITCH_SHIFTER", AL_EFFECT_PITCH_SHIFTER },
273 { (ALchar *)"AL_EFFECT_RING_MODULATOR", AL_EFFECT_RING_MODULATOR },
274 { (ALchar *)"AL_EFFECT_AUTOWAH", AL_EFFECT_AUTOWAH },
275 { (ALchar *)"AL_EFFECT_COMPRESSOR", AL_EFFECT_COMPRESSOR },
276 { (ALchar *)"AL_EFFECT_EQUALIZER", AL_EFFECT_EQUALIZER },
278 // Default
279 { (ALchar *)NULL, (ALenum)0 }
284 ALAPI ALboolean ALAPIENTRY alIsExtensionPresent(const ALchar *extName)
286 ALboolean bIsSupported = AL_FALSE;
287 ALCcontext *pContext;
288 char *ptr, *ext;
290 if (!extName)
292 alSetError(AL_INVALID_VALUE);
293 return AL_FALSE;
296 pContext = alcGetCurrentContext();
297 if(!pContext)
299 alSetError(AL_INVALID_OPERATION);
300 return AL_FALSE;
303 ext = strdup(extName);
304 ptr = ext;
305 do {
306 *ptr = (char)toupper(*ptr);
307 } while(*(ptr++));
309 SuspendContext(pContext);
311 ptr = pContext->ExtensionList;
312 while((ptr=strstr(ptr, ext)) != NULL)
314 if(ptr == pContext->ExtensionList || ptr[-1] == ' ')
316 char e = ptr[strlen(ext)];
317 if(e == ' ' || e == 0)
319 bIsSupported = AL_TRUE;
320 break;
323 ptr++;
326 ProcessContext(pContext);
328 free(ext);
329 return bIsSupported;
333 ALAPI ALvoid * ALAPIENTRY alGetProcAddress(const ALchar *funcName)
335 ALsizei i = 0;
337 while(function[i].funcName &&
338 strcmp((char*)function[i].funcName, (char*)funcName) != 0)
339 i++;
341 return function[i].address;
344 /* NOTE: This function must be able to run without a context! */
345 ALAPI ALenum ALAPIENTRY alGetEnumValue(const ALchar *enumName)
347 ALsizei i = 0;
349 while(enumeration[i].enumName &&
350 strcmp(enumeration[i].enumName, enumName) != 0)
351 i++;
353 return enumeration[i].value;