Allow prepending backend names with - to remove them from the available devices
[openal-soft/android/lowlatency.git] / Alc / ALc.c
blob8156b272e6154d7ee90137d3564d8661417c6ffe
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 "config.h"
23 #include <math.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <memory.h>
27 #include <ctype.h>
29 #include "alMain.h"
30 #include "alSource.h"
31 #include "AL/al.h"
32 #include "AL/alc.h"
33 #include "alThunk.h"
34 #include "alSource.h"
35 #include "alBuffer.h"
36 #include "alAuxEffectSlot.h"
37 #include "alDatabuffer.h"
38 #include "bs2b.h"
39 #include "alu.h"
42 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
43 typedef struct BackendInfo {
44 const char *name;
45 void (*Init)(BackendFuncs*);
46 void (*Deinit)(void);
47 void (*Probe)(int);
48 BackendFuncs Funcs;
49 } BackendInfo;
50 static BackendInfo BackendList[] = {
51 #ifdef HAVE_PULSEAUDIO
52 { "pulse", alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs },
53 #endif
54 #ifdef HAVE_ALSA
55 { "alsa", alc_alsa_init, alc_alsa_deinit, alc_alsa_probe, EmptyFuncs },
56 #endif
57 #ifdef HAVE_OSS
58 { "oss", alc_oss_init, alc_oss_deinit, alc_oss_probe, EmptyFuncs },
59 #endif
60 #ifdef HAVE_SOLARIS
61 { "solaris", alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs },
62 #endif
63 #ifdef HAVE_DSOUND
64 { "dsound", alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs },
65 #endif
66 #ifdef HAVE_WINMM
67 { "winmm", alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs },
68 #endif
69 #ifdef HAVE_PORTAUDIO
70 { "port", alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs },
71 #endif
73 { "null", alc_null_init, alc_null_deinit, alc_null_probe, EmptyFuncs },
74 { "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs },
76 { NULL, NULL, NULL, NULL, EmptyFuncs }
78 #undef EmptyFuncs
80 ///////////////////////////////////////////////////////
82 #define ALC_EFX_MAJOR_VERSION 0x20001
83 #define ALC_EFX_MINOR_VERSION 0x20002
84 #define ALC_MAX_AUXILIARY_SENDS 0x20003
86 ///////////////////////////////////////////////////////
87 // STRING and EXTENSIONS
89 typedef struct ALCfunction {
90 const ALCchar *funcName;
91 ALCvoid *address;
92 } ALCfunction;
94 typedef struct ALCenums {
95 const ALCchar *enumName;
96 ALCenum value;
97 } ALCenums;
100 static const ALCfunction alcFunctions[] = {
101 { "alcCreateContext", (ALCvoid *) alcCreateContext },
102 { "alcMakeContextCurrent", (ALCvoid *) alcMakeContextCurrent },
103 { "alcProcessContext", (ALCvoid *) alcProcessContext },
104 { "alcSuspendContext", (ALCvoid *) alcSuspendContext },
105 { "alcDestroyContext", (ALCvoid *) alcDestroyContext },
106 { "alcGetCurrentContext", (ALCvoid *) alcGetCurrentContext },
107 { "alcGetContextsDevice", (ALCvoid *) alcGetContextsDevice },
108 { "alcOpenDevice", (ALCvoid *) alcOpenDevice },
109 { "alcCloseDevice", (ALCvoid *) alcCloseDevice },
110 { "alcGetError", (ALCvoid *) alcGetError },
111 { "alcIsExtensionPresent", (ALCvoid *) alcIsExtensionPresent },
112 { "alcGetProcAddress", (ALCvoid *) alcGetProcAddress },
113 { "alcGetEnumValue", (ALCvoid *) alcGetEnumValue },
114 { "alcGetString", (ALCvoid *) alcGetString },
115 { "alcGetIntegerv", (ALCvoid *) alcGetIntegerv },
116 { "alcCaptureOpenDevice", (ALCvoid *) alcCaptureOpenDevice },
117 { "alcCaptureCloseDevice", (ALCvoid *) alcCaptureCloseDevice },
118 { "alcCaptureStart", (ALCvoid *) alcCaptureStart },
119 { "alcCaptureStop", (ALCvoid *) alcCaptureStop },
120 { "alcCaptureSamples", (ALCvoid *) alcCaptureSamples },
122 { "alcSetThreadContext", (ALCvoid *) alcSetThreadContext },
123 { "alcGetThreadContext", (ALCvoid *) alcGetThreadContext },
125 { "alEnable", (ALCvoid *) alEnable },
126 { "alDisable", (ALCvoid *) alDisable },
127 { "alIsEnabled", (ALCvoid *) alIsEnabled },
128 { "alGetString", (ALCvoid *) alGetString },
129 { "alGetBooleanv", (ALCvoid *) alGetBooleanv },
130 { "alGetIntegerv", (ALCvoid *) alGetIntegerv },
131 { "alGetFloatv", (ALCvoid *) alGetFloatv },
132 { "alGetDoublev", (ALCvoid *) alGetDoublev },
133 { "alGetBoolean", (ALCvoid *) alGetBoolean },
134 { "alGetInteger", (ALCvoid *) alGetInteger },
135 { "alGetFloat", (ALCvoid *) alGetFloat },
136 { "alGetDouble", (ALCvoid *) alGetDouble },
137 { "alGetError", (ALCvoid *) alGetError },
138 { "alIsExtensionPresent", (ALCvoid *) alIsExtensionPresent },
139 { "alGetProcAddress", (ALCvoid *) alGetProcAddress },
140 { "alGetEnumValue", (ALCvoid *) alGetEnumValue },
141 { "alListenerf", (ALCvoid *) alListenerf },
142 { "alListener3f", (ALCvoid *) alListener3f },
143 { "alListenerfv", (ALCvoid *) alListenerfv },
144 { "alListeneri", (ALCvoid *) alListeneri },
145 { "alListener3i", (ALCvoid *) alListener3i },
146 { "alListeneriv", (ALCvoid *) alListeneriv },
147 { "alGetListenerf", (ALCvoid *) alGetListenerf },
148 { "alGetListener3f", (ALCvoid *) alGetListener3f },
149 { "alGetListenerfv", (ALCvoid *) alGetListenerfv },
150 { "alGetListeneri", (ALCvoid *) alGetListeneri },
151 { "alGetListener3i", (ALCvoid *) alGetListener3i },
152 { "alGetListeneriv", (ALCvoid *) alGetListeneriv },
153 { "alGenSources", (ALCvoid *) alGenSources },
154 { "alDeleteSources", (ALCvoid *) alDeleteSources },
155 { "alIsSource", (ALCvoid *) alIsSource },
156 { "alSourcef", (ALCvoid *) alSourcef },
157 { "alSource3f", (ALCvoid *) alSource3f },
158 { "alSourcefv", (ALCvoid *) alSourcefv },
159 { "alSourcei", (ALCvoid *) alSourcei },
160 { "alSource3i", (ALCvoid *) alSource3i },
161 { "alSourceiv", (ALCvoid *) alSourceiv },
162 { "alGetSourcef", (ALCvoid *) alGetSourcef },
163 { "alGetSource3f", (ALCvoid *) alGetSource3f },
164 { "alGetSourcefv", (ALCvoid *) alGetSourcefv },
165 { "alGetSourcei", (ALCvoid *) alGetSourcei },
166 { "alGetSource3i", (ALCvoid *) alGetSource3i },
167 { "alGetSourceiv", (ALCvoid *) alGetSourceiv },
168 { "alSourcePlayv", (ALCvoid *) alSourcePlayv },
169 { "alSourceStopv", (ALCvoid *) alSourceStopv },
170 { "alSourceRewindv", (ALCvoid *) alSourceRewindv },
171 { "alSourcePausev", (ALCvoid *) alSourcePausev },
172 { "alSourcePlay", (ALCvoid *) alSourcePlay },
173 { "alSourceStop", (ALCvoid *) alSourceStop },
174 { "alSourceRewind", (ALCvoid *) alSourceRewind },
175 { "alSourcePause", (ALCvoid *) alSourcePause },
176 { "alSourceQueueBuffers", (ALCvoid *) alSourceQueueBuffers },
177 { "alSourceUnqueueBuffers", (ALCvoid *) alSourceUnqueueBuffers },
178 { "alGenBuffers", (ALCvoid *) alGenBuffers },
179 { "alDeleteBuffers", (ALCvoid *) alDeleteBuffers },
180 { "alIsBuffer", (ALCvoid *) alIsBuffer },
181 { "alBufferData", (ALCvoid *) alBufferData },
182 { "alBufferf", (ALCvoid *) alBufferf },
183 { "alBuffer3f", (ALCvoid *) alBuffer3f },
184 { "alBufferfv", (ALCvoid *) alBufferfv },
185 { "alBufferi", (ALCvoid *) alBufferi },
186 { "alBuffer3i", (ALCvoid *) alBuffer3i },
187 { "alBufferiv", (ALCvoid *) alBufferiv },
188 { "alGetBufferf", (ALCvoid *) alGetBufferf },
189 { "alGetBuffer3f", (ALCvoid *) alGetBuffer3f },
190 { "alGetBufferfv", (ALCvoid *) alGetBufferfv },
191 { "alGetBufferi", (ALCvoid *) alGetBufferi },
192 { "alGetBuffer3i", (ALCvoid *) alGetBuffer3i },
193 { "alGetBufferiv", (ALCvoid *) alGetBufferiv },
194 { "alDopplerFactor", (ALCvoid *) alDopplerFactor },
195 { "alDopplerVelocity", (ALCvoid *) alDopplerVelocity },
196 { "alSpeedOfSound", (ALCvoid *) alSpeedOfSound },
197 { "alDistanceModel", (ALCvoid *) alDistanceModel },
199 { "alGenFilters", (ALCvoid *) alGenFilters },
200 { "alDeleteFilters", (ALCvoid *) alDeleteFilters },
201 { "alIsFilter", (ALCvoid *) alIsFilter },
202 { "alFilteri", (ALCvoid *) alFilteri },
203 { "alFilteriv", (ALCvoid *) alFilteriv },
204 { "alFilterf", (ALCvoid *) alFilterf },
205 { "alFilterfv", (ALCvoid *) alFilterfv },
206 { "alGetFilteri", (ALCvoid *) alGetFilteri },
207 { "alGetFilteriv", (ALCvoid *) alGetFilteriv },
208 { "alGetFilterf", (ALCvoid *) alGetFilterf },
209 { "alGetFilterfv", (ALCvoid *) alGetFilterfv },
211 { "alGenEffects", (ALCvoid *) alGenEffects },
212 { "alDeleteEffects", (ALCvoid *) alDeleteEffects },
213 { "alIsEffect", (ALCvoid *) alIsEffect },
214 { "alEffecti", (ALCvoid *) alEffecti },
215 { "alEffectiv", (ALCvoid *) alEffectiv },
216 { "alEffectf", (ALCvoid *) alEffectf },
217 { "alEffectfv", (ALCvoid *) alEffectfv },
218 { "alGetEffecti", (ALCvoid *) alGetEffecti },
219 { "alGetEffectiv", (ALCvoid *) alGetEffectiv },
220 { "alGetEffectf", (ALCvoid *) alGetEffectf },
221 { "alGetEffectfv", (ALCvoid *) alGetEffectfv },
223 { "alGenAuxiliaryEffectSlots", (ALCvoid *) alGenAuxiliaryEffectSlots},
224 { "alDeleteAuxiliaryEffectSlots",(ALCvoid *) alDeleteAuxiliaryEffectSlots},
225 { "alIsAuxiliaryEffectSlot", (ALCvoid *) alIsAuxiliaryEffectSlot },
226 { "alAuxiliaryEffectSloti", (ALCvoid *) alAuxiliaryEffectSloti },
227 { "alAuxiliaryEffectSlotiv", (ALCvoid *) alAuxiliaryEffectSlotiv },
228 { "alAuxiliaryEffectSlotf", (ALCvoid *) alAuxiliaryEffectSlotf },
229 { "alAuxiliaryEffectSlotfv", (ALCvoid *) alAuxiliaryEffectSlotfv },
230 { "alGetAuxiliaryEffectSloti", (ALCvoid *) alGetAuxiliaryEffectSloti},
231 { "alGetAuxiliaryEffectSlotiv", (ALCvoid *) alGetAuxiliaryEffectSlotiv},
232 { "alGetAuxiliaryEffectSlotf", (ALCvoid *) alGetAuxiliaryEffectSlotf},
233 { "alGetAuxiliaryEffectSlotfv", (ALCvoid *) alGetAuxiliaryEffectSlotfv},
235 { "alBufferSubDataEXT", (ALCvoid *) alBufferSubDataEXT },
237 { "alGenDatabuffersEXT", (ALCvoid *) alGenDatabuffersEXT },
238 { "alDeleteDatabuffersEXT", (ALCvoid *) alDeleteDatabuffersEXT },
239 { "alIsDatabufferEXT", (ALCvoid *) alIsDatabufferEXT },
240 { "alDatabufferDataEXT", (ALCvoid *) alDatabufferDataEXT },
241 { "alDatabufferSubDataEXT", (ALCvoid *) alDatabufferSubDataEXT },
242 { "alGetDatabufferSubDataEXT", (ALCvoid *) alGetDatabufferSubDataEXT},
243 { "alDatabufferfEXT", (ALCvoid *) alDatabufferfEXT },
244 { "alDatabufferfvEXT", (ALCvoid *) alDatabufferfvEXT },
245 { "alDatabufferiEXT", (ALCvoid *) alDatabufferiEXT },
246 { "alDatabufferivEXT", (ALCvoid *) alDatabufferivEXT },
247 { "alGetDatabufferfEXT", (ALCvoid *) alGetDatabufferfEXT },
248 { "alGetDatabufferfvEXT", (ALCvoid *) alGetDatabufferfvEXT },
249 { "alGetDatabufferiEXT", (ALCvoid *) alGetDatabufferiEXT },
250 { "alGetDatabufferivEXT", (ALCvoid *) alGetDatabufferivEXT },
251 { "alSelectDatabufferEXT", (ALCvoid *) alSelectDatabufferEXT },
252 { "alMapDatabufferEXT", (ALCvoid *) alMapDatabufferEXT },
253 { "alUnmapDatabufferEXT", (ALCvoid *) alUnmapDatabufferEXT },
255 { NULL, (ALCvoid *) NULL }
258 static const ALCenums enumeration[] = {
259 // Types
260 { "ALC_INVALID", ALC_INVALID },
261 { "ALC_FALSE", ALC_FALSE },
262 { "ALC_TRUE", ALC_TRUE },
264 // ALC Properties
265 { "ALC_MAJOR_VERSION", ALC_MAJOR_VERSION },
266 { "ALC_MINOR_VERSION", ALC_MINOR_VERSION },
267 { "ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE },
268 { "ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES },
269 { "ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER },
270 { "ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER },
271 { "ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER },
272 { "ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER },
273 { "ALC_EXTENSIONS", ALC_EXTENSIONS },
274 { "ALC_FREQUENCY", ALC_FREQUENCY },
275 { "ALC_REFRESH", ALC_REFRESH },
276 { "ALC_SYNC", ALC_SYNC },
277 { "ALC_MONO_SOURCES", ALC_MONO_SOURCES },
278 { "ALC_STEREO_SOURCES", ALC_STEREO_SOURCES },
279 { "ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER },
280 { "ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER},
281 { "ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES },
282 { "ALC_CONNECTED", ALC_CONNECTED },
284 // EFX Properties
285 { "ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION },
286 { "ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION },
287 { "ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS },
289 // ALC Error Message
290 { "ALC_NO_ERROR", ALC_NO_ERROR },
291 { "ALC_INVALID_DEVICE", ALC_INVALID_DEVICE },
292 { "ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT },
293 { "ALC_INVALID_ENUM", ALC_INVALID_ENUM },
294 { "ALC_INVALID_VALUE", ALC_INVALID_VALUE },
295 { "ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY },
296 { NULL, (ALCenum)0 }
298 // Error strings
299 static const ALCchar alcNoError[] = "No Error";
300 static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
301 static const ALCchar alcErrInvalidContext[] = "Invalid Context";
302 static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
303 static const ALCchar alcErrInvalidValue[] = "Invalid Value";
304 static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
306 /* Device lists. Sizes only include the first ending null character, not the
307 * second */
308 static ALCchar *alcDeviceList;
309 static size_t alcDeviceListSize;
310 static ALCchar *alcAllDeviceList;
311 static size_t alcAllDeviceListSize;
312 static ALCchar *alcCaptureDeviceList;
313 static size_t alcCaptureDeviceListSize;
314 // Default is always the first in the list
315 static ALCchar *alcDefaultDeviceSpecifier;
316 static ALCchar *alcDefaultAllDeviceSpecifier;
317 static ALCchar *alcCaptureDefaultDeviceSpecifier;
320 static const ALCchar alcNoDeviceExtList[] =
321 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
322 "ALC_EXT_thread_local_context";
323 static const ALCchar alcExtensionList[] =
324 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
325 "ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context";
326 static const ALCint alcMajorVersion = 1;
327 static const ALCint alcMinorVersion = 1;
329 static const ALCint alcEFXMajorVersion = 1;
330 static const ALCint alcEFXMinorVersion = 0;
332 ///////////////////////////////////////////////////////
335 ///////////////////////////////////////////////////////
336 // Global Variables
338 static ALCdevice *g_pDeviceList = NULL;
339 static ALCuint g_ulDeviceCount = 0;
341 static CRITICAL_SECTION g_csMutex;
343 // Context List
344 static ALCcontext *g_pContextList = NULL;
345 static ALCuint g_ulContextCount = 0;
347 // Thread-local current context
348 static tls_type LocalContext;
349 // Process-wide current context
350 static ALCcontext *GlobalContext;
352 // Context Error
353 static ALCenum g_eLastNullDeviceError = ALC_NO_ERROR;
355 // Default context extensions
356 static const ALchar alExtList[] =
357 "AL_EXTX_buffer_sub_data AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE "
358 "AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXTX_loop_points "
359 "AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET "
360 "AL_EXTX_sample_buffer_object AL_EXT_source_distance_model "
361 "AL_LOKI_quadriphonic";
363 // Mixing Priority Level
364 static ALint RTPrioLevel;
366 // Resampler Quality
367 resampler_t DefaultResampler;
369 // Output Log File
370 static FILE *LogFile;
372 ///////////////////////////////////////////////////////
375 ///////////////////////////////////////////////////////
376 // ALC Related helper functions
377 #ifdef _WIN32
378 static void alc_init(void);
379 static void alc_deinit(void);
381 BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
383 (void)lpReserved;
385 // Perform actions based on the reason for calling.
386 switch(ul_reason_for_call)
388 case DLL_PROCESS_ATTACH:
389 DisableThreadLibraryCalls(hModule);
390 alc_init();
391 break;
393 case DLL_PROCESS_DETACH:
394 alc_deinit();
395 break;
397 return TRUE;
399 #else
400 #ifdef HAVE_GCC_DESTRUCTOR
401 static void alc_init(void) __attribute__((constructor));
402 static void alc_deinit(void) __attribute__((destructor));
403 #endif
404 #endif
406 static void alc_init(void)
408 int i;
409 const char *devs, *str;
411 InitializeCriticalSection(&g_csMutex);
412 ALTHUNK_INIT();
413 ReadALConfig();
415 tls_create(&LocalContext);
417 str = getenv("ALSOFT_LOGFILE");
418 if(str && str[0])
420 LogFile = fopen(str, "w");
421 if(!LogFile)
422 fprintf(stderr, "AL lib: Failed to open log file '%s'\n", str);
424 if(!LogFile)
425 LogFile = stderr;
427 RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0);
429 DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT);
430 if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
431 DefaultResampler = RESAMPLER_DEFAULT;
433 devs = GetConfigValue(NULL, "drivers", "");
434 if(devs[0])
436 int n;
437 size_t len;
438 const char *next = devs;
439 int endlist, delitem;
441 i = 0;
442 do {
443 devs = next;
444 next = strchr(devs, ',');
446 delitem = (devs[0] == '-');
447 if(devs[0] == '-') devs++;
449 if(!devs[0] || devs[0] == ',')
451 endlist = 0;
452 continue;
454 endlist = 1;
456 len = (next ? ((size_t)(next-devs)) : strlen(devs));
457 for(n = i;BackendList[n].Init;n++)
459 if(len == strlen(BackendList[n].name) &&
460 strncmp(BackendList[n].name, devs, len) == 0)
462 if(delitem)
464 do {
465 BackendList[n] = BackendList[n+1];
466 ++n;
467 } while(BackendList[n].Init);
469 else
471 BackendInfo Bkp = BackendList[n];
472 while(n > i)
474 BackendList[n] = BackendList[n-1];
475 --n;
477 BackendList[n] = Bkp;
479 i++;
481 break;
484 } while(next++);
486 if(endlist)
488 BackendList[i].name = NULL;
489 BackendList[i].Init = NULL;
490 BackendList[i].Deinit = NULL;
491 BackendList[i].Probe = NULL;
495 for(i = 0;BackendList[i].Init;i++)
496 BackendList[i].Init(&BackendList[i].Funcs);
498 str = GetConfigValue(NULL, "excludefx", "");
499 if(str[0])
501 const struct {
502 const char *name;
503 int type;
504 } EffectList[] = {
505 { "eaxreverb", EAXREVERB },
506 { "reverb", REVERB },
507 { "echo", ECHO },
508 { "modulator", MODULATOR },
509 { NULL, 0 }
511 int n;
512 size_t len;
513 const char *next = str;
515 do {
516 str = next;
517 next = strchr(str, ',');
519 if(!str[0] || next == str)
520 continue;
522 len = (next ? ((size_t)(next-str)) : strlen(str));
523 for(n = 0;EffectList[n].name;n++)
525 if(len == strlen(EffectList[n].name) &&
526 strncmp(EffectList[n].name, str, len) == 0)
527 DisabledEffects[EffectList[n].type] = AL_TRUE;
529 } while(next++);
533 static void alc_deinit(void)
535 int i;
537 ReleaseALC();
539 for(i = 0;BackendList[i].Deinit;i++)
540 BackendList[i].Deinit();
542 if(LogFile != stderr)
543 fclose(LogFile);
544 LogFile = NULL;
546 tls_delete(LocalContext);
548 FreeALConfig();
549 ALTHUNK_EXIT();
550 DeleteCriticalSection(&g_csMutex);
554 static void ProbeDeviceList()
556 ALint i;
558 free(alcDeviceList); alcDeviceList = NULL;
559 alcDeviceListSize = 0;
561 for(i = 0;BackendList[i].Probe;i++)
562 BackendList[i].Probe(DEVICE_PROBE);
565 static void ProbeAllDeviceList()
567 ALint i;
569 free(alcAllDeviceList); alcAllDeviceList = NULL;
570 alcAllDeviceListSize = 0;
572 for(i = 0;BackendList[i].Probe;i++)
573 BackendList[i].Probe(ALL_DEVICE_PROBE);
576 static void ProbeCaptureDeviceList()
578 ALint i;
580 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
581 alcCaptureDeviceListSize = 0;
583 for(i = 0;BackendList[i].Probe;i++)
584 BackendList[i].Probe(CAPTURE_DEVICE_PROBE);
588 #define DECL_APPEND_LIST_FUNC(type) \
589 void Append##type##List(const ALCchar *name) \
591 size_t len = strlen(name); \
592 void *temp; \
594 if(len == 0) \
595 return; \
597 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
598 if(!temp) \
600 AL_PRINT("Realloc failed to add %s!\n", name); \
601 return; \
603 alc##type##List = temp; \
604 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
605 alc##type##ListSize += len+1; \
606 alc##type##List[alc##type##ListSize] = 0; \
609 DECL_APPEND_LIST_FUNC(Device)
610 DECL_APPEND_LIST_FUNC(AllDevice)
611 DECL_APPEND_LIST_FUNC(CaptureDevice)
614 void al_print(const char *fname, unsigned int line, const char *fmt, ...)
616 const char *fn;
617 char str[256];
618 int i;
620 fn = strrchr(fname, '/');
621 if(!fn) fn = strrchr(fname, '\\');;
622 if(!fn) fn = fname;
623 else fn += 1;
625 i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
626 if(i < (int)sizeof(str) && i > 0)
628 va_list ap;
629 va_start(ap, fmt);
630 vsnprintf(str+i, sizeof(str)-i, fmt, ap);
631 va_end(ap);
633 str[sizeof(str)-1] = 0;
635 fprintf(LogFile, "%s", str);
636 fflush(LogFile);
639 void SetRTPriority(void)
641 ALboolean failed;
643 #ifdef _WIN32
644 if(RTPrioLevel > 0)
645 failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
646 else
647 failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
648 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
649 struct sched_param param;
651 if(RTPrioLevel > 0)
653 /* Use the minimum real-time priority possible for now (on Linux this
654 * should be 1 for SCHED_RR) */
655 param.sched_priority = sched_get_priority_min(SCHED_RR);
656 failed = !!pthread_setschedparam(pthread_self(), SCHED_RR, &param);
658 else
660 param.sched_priority = 0;
661 failed = !!pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);
663 #else
664 /* Real-time priority not available */
665 failed = (RTPrioLevel>0);
666 #endif
667 if(failed)
668 AL_PRINT("Failed to set priority level for thread\n");
672 void InitUIntMap(UIntMap *map)
674 map->array = NULL;
675 map->size = 0;
676 map->maxsize = 0;
679 void ResetUIntMap(UIntMap *map)
681 free(map->array);
682 map->array = NULL;
683 map->size = 0;
684 map->maxsize = 0;
687 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
689 ALsizei pos = 0;
691 if(map->size > 0)
693 ALsizei low = 0;
694 ALsizei high = map->size - 1;
695 while(low < high)
697 ALsizei mid = low + (high-low)/2;
698 if(map->array[mid].key < key)
699 low = mid + 1;
700 else
701 high = mid;
703 if(map->array[low].key < key)
704 low++;
705 pos = low;
708 if(pos == map->size || map->array[pos].key != key)
710 if(map->size == map->maxsize)
712 ALvoid *temp;
713 ALsizei newsize;
715 newsize = (map->maxsize ? (map->maxsize<<1) : 4);
716 if(newsize < map->maxsize)
717 return AL_OUT_OF_MEMORY;
719 temp = realloc(map->array, newsize*sizeof(map->array[0]));
720 if(!temp) return AL_OUT_OF_MEMORY;
721 map->array = temp;
722 map->maxsize = newsize;
725 map->size++;
726 if(pos < map->size-1)
727 memmove(&map->array[pos+1], &map->array[pos],
728 (map->size-1-pos)*sizeof(map->array[0]));
730 map->array[pos].key = key;
731 map->array[pos].value = value;
733 return AL_NO_ERROR;
736 void RemoveUIntMapKey(UIntMap *map, ALuint key)
738 if(map->size > 0)
740 ALsizei low = 0;
741 ALsizei high = map->size - 1;
742 while(low < high)
744 ALsizei mid = low + (high-low)/2;
745 if(map->array[mid].key < key)
746 low = mid + 1;
747 else
748 high = mid;
750 if(map->array[low].key == key)
752 if(low < map->size-1)
753 memmove(&map->array[low], &map->array[low+1],
754 (map->size-1-low)*sizeof(map->array[0]));
755 map->size--;
762 IsDevice
764 Check pDevice is a valid Device pointer
766 static ALCboolean IsDevice(ALCdevice *pDevice)
768 ALCdevice *pTempDevice;
770 SuspendContext(NULL);
772 pTempDevice = g_pDeviceList;
773 while(pTempDevice && pTempDevice != pDevice)
774 pTempDevice = pTempDevice->next;
776 ProcessContext(NULL);
778 return (pTempDevice ? ALC_TRUE : ALC_FALSE);
782 IsContext
784 Check pContext is a valid Context pointer
786 static ALCboolean IsContext(ALCcontext *pContext)
788 ALCcontext *pTempContext;
790 SuspendContext(NULL);
792 pTempContext = g_pContextList;
793 while (pTempContext && pTempContext != pContext)
794 pTempContext = pTempContext->next;
796 ProcessContext(NULL);
798 return (pTempContext ? ALC_TRUE : ALC_FALSE);
803 alcSetError
805 Store latest ALC Error
807 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
809 if(IsDevice(device))
810 device->LastError = errorCode;
811 else
812 g_eLastNullDeviceError = errorCode;
817 SuspendContext
819 Thread-safe entry
821 ALCvoid SuspendContext(ALCcontext *pContext)
823 (void)pContext;
824 EnterCriticalSection(&g_csMutex);
829 ProcessContext
831 Thread-safe exit
833 ALCvoid ProcessContext(ALCcontext *pContext)
835 (void)pContext;
836 LeaveCriticalSection(&g_csMutex);
841 GetContextSuspended
843 Returns the currently active Context, in a locked state
845 ALCcontext *GetContextSuspended(void)
847 ALCcontext *pContext = NULL;
849 SuspendContext(NULL);
851 pContext = tls_get(LocalContext);
852 if(pContext && !IsContext(pContext))
854 tls_set(LocalContext, NULL);
855 pContext = NULL;
857 if(!pContext)
858 pContext = GlobalContext;
860 if(pContext)
861 SuspendContext(pContext);
863 ProcessContext(NULL);
865 return pContext;
870 InitContext
872 Initialize Context variables
874 static ALvoid InitContext(ALCcontext *pContext)
876 //Initialise listener
877 pContext->Listener.Gain = 1.0f;
878 pContext->Listener.MetersPerUnit = 1.0f;
879 pContext->Listener.Position[0] = 0.0f;
880 pContext->Listener.Position[1] = 0.0f;
881 pContext->Listener.Position[2] = 0.0f;
882 pContext->Listener.Velocity[0] = 0.0f;
883 pContext->Listener.Velocity[1] = 0.0f;
884 pContext->Listener.Velocity[2] = 0.0f;
885 pContext->Listener.Forward[0] = 0.0f;
886 pContext->Listener.Forward[1] = 0.0f;
887 pContext->Listener.Forward[2] = -1.0f;
888 pContext->Listener.Up[0] = 0.0f;
889 pContext->Listener.Up[1] = 1.0f;
890 pContext->Listener.Up[2] = 0.0f;
892 //Validate pContext
893 pContext->LastError = AL_NO_ERROR;
894 pContext->Suspended = AL_FALSE;
895 InitUIntMap(&pContext->SourceMap);
897 //Set globals
898 pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
899 pContext->SourceDistanceModel = AL_FALSE;
900 pContext->DopplerFactor = 1.0f;
901 pContext->DopplerVelocity = 1.0f;
902 pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
904 pContext->ExtensionList = alExtList;
909 ExitContext
911 Clean up Context, destroy any remaining Sources
913 static ALCvoid ExitContext(ALCcontext *pContext)
915 //Invalidate context
916 pContext->LastError = AL_NO_ERROR;
919 ///////////////////////////////////////////////////////
922 ///////////////////////////////////////////////////////
923 // ALC Functions calls
926 // This should probably move to another c file but for now ...
927 ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
929 ALCboolean DeviceFound = ALC_FALSE;
930 ALCdevice *device = NULL;
931 ALCint i;
933 if(SampleSize <= 0)
935 alcSetError(NULL, ALC_INVALID_VALUE);
936 return NULL;
939 if(deviceName && !deviceName[0])
940 deviceName = NULL;
942 device = calloc(1, sizeof(ALCdevice));
943 if(!device)
945 alcSetError(NULL, ALC_OUT_OF_MEMORY);
946 return NULL;
949 //Validate device
950 device->Connected = ALC_TRUE;
951 device->IsCaptureDevice = AL_TRUE;
953 device->szDeviceName = NULL;
955 device->Frequency = frequency;
956 device->Format = format;
957 device->UpdateSize = SampleSize;
958 device->NumUpdates = 1;
960 SuspendContext(NULL);
961 for(i = 0;BackendList[i].Init;i++)
963 device->Funcs = &BackendList[i].Funcs;
964 if(ALCdevice_OpenCapture(device, deviceName))
966 device->next = g_pDeviceList;
967 g_pDeviceList = device;
968 g_ulDeviceCount++;
970 DeviceFound = ALC_TRUE;
971 break;
974 ProcessContext(NULL);
976 if(!DeviceFound)
978 alcSetError(NULL, ALC_INVALID_VALUE);
979 free(device);
980 device = NULL;
983 return device;
986 ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
988 ALCdevice **list;
990 if(!IsDevice(pDevice) || !pDevice->IsCaptureDevice)
992 alcSetError(pDevice, ALC_INVALID_DEVICE);
993 return ALC_FALSE;
996 SuspendContext(NULL);
998 list = &g_pDeviceList;
999 while(*list != pDevice)
1000 list = &(*list)->next;
1002 *list = (*list)->next;
1003 g_ulDeviceCount--;
1005 ProcessContext(NULL);
1007 ALCdevice_CloseCapture(pDevice);
1009 free(pDevice->szDeviceName);
1010 pDevice->szDeviceName = NULL;
1012 free(pDevice);
1014 return ALC_TRUE;
1017 ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
1019 SuspendContext(NULL);
1020 if(!IsDevice(device) || !device->IsCaptureDevice)
1021 alcSetError(device, ALC_INVALID_DEVICE);
1022 else if(device->Connected)
1023 ALCdevice_StartCapture(device);
1024 ProcessContext(NULL);
1027 ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
1029 SuspendContext(NULL);
1030 if(!IsDevice(device) || !device->IsCaptureDevice)
1031 alcSetError(device, ALC_INVALID_DEVICE);
1032 else
1033 ALCdevice_StopCapture(device);
1034 ProcessContext(NULL);
1037 ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
1039 SuspendContext(NULL);
1040 if(!IsDevice(device) || !device->IsCaptureDevice)
1041 alcSetError(device, ALC_INVALID_DEVICE);
1042 else
1043 ALCdevice_CaptureSamples(device, buffer, samples);
1044 ProcessContext(NULL);
1048 alcGetError
1050 Return last ALC generated error code
1052 ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
1054 ALCenum errorCode;
1056 if(IsDevice(device))
1058 errorCode = device->LastError;
1059 device->LastError = ALC_NO_ERROR;
1061 else
1063 errorCode = g_eLastNullDeviceError;
1064 g_eLastNullDeviceError = ALC_NO_ERROR;
1066 return errorCode;
1071 alcSuspendContext
1073 Not functional
1075 ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *pContext)
1077 SuspendContext(NULL);
1078 if(IsContext(pContext))
1079 pContext->Suspended = AL_TRUE;
1080 ProcessContext(NULL);
1085 alcProcessContext
1087 Not functional
1089 ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *pContext)
1091 SuspendContext(NULL);
1092 if(IsContext(pContext))
1093 pContext->Suspended = AL_FALSE;
1094 ProcessContext(NULL);
1099 alcGetString
1101 Returns information about the Device, and error strings
1103 ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
1105 const ALCchar *value = NULL;
1107 switch (param)
1109 case ALC_NO_ERROR:
1110 value = alcNoError;
1111 break;
1113 case ALC_INVALID_ENUM:
1114 value = alcErrInvalidEnum;
1115 break;
1117 case ALC_INVALID_VALUE:
1118 value = alcErrInvalidValue;
1119 break;
1121 case ALC_INVALID_DEVICE:
1122 value = alcErrInvalidDevice;
1123 break;
1125 case ALC_INVALID_CONTEXT:
1126 value = alcErrInvalidContext;
1127 break;
1129 case ALC_OUT_OF_MEMORY:
1130 value = alcErrOutOfMemory;
1131 break;
1133 case ALC_DEVICE_SPECIFIER:
1134 if(IsDevice(pDevice))
1135 value = pDevice->szDeviceName;
1136 else
1138 ProbeDeviceList();
1139 value = alcDeviceList;
1141 break;
1143 case ALC_ALL_DEVICES_SPECIFIER:
1144 ProbeAllDeviceList();
1145 value = alcAllDeviceList;
1146 break;
1148 case ALC_CAPTURE_DEVICE_SPECIFIER:
1149 if(IsDevice(pDevice))
1150 value = pDevice->szDeviceName;
1151 else
1153 ProbeCaptureDeviceList();
1154 value = alcCaptureDeviceList;
1156 break;
1158 /* Default devices are always first in the list */
1159 case ALC_DEFAULT_DEVICE_SPECIFIER:
1160 if(!alcDeviceList)
1161 ProbeDeviceList();
1163 free(alcDefaultDeviceSpecifier);
1164 alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
1165 if(!alcDefaultDeviceSpecifier)
1166 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1167 value = alcDefaultDeviceSpecifier;
1168 break;
1170 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
1171 if(!alcAllDeviceList)
1172 ProbeAllDeviceList();
1174 free(alcDefaultAllDeviceSpecifier);
1175 alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
1176 alcAllDeviceList : "");
1177 if(!alcDefaultAllDeviceSpecifier)
1178 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1179 value = alcDefaultAllDeviceSpecifier;
1180 break;
1182 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
1183 if(!alcCaptureDeviceList)
1184 ProbeCaptureDeviceList();
1186 free(alcCaptureDefaultDeviceSpecifier);
1187 alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
1188 alcCaptureDeviceList : "");
1189 if(!alcCaptureDefaultDeviceSpecifier)
1190 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1191 value = alcCaptureDefaultDeviceSpecifier;
1192 break;
1194 case ALC_EXTENSIONS:
1195 if(IsDevice(pDevice))
1196 value = alcExtensionList;
1197 else
1198 value = alcNoDeviceExtList;
1199 break;
1201 default:
1202 alcSetError(pDevice, ALC_INVALID_ENUM);
1203 break;
1206 return value;
1211 alcGetIntegerv
1213 Returns information about the Device and the version of Open AL
1215 ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
1217 if(size == 0 || data == NULL)
1219 alcSetError(device, ALC_INVALID_VALUE);
1220 return;
1223 if(IsDevice(device) && device->IsCaptureDevice)
1225 SuspendContext(NULL);
1227 // Capture device
1228 switch (param)
1230 case ALC_CAPTURE_SAMPLES:
1231 *data = ALCdevice_AvailableSamples(device);
1232 break;
1234 case ALC_CONNECTED:
1235 *data = device->Connected;
1236 break;
1238 default:
1239 alcSetError(device, ALC_INVALID_ENUM);
1240 break;
1243 ProcessContext(NULL);
1244 return;
1247 // Playback Device
1248 switch (param)
1250 case ALC_MAJOR_VERSION:
1251 *data = alcMajorVersion;
1252 break;
1254 case ALC_MINOR_VERSION:
1255 *data = alcMinorVersion;
1256 break;
1258 case ALC_EFX_MAJOR_VERSION:
1259 *data = alcEFXMajorVersion;
1260 break;
1262 case ALC_EFX_MINOR_VERSION:
1263 *data = alcEFXMinorVersion;
1264 break;
1266 case ALC_MAX_AUXILIARY_SENDS:
1267 if(!IsDevice(device))
1268 alcSetError(device, ALC_INVALID_DEVICE);
1269 else
1270 *data = device->NumAuxSends;
1271 break;
1273 case ALC_ATTRIBUTES_SIZE:
1274 if(!IsDevice(device))
1275 alcSetError(device, ALC_INVALID_DEVICE);
1276 else
1277 *data = 13;
1278 break;
1280 case ALC_ALL_ATTRIBUTES:
1281 if(!IsDevice(device))
1282 alcSetError(device, ALC_INVALID_DEVICE);
1283 else if (size < 13)
1284 alcSetError(device, ALC_INVALID_VALUE);
1285 else
1287 int i = 0;
1289 SuspendContext(NULL);
1290 data[i++] = ALC_FREQUENCY;
1291 data[i++] = device->Frequency;
1293 data[i++] = ALC_REFRESH;
1294 data[i++] = device->Frequency / device->UpdateSize;
1296 data[i++] = ALC_SYNC;
1297 data[i++] = ALC_FALSE;
1299 data[i++] = ALC_MONO_SOURCES;
1300 data[i++] = device->NumMonoSources;
1302 data[i++] = ALC_STEREO_SOURCES;
1303 data[i++] = device->NumStereoSources;
1305 data[i++] = ALC_MAX_AUXILIARY_SENDS;
1306 data[i++] = device->NumAuxSends;
1308 data[i++] = 0;
1309 ProcessContext(NULL);
1311 break;
1313 case ALC_FREQUENCY:
1314 if(!IsDevice(device))
1315 alcSetError(device, ALC_INVALID_DEVICE);
1316 else
1317 *data = device->Frequency;
1318 break;
1320 case ALC_REFRESH:
1321 if(!IsDevice(device))
1322 alcSetError(device, ALC_INVALID_DEVICE);
1323 else
1324 *data = device->Frequency / device->UpdateSize;
1325 break;
1327 case ALC_SYNC:
1328 if(!IsDevice(device))
1329 alcSetError(device, ALC_INVALID_DEVICE);
1330 else
1331 *data = ALC_FALSE;
1332 break;
1334 case ALC_MONO_SOURCES:
1335 if(!IsDevice(device))
1336 alcSetError(device, ALC_INVALID_DEVICE);
1337 else
1338 *data = device->NumMonoSources;
1339 break;
1341 case ALC_STEREO_SOURCES:
1342 if(!IsDevice(device))
1343 alcSetError(device, ALC_INVALID_DEVICE);
1344 else
1345 *data = device->NumStereoSources;
1346 break;
1348 case ALC_CONNECTED:
1349 if(!IsDevice(device))
1350 alcSetError(device, ALC_INVALID_DEVICE);
1351 else
1352 *data = device->Connected;
1353 break;
1355 default:
1356 alcSetError(device, ALC_INVALID_ENUM);
1357 break;
1363 alcIsExtensionPresent
1365 Determines if there is support for a particular extension
1367 ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
1369 ALCboolean bResult = ALC_FALSE;
1370 const char *ptr;
1371 size_t len;
1373 if(!extName)
1375 alcSetError(device, ALC_INVALID_VALUE);
1376 return ALC_FALSE;
1379 len = strlen(extName);
1380 ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
1381 while(ptr && *ptr)
1383 if(strncasecmp(ptr, extName, len) == 0 &&
1384 (ptr[len] == '\0' || isspace(ptr[len])))
1386 bResult = ALC_TRUE;
1387 break;
1389 if((ptr=strchr(ptr, ' ')) != NULL)
1391 do {
1392 ++ptr;
1393 } while(isspace(*ptr));
1397 return bResult;
1402 alcGetProcAddress
1404 Retrieves the function address for a particular extension function
1406 ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
1408 ALsizei i = 0;
1410 if(!funcName)
1412 alcSetError(device, ALC_INVALID_VALUE);
1413 return NULL;
1416 while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
1417 i++;
1418 return alcFunctions[i].address;
1423 alcGetEnumValue
1425 Get the value for a particular ALC Enumerated Value
1427 ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
1429 ALsizei i = 0;
1431 if(!enumName)
1433 alcSetError(device, ALC_INVALID_VALUE);
1434 return (ALCenum)0;
1437 while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) != 0)
1438 i++;
1439 return enumeration[i].value;
1444 alcCreateContext
1446 Create and attach a Context to a particular Device.
1448 ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
1450 ALCcontext *ALContext;
1451 ALboolean running;
1452 ALuint attrIdx;
1453 void *temp;
1454 ALuint i;
1456 SuspendContext(NULL);
1458 if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
1460 alcSetError(device, ALC_INVALID_DEVICE);
1461 ProcessContext(NULL);
1462 return NULL;
1465 running = ((device->NumContexts > 0) ? AL_TRUE : AL_FALSE);
1467 // Reset Context Last Error code
1468 device->LastError = ALC_NO_ERROR;
1470 // Check for attributes
1471 if(attrList && attrList[0])
1473 ALCuint freq, numMono, numStereo, numSends;
1475 // If a context is already running on the device, stop playback so the
1476 // device attributes can be updated
1477 if(running)
1479 ProcessContext(NULL);
1480 ALCdevice_StopPlayback(device);
1481 SuspendContext(NULL);
1482 running = AL_FALSE;
1485 freq = device->Frequency;
1486 numMono = device->NumMonoSources;
1487 numStereo = device->NumStereoSources;
1488 numSends = device->NumAuxSends;
1490 attrIdx = 0;
1491 while(attrList[attrIdx])
1493 if(attrList[attrIdx] == ALC_FREQUENCY &&
1494 !ConfigValueExists(NULL, "frequency"))
1496 freq = attrList[attrIdx + 1];
1497 if(freq < 8000)
1498 freq = 8000;
1501 if(attrList[attrIdx] == ALC_STEREO_SOURCES)
1503 numStereo = attrList[attrIdx + 1];
1504 if(numStereo > device->MaxNoOfSources)
1505 numStereo = device->MaxNoOfSources;
1507 numMono = device->MaxNoOfSources - numStereo;
1510 if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
1511 !ConfigValueExists(NULL, "sends"))
1513 numSends = attrList[attrIdx + 1];
1514 if(numSends > MAX_SENDS)
1515 numSends = MAX_SENDS;
1518 attrIdx += 2;
1521 device->UpdateSize = (ALuint64)device->UpdateSize * freq /
1522 device->Frequency;
1524 device->Frequency = freq;
1525 device->NumMonoSources = numMono;
1526 device->NumStereoSources = numStereo;
1527 device->NumAuxSends = numSends;
1530 if(running == AL_FALSE && ALCdevice_ResetPlayback(device) == ALC_FALSE)
1532 alcSetError(device, ALC_INVALID_DEVICE);
1533 aluHandleDisconnect(device);
1534 ProcessContext(NULL);
1535 return NULL;
1537 aluInitPanning(device);
1539 for(i = 0;i < device->NumContexts;i++)
1541 ALCcontext *context = device->Contexts[i];
1542 ALsizei pos;
1544 SuspendContext(context);
1545 for(pos = 0;pos < context->EffectSlotMap.size;pos++)
1547 ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
1548 if(!slot->EffectState)
1549 continue;
1551 if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
1553 alcSetError(device, ALC_INVALID_DEVICE);
1554 aluHandleDisconnect(device);
1555 ProcessContext(context);
1556 ProcessContext(NULL);
1557 ALCdevice_StopPlayback(device);
1558 return NULL;
1560 ALEffect_Update(slot->EffectState, context, &slot->effect);
1563 for(pos = 0;pos < context->SourceMap.size;pos++)
1565 ALsource *source = context->SourceMap.array[pos].value;
1566 ALuint s = device->NumAuxSends;
1567 while(s < MAX_SENDS)
1569 if(source->Send[s].Slot)
1570 source->Send[s].Slot->refcount--;
1571 source->Send[s].Slot = NULL;
1572 source->Send[s].WetFilter.type = 0;
1573 source->Send[s].WetFilter.filter = 0;
1574 s++;
1576 source->NeedsUpdate = AL_TRUE;
1578 ProcessContext(context);
1581 if(device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
1583 if(!device->Bs2b)
1585 device->Bs2b = calloc(1, sizeof(*device->Bs2b));
1586 bs2b_clear(device->Bs2b);
1588 bs2b_set_srate(device->Bs2b, device->Frequency);
1589 bs2b_set_level(device->Bs2b, device->Bs2bLevel);
1591 else
1593 free(device->Bs2b);
1594 device->Bs2b = NULL;
1597 if(aluChannelsFromFormat(device->Format) <= 2)
1599 device->HeadDampen = GetConfigValueFloat(NULL, "head_dampen", DEFAULT_HEAD_DAMPEN);
1600 device->HeadDampen = __min(device->HeadDampen, 1.0f);
1601 device->HeadDampen = __max(device->HeadDampen, 0.0f);
1603 else
1604 device->HeadDampen = 0.0f;
1606 temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
1607 if(!temp)
1609 alcSetError(device, ALC_OUT_OF_MEMORY);
1610 ProcessContext(NULL);
1611 return NULL;
1613 device->Contexts = temp;
1615 ALContext = calloc(1, sizeof(ALCcontext));
1616 if(!ALContext)
1618 alcSetError(device, ALC_OUT_OF_MEMORY);
1619 ProcessContext(NULL);
1620 return NULL;
1623 device->Contexts[device->NumContexts++] = ALContext;
1624 ALContext->Device = device;
1626 InitContext(ALContext);
1628 ALContext->next = g_pContextList;
1629 g_pContextList = ALContext;
1630 g_ulContextCount++;
1632 ProcessContext(NULL);
1634 return ALContext;
1639 alcDestroyContext
1641 Remove a Context
1643 ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
1645 ALCdevice *Device;
1646 ALCcontext **list;
1647 ALuint i;
1649 if(!IsContext(context))
1651 alcSetError(NULL, ALC_INVALID_CONTEXT);
1652 return;
1655 Device = context->Device;
1657 if(Device->NumContexts == 1)
1658 ALCdevice_StopPlayback(Device);
1660 SuspendContext(NULL);
1662 if(context == GlobalContext)
1663 GlobalContext = NULL;
1665 for(i = 0;i < Device->NumContexts-1;i++)
1667 if(Device->Contexts[i] == context)
1669 Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
1670 break;
1673 Device->NumContexts--;
1675 // Lock context
1676 SuspendContext(context);
1678 if(context->SourceMap.size > 0)
1680 #ifdef _DEBUG
1681 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size);
1682 #endif
1683 ReleaseALSources(context);
1685 ResetUIntMap(&context->SourceMap);
1687 if(context->EffectSlotMap.size > 0)
1689 #ifdef _DEBUG
1690 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size);
1691 #endif
1692 ReleaseALAuxiliaryEffectSlots(context);
1694 ResetUIntMap(&context->EffectSlotMap);
1696 list = &g_pContextList;
1697 while(*list != context)
1698 list = &(*list)->next;
1700 *list = (*list)->next;
1701 g_ulContextCount--;
1703 // Unlock context
1704 ProcessContext(context);
1705 ProcessContext(NULL);
1707 ExitContext(context);
1709 // Free memory (MUST do this after ProcessContext)
1710 memset(context, 0, sizeof(ALCcontext));
1711 free(context);
1716 alcGetCurrentContext
1718 Returns the currently active Context
1720 ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
1722 ALCcontext *pContext;
1724 if((pContext=GetContextSuspended()) != NULL)
1725 ProcessContext(pContext);
1727 return pContext;
1731 alcGetThreadContext
1733 Returns the currently active thread-local Context
1735 ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
1737 ALCcontext *pContext = NULL;
1739 SuspendContext(NULL);
1741 pContext = tls_get(LocalContext);
1742 if(pContext && !IsContext(pContext))
1744 tls_set(LocalContext, NULL);
1745 pContext = NULL;
1748 ProcessContext(NULL);
1750 return pContext;
1755 alcGetContextsDevice
1757 Returns the Device that a particular Context is attached to
1759 ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
1761 ALCdevice *pDevice = NULL;
1763 SuspendContext(NULL);
1764 if(IsContext(pContext))
1765 pDevice = pContext->Device;
1766 else
1767 alcSetError(NULL, ALC_INVALID_CONTEXT);
1768 ProcessContext(NULL);
1770 return pDevice;
1775 alcMakeContextCurrent
1777 Makes the given Context the active Context
1779 ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
1781 ALboolean bReturn = AL_TRUE;
1783 SuspendContext(NULL);
1785 // context must be a valid Context or NULL
1786 if(context == NULL || IsContext(context))
1788 GlobalContext = context;
1789 tls_set(LocalContext, NULL);
1791 else
1793 alcSetError(NULL, ALC_INVALID_CONTEXT);
1794 bReturn = AL_FALSE;
1797 ProcessContext(NULL);
1799 return bReturn;
1803 alcSetThreadContext
1805 Makes the given Context the active Context for the current thread
1807 ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
1809 ALboolean bReturn = AL_TRUE;
1811 SuspendContext(NULL);
1813 // context must be a valid Context or NULL
1814 if(context == NULL || IsContext(context))
1815 tls_set(LocalContext, context);
1816 else
1818 alcSetError(NULL, ALC_INVALID_CONTEXT);
1819 bReturn = AL_FALSE;
1822 ProcessContext(NULL);
1824 return bReturn;
1828 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1829 void SetDefaultChannelOrder(ALCdevice *device)
1831 switch(aluChannelsFromFormat(device->Format))
1833 case 1: device->DevChannels[FRONT_CENTER] = 0; break;
1835 case 2: device->DevChannels[FRONT_LEFT] = 0;
1836 device->DevChannels[FRONT_RIGHT] = 1; break;
1838 case 4: device->DevChannels[FRONT_LEFT] = 0;
1839 device->DevChannels[FRONT_RIGHT] = 1;
1840 device->DevChannels[BACK_LEFT] = 2;
1841 device->DevChannels[BACK_RIGHT] = 3; break;
1843 case 6: device->DevChannels[FRONT_LEFT] = 0;
1844 device->DevChannels[FRONT_RIGHT] = 1;
1845 device->DevChannels[BACK_LEFT] = 2;
1846 device->DevChannels[BACK_RIGHT] = 3;
1847 device->DevChannels[FRONT_CENTER] = 4;
1848 device->DevChannels[LFE] = 5; break;
1850 case 7: device->DevChannels[FRONT_LEFT] = 0;
1851 device->DevChannels[FRONT_RIGHT] = 1;
1852 device->DevChannels[FRONT_CENTER] = 2;
1853 device->DevChannels[LFE] = 3;
1854 device->DevChannels[BACK_CENTER] = 4;
1855 device->DevChannels[SIDE_LEFT] = 5;
1856 device->DevChannels[SIDE_RIGHT] = 6; break;
1858 case 8: device->DevChannels[FRONT_LEFT] = 0;
1859 device->DevChannels[FRONT_RIGHT] = 1;
1860 device->DevChannels[BACK_LEFT] = 2;
1861 device->DevChannels[BACK_RIGHT] = 3;
1862 device->DevChannels[FRONT_CENTER] = 4;
1863 device->DevChannels[LFE] = 5;
1864 device->DevChannels[SIDE_LEFT] = 6;
1865 device->DevChannels[SIDE_RIGHT] = 7; break;
1868 // Sets the default order used by WaveFormatEx
1869 void SetDefaultWFXChannelOrder(ALCdevice *device)
1871 switch(aluChannelsFromFormat(device->Format))
1873 case 1: device->DevChannels[FRONT_CENTER] = 0; break;
1875 case 2: device->DevChannels[FRONT_LEFT] = 0;
1876 device->DevChannels[FRONT_RIGHT] = 1; break;
1878 case 4: device->DevChannels[FRONT_LEFT] = 0;
1879 device->DevChannels[FRONT_RIGHT] = 1;
1880 device->DevChannels[BACK_LEFT] = 2;
1881 device->DevChannels[BACK_RIGHT] = 3; break;
1883 case 6: device->DevChannels[FRONT_LEFT] = 0;
1884 device->DevChannels[FRONT_RIGHT] = 1;
1885 device->DevChannels[FRONT_CENTER] = 2;
1886 device->DevChannels[LFE] = 3;
1887 device->DevChannels[BACK_LEFT] = 4;
1888 device->DevChannels[BACK_RIGHT] = 5; break;
1890 case 7: device->DevChannels[FRONT_LEFT] = 0;
1891 device->DevChannels[FRONT_RIGHT] = 1;
1892 device->DevChannels[FRONT_CENTER] = 2;
1893 device->DevChannels[LFE] = 3;
1894 device->DevChannels[BACK_CENTER] = 4;
1895 device->DevChannels[SIDE_LEFT] = 5;
1896 device->DevChannels[SIDE_RIGHT] = 6; break;
1898 case 8: device->DevChannels[FRONT_LEFT] = 0;
1899 device->DevChannels[FRONT_RIGHT] = 1;
1900 device->DevChannels[FRONT_CENTER] = 2;
1901 device->DevChannels[LFE] = 3;
1902 device->DevChannels[BACK_LEFT] = 4;
1903 device->DevChannels[BACK_RIGHT] = 5;
1904 device->DevChannels[SIDE_LEFT] = 6;
1905 device->DevChannels[SIDE_RIGHT] = 7; break;
1909 static ALenum GetFormatFromString(const char *str)
1911 if(strcasecmp(str, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32;
1912 if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32;
1913 if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32;
1914 if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32;
1915 if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32;
1916 if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32;
1918 if(strcasecmp(str, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16;
1919 if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16;
1920 if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16;
1921 if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16;
1922 if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16;
1923 if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16;
1925 if(strcasecmp(str, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8;
1926 if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8;
1927 if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8;
1928 if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8;
1929 if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8;
1930 if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8;
1932 AL_PRINT("Unknown format: \"%s\"\n", str);
1933 return AL_FORMAT_STEREO16;
1937 alcOpenDevice
1939 Open the Device specified.
1941 ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
1943 ALboolean bDeviceFound = AL_FALSE;
1944 const ALCchar *fmt;
1945 ALCdevice *device;
1946 ALint i;
1948 if(deviceName && !deviceName[0])
1949 deviceName = NULL;
1951 device = calloc(1, sizeof(ALCdevice));
1952 if(!device)
1954 alcSetError(NULL, ALC_OUT_OF_MEMORY);
1955 return NULL;
1958 //Validate device
1959 device->Connected = ALC_TRUE;
1960 device->IsCaptureDevice = AL_FALSE;
1961 device->LastError = ALC_NO_ERROR;
1963 device->Bs2b = NULL;
1964 device->szDeviceName = NULL;
1966 device->Contexts = NULL;
1967 device->NumContexts = 0;
1969 InitUIntMap(&device->BufferMap);
1970 InitUIntMap(&device->EffectMap);
1971 InitUIntMap(&device->FilterMap);
1972 InitUIntMap(&device->DatabufferMap);
1974 //Set output format
1975 device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
1976 if(device->Frequency < 8000)
1977 device->Frequency = 8000;
1979 fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
1980 device->Format = GetFormatFromString(fmt);
1982 device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
1983 if(device->NumUpdates < 2)
1984 device->NumUpdates = 4;
1986 i = GetConfigValueInt(NULL, "refresh", 4096);
1987 if(i <= 0) i = 4096;
1989 device->UpdateSize = GetConfigValueInt(NULL, "period_size", i/device->NumUpdates);
1990 if(device->UpdateSize <= 0)
1991 device->UpdateSize = i/device->NumUpdates;
1993 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
1994 if((ALint)device->MaxNoOfSources <= 0)
1995 device->MaxNoOfSources = 256;
1997 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
1998 if((ALint)device->AuxiliaryEffectSlotMax <= 0)
1999 device->AuxiliaryEffectSlotMax = 4;
2001 device->NumStereoSources = 1;
2002 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
2004 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
2005 if(device->NumAuxSends > MAX_SENDS)
2006 device->NumAuxSends = MAX_SENDS;
2008 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
2010 device->HeadDampen = 0.0f;
2012 // Find a playback device to open
2013 SuspendContext(NULL);
2014 for(i = 0;BackendList[i].Init;i++)
2016 device->Funcs = &BackendList[i].Funcs;
2017 if(ALCdevice_OpenPlayback(device, deviceName))
2019 device->next = g_pDeviceList;
2020 g_pDeviceList = device;
2021 g_ulDeviceCount++;
2023 bDeviceFound = AL_TRUE;
2024 break;
2027 ProcessContext(NULL);
2029 if(!bDeviceFound)
2031 // No suitable output device found
2032 alcSetError(NULL, ALC_INVALID_VALUE);
2033 free(device);
2034 device = NULL;
2037 return device;
2042 alcCloseDevice
2044 Close the specified Device
2046 ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
2048 ALCdevice **list;
2050 if(!IsDevice(pDevice) || pDevice->IsCaptureDevice)
2052 alcSetError(pDevice, ALC_INVALID_DEVICE);
2053 return ALC_FALSE;
2056 SuspendContext(NULL);
2058 list = &g_pDeviceList;
2059 while(*list != pDevice)
2060 list = &(*list)->next;
2062 *list = (*list)->next;
2063 g_ulDeviceCount--;
2065 ProcessContext(NULL);
2067 if(pDevice->NumContexts > 0)
2069 #ifdef _DEBUG
2070 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
2071 #endif
2072 while(pDevice->NumContexts > 0)
2073 alcDestroyContext(pDevice->Contexts[0]);
2075 ALCdevice_ClosePlayback(pDevice);
2077 if(pDevice->BufferMap.size > 0)
2079 #ifdef _DEBUG
2080 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferMap.size);
2081 #endif
2082 ReleaseALBuffers(pDevice);
2084 ResetUIntMap(&pDevice->BufferMap);
2086 if(pDevice->EffectMap.size > 0)
2088 #ifdef _DEBUG
2089 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size);
2090 #endif
2091 ReleaseALEffects(pDevice);
2093 ResetUIntMap(&pDevice->EffectMap);
2095 if(pDevice->FilterMap.size > 0)
2097 #ifdef _DEBUG
2098 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size);
2099 #endif
2100 ReleaseALFilters(pDevice);
2102 ResetUIntMap(&pDevice->FilterMap);
2104 if(pDevice->DatabufferMap.size > 0)
2106 #ifdef _DEBUG
2107 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice->DatabufferMap.size);
2108 #endif
2109 ReleaseALDatabuffers(pDevice);
2111 ResetUIntMap(&pDevice->DatabufferMap);
2113 free(pDevice->Bs2b);
2114 pDevice->Bs2b = NULL;
2116 free(pDevice->szDeviceName);
2117 pDevice->szDeviceName = NULL;
2119 free(pDevice->Contexts);
2120 pDevice->Contexts = NULL;
2122 //Release device structure
2123 memset(pDevice, 0, sizeof(ALCdevice));
2124 free(pDevice);
2126 return ALC_TRUE;
2130 ALCvoid ReleaseALC(ALCvoid)
2132 free(alcDeviceList); alcDeviceList = NULL;
2133 alcDeviceListSize = 0;
2134 free(alcAllDeviceList); alcAllDeviceList = NULL;
2135 alcAllDeviceListSize = 0;
2136 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
2137 alcCaptureDeviceListSize = 0;
2139 free(alcDefaultDeviceSpecifier);
2140 alcDefaultDeviceSpecifier = NULL;
2141 free(alcDefaultAllDeviceSpecifier);
2142 alcDefaultAllDeviceSpecifier = NULL;
2143 free(alcCaptureDefaultDeviceSpecifier);
2144 alcCaptureDefaultDeviceSpecifier = NULL;
2146 #ifdef _DEBUG
2147 if(g_ulDeviceCount > 0)
2148 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
2149 #endif
2151 while(g_pDeviceList)
2153 if(g_pDeviceList->IsCaptureDevice)
2154 alcCaptureCloseDevice(g_pDeviceList);
2155 else
2156 alcCloseDevice(g_pDeviceList);
2160 ///////////////////////////////////////////////////////