Avoid making Resampler[Pre]Padding static
[openal-soft.git] / Alc / ALc.c
blobd2bdf14414f14480c783ff34aa713577bb1f9b41
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 #ifdef HAVE_WAVE
75 { "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs },
76 #endif
78 { NULL, NULL, NULL, NULL, EmptyFuncs }
80 #undef EmptyFuncs
82 ///////////////////////////////////////////////////////
84 #define ALC_EFX_MAJOR_VERSION 0x20001
85 #define ALC_EFX_MINOR_VERSION 0x20002
86 #define ALC_MAX_AUXILIARY_SENDS 0x20003
88 ///////////////////////////////////////////////////////
89 // STRING and EXTENSIONS
91 typedef struct ALCfunction {
92 const ALCchar *funcName;
93 ALCvoid *address;
94 } ALCfunction;
96 typedef struct ALCenums {
97 const ALCchar *enumName;
98 ALCenum value;
99 } ALCenums;
102 static const ALCfunction alcFunctions[] = {
103 { "alcCreateContext", (ALCvoid *) alcCreateContext },
104 { "alcMakeContextCurrent", (ALCvoid *) alcMakeContextCurrent },
105 { "alcProcessContext", (ALCvoid *) alcProcessContext },
106 { "alcSuspendContext", (ALCvoid *) alcSuspendContext },
107 { "alcDestroyContext", (ALCvoid *) alcDestroyContext },
108 { "alcGetCurrentContext", (ALCvoid *) alcGetCurrentContext },
109 { "alcGetContextsDevice", (ALCvoid *) alcGetContextsDevice },
110 { "alcOpenDevice", (ALCvoid *) alcOpenDevice },
111 { "alcCloseDevice", (ALCvoid *) alcCloseDevice },
112 { "alcGetError", (ALCvoid *) alcGetError },
113 { "alcIsExtensionPresent", (ALCvoid *) alcIsExtensionPresent },
114 { "alcGetProcAddress", (ALCvoid *) alcGetProcAddress },
115 { "alcGetEnumValue", (ALCvoid *) alcGetEnumValue },
116 { "alcGetString", (ALCvoid *) alcGetString },
117 { "alcGetIntegerv", (ALCvoid *) alcGetIntegerv },
118 { "alcCaptureOpenDevice", (ALCvoid *) alcCaptureOpenDevice },
119 { "alcCaptureCloseDevice", (ALCvoid *) alcCaptureCloseDevice },
120 { "alcCaptureStart", (ALCvoid *) alcCaptureStart },
121 { "alcCaptureStop", (ALCvoid *) alcCaptureStop },
122 { "alcCaptureSamples", (ALCvoid *) alcCaptureSamples },
124 { "alcSetThreadContext", (ALCvoid *) alcSetThreadContext },
125 { "alcGetThreadContext", (ALCvoid *) alcGetThreadContext },
127 { "alEnable", (ALCvoid *) alEnable },
128 { "alDisable", (ALCvoid *) alDisable },
129 { "alIsEnabled", (ALCvoid *) alIsEnabled },
130 { "alGetString", (ALCvoid *) alGetString },
131 { "alGetBooleanv", (ALCvoid *) alGetBooleanv },
132 { "alGetIntegerv", (ALCvoid *) alGetIntegerv },
133 { "alGetFloatv", (ALCvoid *) alGetFloatv },
134 { "alGetDoublev", (ALCvoid *) alGetDoublev },
135 { "alGetBoolean", (ALCvoid *) alGetBoolean },
136 { "alGetInteger", (ALCvoid *) alGetInteger },
137 { "alGetFloat", (ALCvoid *) alGetFloat },
138 { "alGetDouble", (ALCvoid *) alGetDouble },
139 { "alGetError", (ALCvoid *) alGetError },
140 { "alIsExtensionPresent", (ALCvoid *) alIsExtensionPresent },
141 { "alGetProcAddress", (ALCvoid *) alGetProcAddress },
142 { "alGetEnumValue", (ALCvoid *) alGetEnumValue },
143 { "alListenerf", (ALCvoid *) alListenerf },
144 { "alListener3f", (ALCvoid *) alListener3f },
145 { "alListenerfv", (ALCvoid *) alListenerfv },
146 { "alListeneri", (ALCvoid *) alListeneri },
147 { "alListener3i", (ALCvoid *) alListener3i },
148 { "alListeneriv", (ALCvoid *) alListeneriv },
149 { "alGetListenerf", (ALCvoid *) alGetListenerf },
150 { "alGetListener3f", (ALCvoid *) alGetListener3f },
151 { "alGetListenerfv", (ALCvoid *) alGetListenerfv },
152 { "alGetListeneri", (ALCvoid *) alGetListeneri },
153 { "alGetListener3i", (ALCvoid *) alGetListener3i },
154 { "alGetListeneriv", (ALCvoid *) alGetListeneriv },
155 { "alGenSources", (ALCvoid *) alGenSources },
156 { "alDeleteSources", (ALCvoid *) alDeleteSources },
157 { "alIsSource", (ALCvoid *) alIsSource },
158 { "alSourcef", (ALCvoid *) alSourcef },
159 { "alSource3f", (ALCvoid *) alSource3f },
160 { "alSourcefv", (ALCvoid *) alSourcefv },
161 { "alSourcei", (ALCvoid *) alSourcei },
162 { "alSource3i", (ALCvoid *) alSource3i },
163 { "alSourceiv", (ALCvoid *) alSourceiv },
164 { "alGetSourcef", (ALCvoid *) alGetSourcef },
165 { "alGetSource3f", (ALCvoid *) alGetSource3f },
166 { "alGetSourcefv", (ALCvoid *) alGetSourcefv },
167 { "alGetSourcei", (ALCvoid *) alGetSourcei },
168 { "alGetSource3i", (ALCvoid *) alGetSource3i },
169 { "alGetSourceiv", (ALCvoid *) alGetSourceiv },
170 { "alSourcePlayv", (ALCvoid *) alSourcePlayv },
171 { "alSourceStopv", (ALCvoid *) alSourceStopv },
172 { "alSourceRewindv", (ALCvoid *) alSourceRewindv },
173 { "alSourcePausev", (ALCvoid *) alSourcePausev },
174 { "alSourcePlay", (ALCvoid *) alSourcePlay },
175 { "alSourceStop", (ALCvoid *) alSourceStop },
176 { "alSourceRewind", (ALCvoid *) alSourceRewind },
177 { "alSourcePause", (ALCvoid *) alSourcePause },
178 { "alSourceQueueBuffers", (ALCvoid *) alSourceQueueBuffers },
179 { "alSourceUnqueueBuffers", (ALCvoid *) alSourceUnqueueBuffers },
180 { "alGenBuffers", (ALCvoid *) alGenBuffers },
181 { "alDeleteBuffers", (ALCvoid *) alDeleteBuffers },
182 { "alIsBuffer", (ALCvoid *) alIsBuffer },
183 { "alBufferData", (ALCvoid *) alBufferData },
184 { "alBufferf", (ALCvoid *) alBufferf },
185 { "alBuffer3f", (ALCvoid *) alBuffer3f },
186 { "alBufferfv", (ALCvoid *) alBufferfv },
187 { "alBufferi", (ALCvoid *) alBufferi },
188 { "alBuffer3i", (ALCvoid *) alBuffer3i },
189 { "alBufferiv", (ALCvoid *) alBufferiv },
190 { "alGetBufferf", (ALCvoid *) alGetBufferf },
191 { "alGetBuffer3f", (ALCvoid *) alGetBuffer3f },
192 { "alGetBufferfv", (ALCvoid *) alGetBufferfv },
193 { "alGetBufferi", (ALCvoid *) alGetBufferi },
194 { "alGetBuffer3i", (ALCvoid *) alGetBuffer3i },
195 { "alGetBufferiv", (ALCvoid *) alGetBufferiv },
196 { "alDopplerFactor", (ALCvoid *) alDopplerFactor },
197 { "alDopplerVelocity", (ALCvoid *) alDopplerVelocity },
198 { "alSpeedOfSound", (ALCvoid *) alSpeedOfSound },
199 { "alDistanceModel", (ALCvoid *) alDistanceModel },
201 { "alGenFilters", (ALCvoid *) alGenFilters },
202 { "alDeleteFilters", (ALCvoid *) alDeleteFilters },
203 { "alIsFilter", (ALCvoid *) alIsFilter },
204 { "alFilteri", (ALCvoid *) alFilteri },
205 { "alFilteriv", (ALCvoid *) alFilteriv },
206 { "alFilterf", (ALCvoid *) alFilterf },
207 { "alFilterfv", (ALCvoid *) alFilterfv },
208 { "alGetFilteri", (ALCvoid *) alGetFilteri },
209 { "alGetFilteriv", (ALCvoid *) alGetFilteriv },
210 { "alGetFilterf", (ALCvoid *) alGetFilterf },
211 { "alGetFilterfv", (ALCvoid *) alGetFilterfv },
213 { "alGenEffects", (ALCvoid *) alGenEffects },
214 { "alDeleteEffects", (ALCvoid *) alDeleteEffects },
215 { "alIsEffect", (ALCvoid *) alIsEffect },
216 { "alEffecti", (ALCvoid *) alEffecti },
217 { "alEffectiv", (ALCvoid *) alEffectiv },
218 { "alEffectf", (ALCvoid *) alEffectf },
219 { "alEffectfv", (ALCvoid *) alEffectfv },
220 { "alGetEffecti", (ALCvoid *) alGetEffecti },
221 { "alGetEffectiv", (ALCvoid *) alGetEffectiv },
222 { "alGetEffectf", (ALCvoid *) alGetEffectf },
223 { "alGetEffectfv", (ALCvoid *) alGetEffectfv },
225 { "alGenAuxiliaryEffectSlots", (ALCvoid *) alGenAuxiliaryEffectSlots},
226 { "alDeleteAuxiliaryEffectSlots",(ALCvoid *) alDeleteAuxiliaryEffectSlots},
227 { "alIsAuxiliaryEffectSlot", (ALCvoid *) alIsAuxiliaryEffectSlot },
228 { "alAuxiliaryEffectSloti", (ALCvoid *) alAuxiliaryEffectSloti },
229 { "alAuxiliaryEffectSlotiv", (ALCvoid *) alAuxiliaryEffectSlotiv },
230 { "alAuxiliaryEffectSlotf", (ALCvoid *) alAuxiliaryEffectSlotf },
231 { "alAuxiliaryEffectSlotfv", (ALCvoid *) alAuxiliaryEffectSlotfv },
232 { "alGetAuxiliaryEffectSloti", (ALCvoid *) alGetAuxiliaryEffectSloti},
233 { "alGetAuxiliaryEffectSlotiv", (ALCvoid *) alGetAuxiliaryEffectSlotiv},
234 { "alGetAuxiliaryEffectSlotf", (ALCvoid *) alGetAuxiliaryEffectSlotf},
235 { "alGetAuxiliaryEffectSlotfv", (ALCvoid *) alGetAuxiliaryEffectSlotfv},
237 { "alBufferSubDataEXT", (ALCvoid *) alBufferSubDataEXT },
239 { "alBufferSubDataSOFT", (ALCvoid *) alBufferSubDataSOFT },
240 #if 0
241 { "alGenDatabuffersEXT", (ALCvoid *) alGenDatabuffersEXT },
242 { "alDeleteDatabuffersEXT", (ALCvoid *) alDeleteDatabuffersEXT },
243 { "alIsDatabufferEXT", (ALCvoid *) alIsDatabufferEXT },
244 { "alDatabufferDataEXT", (ALCvoid *) alDatabufferDataEXT },
245 { "alDatabufferSubDataEXT", (ALCvoid *) alDatabufferSubDataEXT },
246 { "alGetDatabufferSubDataEXT", (ALCvoid *) alGetDatabufferSubDataEXT},
247 { "alDatabufferfEXT", (ALCvoid *) alDatabufferfEXT },
248 { "alDatabufferfvEXT", (ALCvoid *) alDatabufferfvEXT },
249 { "alDatabufferiEXT", (ALCvoid *) alDatabufferiEXT },
250 { "alDatabufferivEXT", (ALCvoid *) alDatabufferivEXT },
251 { "alGetDatabufferfEXT", (ALCvoid *) alGetDatabufferfEXT },
252 { "alGetDatabufferfvEXT", (ALCvoid *) alGetDatabufferfvEXT },
253 { "alGetDatabufferiEXT", (ALCvoid *) alGetDatabufferiEXT },
254 { "alGetDatabufferivEXT", (ALCvoid *) alGetDatabufferivEXT },
255 { "alSelectDatabufferEXT", (ALCvoid *) alSelectDatabufferEXT },
256 { "alMapDatabufferEXT", (ALCvoid *) alMapDatabufferEXT },
257 { "alUnmapDatabufferEXT", (ALCvoid *) alUnmapDatabufferEXT },
258 #endif
259 { NULL, (ALCvoid *) NULL }
262 static const ALCenums enumeration[] = {
263 // Types
264 { "ALC_INVALID", ALC_INVALID },
265 { "ALC_FALSE", ALC_FALSE },
266 { "ALC_TRUE", ALC_TRUE },
268 // ALC Properties
269 { "ALC_MAJOR_VERSION", ALC_MAJOR_VERSION },
270 { "ALC_MINOR_VERSION", ALC_MINOR_VERSION },
271 { "ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE },
272 { "ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES },
273 { "ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER },
274 { "ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER },
275 { "ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER },
276 { "ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER },
277 { "ALC_EXTENSIONS", ALC_EXTENSIONS },
278 { "ALC_FREQUENCY", ALC_FREQUENCY },
279 { "ALC_REFRESH", ALC_REFRESH },
280 { "ALC_SYNC", ALC_SYNC },
281 { "ALC_MONO_SOURCES", ALC_MONO_SOURCES },
282 { "ALC_STEREO_SOURCES", ALC_STEREO_SOURCES },
283 { "ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER },
284 { "ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER},
285 { "ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES },
286 { "ALC_CONNECTED", ALC_CONNECTED },
288 // EFX Properties
289 { "ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION },
290 { "ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION },
291 { "ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS },
293 // ALC Error Message
294 { "ALC_NO_ERROR", ALC_NO_ERROR },
295 { "ALC_INVALID_DEVICE", ALC_INVALID_DEVICE },
296 { "ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT },
297 { "ALC_INVALID_ENUM", ALC_INVALID_ENUM },
298 { "ALC_INVALID_VALUE", ALC_INVALID_VALUE },
299 { "ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY },
300 { NULL, (ALCenum)0 }
302 // Error strings
303 static const ALCchar alcNoError[] = "No Error";
304 static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
305 static const ALCchar alcErrInvalidContext[] = "Invalid Context";
306 static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
307 static const ALCchar alcErrInvalidValue[] = "Invalid Value";
308 static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
310 /* Device lists. Sizes only include the first ending null character, not the
311 * second */
312 static ALCchar *alcDeviceList;
313 static size_t alcDeviceListSize;
314 static ALCchar *alcAllDeviceList;
315 static size_t alcAllDeviceListSize;
316 static ALCchar *alcCaptureDeviceList;
317 static size_t alcCaptureDeviceListSize;
318 // Default is always the first in the list
319 static ALCchar *alcDefaultDeviceSpecifier;
320 static ALCchar *alcDefaultAllDeviceSpecifier;
321 static ALCchar *alcCaptureDefaultDeviceSpecifier;
324 static const ALCchar alcNoDeviceExtList[] =
325 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
326 "ALC_EXT_thread_local_context";
327 static const ALCchar alcExtensionList[] =
328 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
329 "ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context";
330 static const ALCint alcMajorVersion = 1;
331 static const ALCint alcMinorVersion = 1;
333 static const ALCint alcEFXMajorVersion = 1;
334 static const ALCint alcEFXMinorVersion = 0;
336 ///////////////////////////////////////////////////////
339 ///////////////////////////////////////////////////////
340 // Global Variables
342 static ALCdevice *g_pDeviceList = NULL;
343 static ALCuint g_ulDeviceCount = 0;
345 static CRITICAL_SECTION g_csMutex;
347 // Context List
348 static ALCcontext *g_pContextList = NULL;
349 static ALCuint g_ulContextCount = 0;
351 // Thread-local current context
352 static tls_type LocalContext;
353 // Process-wide current context
354 static ALCcontext *GlobalContext;
356 // Context Error
357 static ALCenum g_eLastNullDeviceError = ALC_NO_ERROR;
359 // Default context extensions
360 static const ALchar alExtList[] =
361 "AL_EXTX_buffer_sub_data AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE "
362 "AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXTX_loop_points "
363 "AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET "
364 "AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_sub_data";
366 // Mixing Priority Level
367 static ALint RTPrioLevel;
369 // Output Log File
370 static FILE *LogFile;
372 ///////////////////////////////////////////////////////
375 ///////////////////////////////////////////////////////
376 // ALC Related helper functions
377 #ifdef HAVE_GCC_DESTRUCTOR
378 static void alc_init(void) __attribute__((constructor));
379 static void alc_deinit(void) __attribute__((destructor));
380 #else
381 #ifdef _WIN32
382 static void alc_init(void);
383 static void alc_deinit(void);
385 BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
387 (void)lpReserved;
389 // Perform actions based on the reason for calling.
390 switch(ul_reason_for_call)
392 case DLL_PROCESS_ATTACH:
393 DisableThreadLibraryCalls(hModule);
394 alc_init();
395 break;
397 case DLL_PROCESS_DETACH:
398 alc_deinit();
399 break;
401 return TRUE;
403 #endif
404 #endif
406 static void alc_init(void)
408 int i;
409 const char *devs, *str;
411 str = getenv("ALSOFT_LOGFILE");
412 if(str && str[0])
414 LogFile = fopen(str, "w");
415 if(!LogFile)
416 fprintf(stderr, "AL lib: Failed to open log file '%s'\n", str);
418 if(!LogFile)
419 LogFile = stderr;
421 InitializeCriticalSection(&g_csMutex);
422 ALTHUNK_INIT();
423 ReadALConfig();
425 tls_create(&LocalContext);
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 tls_delete(LocalContext);
544 FreeALConfig();
545 ALTHUNK_EXIT();
546 DeleteCriticalSection(&g_csMutex);
548 if(LogFile != stderr)
549 fclose(LogFile);
550 LogFile = NULL;
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;
816 /* UpdateDeviceParams:
818 * Updates device parameters according to the attribute list.
820 static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
822 ALCuint freq, numMono, numStereo, numSends;
823 ALboolean running;
824 ALuint oldRate;
825 ALuint attrIdx;
826 ALuint i;
828 running = ((device->NumContexts > 0) ? AL_TRUE : AL_FALSE);
829 oldRate = device->Frequency;
831 // Check for attributes
832 if(attrList && attrList[0])
834 // If a context is already running on the device, stop playback so the
835 // device attributes can be updated
836 if(running)
838 ProcessContext(NULL);
839 ALCdevice_StopPlayback(device);
840 SuspendContext(NULL);
841 running = AL_FALSE;
844 freq = device->Frequency;
845 numMono = device->NumMonoSources;
846 numStereo = device->NumStereoSources;
847 numSends = device->NumAuxSends;
849 attrIdx = 0;
850 while(attrList[attrIdx])
852 if(attrList[attrIdx] == ALC_FREQUENCY &&
853 !ConfigValueExists(NULL, "frequency"))
855 freq = attrList[attrIdx + 1];
856 if(freq < 8000)
857 freq = 8000;
860 if(attrList[attrIdx] == ALC_STEREO_SOURCES)
862 numStereo = attrList[attrIdx + 1];
863 if(numStereo > device->MaxNoOfSources)
864 numStereo = device->MaxNoOfSources;
866 numMono = device->MaxNoOfSources - numStereo;
869 if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
870 !ConfigValueExists(NULL, "sends"))
872 numSends = attrList[attrIdx + 1];
873 if(numSends > MAX_SENDS)
874 numSends = MAX_SENDS;
877 attrIdx += 2;
880 device->UpdateSize = (ALuint64)device->UpdateSize * freq /
881 device->Frequency;
883 device->Frequency = freq;
884 device->NumMonoSources = numMono;
885 device->NumStereoSources = numStereo;
886 device->NumAuxSends = numSends;
889 if(running)
890 return ALC_TRUE;
892 if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
893 return ALC_FALSE;
895 aluInitPanning(device);
897 for(i = 0;i < OUTPUTCHANNELS;i++)
899 device->ClickRemoval[i] = 0.0f;
900 device->PendingClicks[i] = 0.0f;
903 for(i = 0;i < device->NumContexts;i++)
905 ALCcontext *context = device->Contexts[i];
906 ALsizei pos;
908 SuspendContext(context);
909 for(pos = 0;pos < context->EffectSlotMap.size;pos++)
911 ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
913 if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
915 ProcessContext(context);
916 return ALC_FALSE;
918 ALEffect_Update(slot->EffectState, context, &slot->effect);
921 for(pos = 0;pos < context->SourceMap.size;pos++)
923 ALsource *source = context->SourceMap.array[pos].value;
924 ALuint s = device->NumAuxSends;
925 while(s < MAX_SENDS)
927 if(source->Send[s].Slot)
928 source->Send[s].Slot->refcount--;
929 source->Send[s].Slot = NULL;
930 source->Send[s].WetFilter.type = 0;
931 source->Send[s].WetFilter.filter = 0;
932 s++;
934 source->NeedsUpdate = AL_TRUE;
936 ProcessContext(context);
939 if(device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
941 if(!device->Bs2b)
943 device->Bs2b = calloc(1, sizeof(*device->Bs2b));
944 bs2b_clear(device->Bs2b);
946 bs2b_set_srate(device->Bs2b, device->Frequency);
947 bs2b_set_level(device->Bs2b, device->Bs2bLevel);
949 else
951 free(device->Bs2b);
952 device->Bs2b = NULL;
955 if(aluChannelsFromFormat(device->Format) <= 2)
957 device->HeadDampen = GetConfigValueFloat(NULL, "head_dampen", DEFAULT_HEAD_DAMPEN);
958 device->HeadDampen = __min(device->HeadDampen, 1.0f);
959 device->HeadDampen = __max(device->HeadDampen, 0.0f);
961 else
962 device->HeadDampen = 0.0f;
964 return ALC_TRUE;
969 SuspendContext
971 Thread-safe entry
973 ALCvoid SuspendContext(ALCcontext *pContext)
975 (void)pContext;
976 EnterCriticalSection(&g_csMutex);
981 ProcessContext
983 Thread-safe exit
985 ALCvoid ProcessContext(ALCcontext *pContext)
987 (void)pContext;
988 LeaveCriticalSection(&g_csMutex);
993 GetContextSuspended
995 Returns the currently active Context, in a locked state
997 ALCcontext *GetContextSuspended(void)
999 ALCcontext *pContext = NULL;
1001 SuspendContext(NULL);
1003 pContext = tls_get(LocalContext);
1004 if(pContext && !IsContext(pContext))
1006 tls_set(LocalContext, NULL);
1007 pContext = NULL;
1009 if(!pContext)
1010 pContext = GlobalContext;
1012 if(pContext)
1013 SuspendContext(pContext);
1015 ProcessContext(NULL);
1017 return pContext;
1022 InitContext
1024 Initialize Context variables
1026 static ALvoid InitContext(ALCcontext *pContext)
1028 //Initialise listener
1029 pContext->Listener.Gain = 1.0f;
1030 pContext->Listener.MetersPerUnit = 1.0f;
1031 pContext->Listener.Position[0] = 0.0f;
1032 pContext->Listener.Position[1] = 0.0f;
1033 pContext->Listener.Position[2] = 0.0f;
1034 pContext->Listener.Velocity[0] = 0.0f;
1035 pContext->Listener.Velocity[1] = 0.0f;
1036 pContext->Listener.Velocity[2] = 0.0f;
1037 pContext->Listener.Forward[0] = 0.0f;
1038 pContext->Listener.Forward[1] = 0.0f;
1039 pContext->Listener.Forward[2] = -1.0f;
1040 pContext->Listener.Up[0] = 0.0f;
1041 pContext->Listener.Up[1] = 1.0f;
1042 pContext->Listener.Up[2] = 0.0f;
1044 //Validate pContext
1045 pContext->LastError = AL_NO_ERROR;
1046 pContext->Suspended = AL_FALSE;
1047 pContext->ActiveSourceCount = 0;
1048 InitUIntMap(&pContext->SourceMap);
1049 InitUIntMap(&pContext->EffectSlotMap);
1051 //Set globals
1052 pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
1053 pContext->SourceDistanceModel = AL_FALSE;
1054 pContext->DopplerFactor = 1.0f;
1055 pContext->DopplerVelocity = 1.0f;
1056 pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
1058 pContext->ExtensionList = alExtList;
1063 ExitContext
1065 Clean up Context, destroy any remaining Sources
1067 static ALCvoid ExitContext(ALCcontext *pContext)
1069 //Invalidate context
1070 pContext->LastError = AL_NO_ERROR;
1073 ///////////////////////////////////////////////////////
1076 ///////////////////////////////////////////////////////
1077 // ALC Functions calls
1080 // This should probably move to another c file but for now ...
1081 ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
1083 ALCboolean DeviceFound = ALC_FALSE;
1084 ALCdevice *device = NULL;
1085 ALCint i;
1087 if(SampleSize <= 0)
1089 alcSetError(NULL, ALC_INVALID_VALUE);
1090 return NULL;
1093 if(deviceName && !deviceName[0])
1094 deviceName = NULL;
1096 device = calloc(1, sizeof(ALCdevice));
1097 if(!device)
1099 alcSetError(NULL, ALC_OUT_OF_MEMORY);
1100 return NULL;
1103 //Validate device
1104 device->Connected = ALC_TRUE;
1105 device->IsCaptureDevice = AL_TRUE;
1107 device->szDeviceName = NULL;
1109 device->Frequency = frequency;
1110 device->Format = format;
1111 device->UpdateSize = SampleSize;
1112 device->NumUpdates = 1;
1114 SuspendContext(NULL);
1115 for(i = 0;BackendList[i].Init;i++)
1117 device->Funcs = &BackendList[i].Funcs;
1118 if(ALCdevice_OpenCapture(device, deviceName))
1120 device->next = g_pDeviceList;
1121 g_pDeviceList = device;
1122 g_ulDeviceCount++;
1124 DeviceFound = ALC_TRUE;
1125 break;
1128 ProcessContext(NULL);
1130 if(!DeviceFound)
1132 alcSetError(NULL, ALC_INVALID_VALUE);
1133 free(device);
1134 device = NULL;
1137 return device;
1140 ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
1142 ALCdevice **list;
1144 if(!IsDevice(pDevice) || !pDevice->IsCaptureDevice)
1146 alcSetError(pDevice, ALC_INVALID_DEVICE);
1147 return ALC_FALSE;
1150 SuspendContext(NULL);
1152 list = &g_pDeviceList;
1153 while(*list != pDevice)
1154 list = &(*list)->next;
1156 *list = (*list)->next;
1157 g_ulDeviceCount--;
1159 ProcessContext(NULL);
1161 ALCdevice_CloseCapture(pDevice);
1163 free(pDevice->szDeviceName);
1164 pDevice->szDeviceName = NULL;
1166 free(pDevice);
1168 return ALC_TRUE;
1171 ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
1173 SuspendContext(NULL);
1174 if(!IsDevice(device) || !device->IsCaptureDevice)
1175 alcSetError(device, ALC_INVALID_DEVICE);
1176 else if(device->Connected)
1177 ALCdevice_StartCapture(device);
1178 ProcessContext(NULL);
1181 ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
1183 SuspendContext(NULL);
1184 if(!IsDevice(device) || !device->IsCaptureDevice)
1185 alcSetError(device, ALC_INVALID_DEVICE);
1186 else
1187 ALCdevice_StopCapture(device);
1188 ProcessContext(NULL);
1191 ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
1193 SuspendContext(NULL);
1194 if(!IsDevice(device) || !device->IsCaptureDevice)
1195 alcSetError(device, ALC_INVALID_DEVICE);
1196 else
1197 ALCdevice_CaptureSamples(device, buffer, samples);
1198 ProcessContext(NULL);
1202 alcGetError
1204 Return last ALC generated error code
1206 ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
1208 ALCenum errorCode;
1210 if(IsDevice(device))
1212 errorCode = device->LastError;
1213 device->LastError = ALC_NO_ERROR;
1215 else
1217 errorCode = g_eLastNullDeviceError;
1218 g_eLastNullDeviceError = ALC_NO_ERROR;
1220 return errorCode;
1225 alcSuspendContext
1227 Not functional
1229 ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *pContext)
1231 SuspendContext(NULL);
1232 if(IsContext(pContext))
1233 pContext->Suspended = AL_TRUE;
1234 ProcessContext(NULL);
1239 alcProcessContext
1241 Not functional
1243 ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *pContext)
1245 SuspendContext(NULL);
1246 if(IsContext(pContext))
1247 pContext->Suspended = AL_FALSE;
1248 ProcessContext(NULL);
1253 alcGetString
1255 Returns information about the Device, and error strings
1257 ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
1259 const ALCchar *value = NULL;
1261 switch (param)
1263 case ALC_NO_ERROR:
1264 value = alcNoError;
1265 break;
1267 case ALC_INVALID_ENUM:
1268 value = alcErrInvalidEnum;
1269 break;
1271 case ALC_INVALID_VALUE:
1272 value = alcErrInvalidValue;
1273 break;
1275 case ALC_INVALID_DEVICE:
1276 value = alcErrInvalidDevice;
1277 break;
1279 case ALC_INVALID_CONTEXT:
1280 value = alcErrInvalidContext;
1281 break;
1283 case ALC_OUT_OF_MEMORY:
1284 value = alcErrOutOfMemory;
1285 break;
1287 case ALC_DEVICE_SPECIFIER:
1288 if(IsDevice(pDevice))
1289 value = pDevice->szDeviceName;
1290 else
1292 ProbeDeviceList();
1293 value = alcDeviceList;
1295 break;
1297 case ALC_ALL_DEVICES_SPECIFIER:
1298 ProbeAllDeviceList();
1299 value = alcAllDeviceList;
1300 break;
1302 case ALC_CAPTURE_DEVICE_SPECIFIER:
1303 if(IsDevice(pDevice))
1304 value = pDevice->szDeviceName;
1305 else
1307 ProbeCaptureDeviceList();
1308 value = alcCaptureDeviceList;
1310 break;
1312 /* Default devices are always first in the list */
1313 case ALC_DEFAULT_DEVICE_SPECIFIER:
1314 if(!alcDeviceList)
1315 ProbeDeviceList();
1317 free(alcDefaultDeviceSpecifier);
1318 alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
1319 if(!alcDefaultDeviceSpecifier)
1320 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1321 value = alcDefaultDeviceSpecifier;
1322 break;
1324 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
1325 if(!alcAllDeviceList)
1326 ProbeAllDeviceList();
1328 free(alcDefaultAllDeviceSpecifier);
1329 alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
1330 alcAllDeviceList : "");
1331 if(!alcDefaultAllDeviceSpecifier)
1332 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1333 value = alcDefaultAllDeviceSpecifier;
1334 break;
1336 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
1337 if(!alcCaptureDeviceList)
1338 ProbeCaptureDeviceList();
1340 free(alcCaptureDefaultDeviceSpecifier);
1341 alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
1342 alcCaptureDeviceList : "");
1343 if(!alcCaptureDefaultDeviceSpecifier)
1344 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1345 value = alcCaptureDefaultDeviceSpecifier;
1346 break;
1348 case ALC_EXTENSIONS:
1349 if(IsDevice(pDevice))
1350 value = alcExtensionList;
1351 else
1352 value = alcNoDeviceExtList;
1353 break;
1355 default:
1356 alcSetError(pDevice, ALC_INVALID_ENUM);
1357 break;
1360 return value;
1365 alcGetIntegerv
1367 Returns information about the Device and the version of Open AL
1369 ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
1371 if(size == 0 || data == NULL)
1373 alcSetError(device, ALC_INVALID_VALUE);
1374 return;
1377 if(IsDevice(device) && device->IsCaptureDevice)
1379 SuspendContext(NULL);
1381 // Capture device
1382 switch (param)
1384 case ALC_CAPTURE_SAMPLES:
1385 *data = ALCdevice_AvailableSamples(device);
1386 break;
1388 case ALC_CONNECTED:
1389 *data = device->Connected;
1390 break;
1392 default:
1393 alcSetError(device, ALC_INVALID_ENUM);
1394 break;
1397 ProcessContext(NULL);
1398 return;
1401 // Playback Device
1402 switch (param)
1404 case ALC_MAJOR_VERSION:
1405 *data = alcMajorVersion;
1406 break;
1408 case ALC_MINOR_VERSION:
1409 *data = alcMinorVersion;
1410 break;
1412 case ALC_EFX_MAJOR_VERSION:
1413 *data = alcEFXMajorVersion;
1414 break;
1416 case ALC_EFX_MINOR_VERSION:
1417 *data = alcEFXMinorVersion;
1418 break;
1420 case ALC_MAX_AUXILIARY_SENDS:
1421 if(!IsDevice(device))
1422 alcSetError(device, ALC_INVALID_DEVICE);
1423 else
1424 *data = device->NumAuxSends;
1425 break;
1427 case ALC_ATTRIBUTES_SIZE:
1428 if(!IsDevice(device))
1429 alcSetError(device, ALC_INVALID_DEVICE);
1430 else
1431 *data = 13;
1432 break;
1434 case ALC_ALL_ATTRIBUTES:
1435 if(!IsDevice(device))
1436 alcSetError(device, ALC_INVALID_DEVICE);
1437 else if (size < 13)
1438 alcSetError(device, ALC_INVALID_VALUE);
1439 else
1441 int i = 0;
1443 SuspendContext(NULL);
1444 data[i++] = ALC_FREQUENCY;
1445 data[i++] = device->Frequency;
1447 data[i++] = ALC_REFRESH;
1448 data[i++] = device->Frequency / device->UpdateSize;
1450 data[i++] = ALC_SYNC;
1451 data[i++] = ALC_FALSE;
1453 data[i++] = ALC_MONO_SOURCES;
1454 data[i++] = device->NumMonoSources;
1456 data[i++] = ALC_STEREO_SOURCES;
1457 data[i++] = device->NumStereoSources;
1459 data[i++] = ALC_MAX_AUXILIARY_SENDS;
1460 data[i++] = device->NumAuxSends;
1462 data[i++] = 0;
1463 ProcessContext(NULL);
1465 break;
1467 case ALC_FREQUENCY:
1468 if(!IsDevice(device))
1469 alcSetError(device, ALC_INVALID_DEVICE);
1470 else
1471 *data = device->Frequency;
1472 break;
1474 case ALC_REFRESH:
1475 if(!IsDevice(device))
1476 alcSetError(device, ALC_INVALID_DEVICE);
1477 else
1478 *data = device->Frequency / device->UpdateSize;
1479 break;
1481 case ALC_SYNC:
1482 if(!IsDevice(device))
1483 alcSetError(device, ALC_INVALID_DEVICE);
1484 else
1485 *data = ALC_FALSE;
1486 break;
1488 case ALC_MONO_SOURCES:
1489 if(!IsDevice(device))
1490 alcSetError(device, ALC_INVALID_DEVICE);
1491 else
1492 *data = device->NumMonoSources;
1493 break;
1495 case ALC_STEREO_SOURCES:
1496 if(!IsDevice(device))
1497 alcSetError(device, ALC_INVALID_DEVICE);
1498 else
1499 *data = device->NumStereoSources;
1500 break;
1502 case ALC_CONNECTED:
1503 if(!IsDevice(device))
1504 alcSetError(device, ALC_INVALID_DEVICE);
1505 else
1506 *data = device->Connected;
1507 break;
1509 default:
1510 alcSetError(device, ALC_INVALID_ENUM);
1511 break;
1517 alcIsExtensionPresent
1519 Determines if there is support for a particular extension
1521 ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
1523 ALCboolean bResult = ALC_FALSE;
1524 const char *ptr;
1525 size_t len;
1527 if(!extName)
1529 alcSetError(device, ALC_INVALID_VALUE);
1530 return ALC_FALSE;
1533 len = strlen(extName);
1534 ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
1535 while(ptr && *ptr)
1537 if(strncasecmp(ptr, extName, len) == 0 &&
1538 (ptr[len] == '\0' || isspace(ptr[len])))
1540 bResult = ALC_TRUE;
1541 break;
1543 if((ptr=strchr(ptr, ' ')) != NULL)
1545 do {
1546 ++ptr;
1547 } while(isspace(*ptr));
1551 return bResult;
1556 alcGetProcAddress
1558 Retrieves the function address for a particular extension function
1560 ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
1562 ALsizei i = 0;
1564 if(!funcName)
1566 alcSetError(device, ALC_INVALID_VALUE);
1567 return NULL;
1570 while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
1571 i++;
1572 return alcFunctions[i].address;
1577 alcGetEnumValue
1579 Get the value for a particular ALC Enumerated Value
1581 ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
1583 ALsizei i = 0;
1585 if(!enumName)
1587 alcSetError(device, ALC_INVALID_VALUE);
1588 return (ALCenum)0;
1591 while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) != 0)
1592 i++;
1593 return enumeration[i].value;
1598 alcCreateContext
1600 Create and attach a Context to a particular Device.
1602 ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
1604 ALCcontext *ALContext;
1605 void *temp;
1607 SuspendContext(NULL);
1609 if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
1611 alcSetError(device, ALC_INVALID_DEVICE);
1612 ProcessContext(NULL);
1613 return NULL;
1616 // Reset Context Last Error code
1617 device->LastError = ALC_NO_ERROR;
1619 if(UpdateDeviceParams(device, attrList) == ALC_FALSE)
1621 alcSetError(device, ALC_INVALID_DEVICE);
1622 aluHandleDisconnect(device);
1623 ProcessContext(NULL);
1624 ALCdevice_StopPlayback(device);
1625 return NULL;
1628 ALContext = NULL;
1629 temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
1630 if(temp)
1632 device->Contexts = temp;
1634 ALContext = calloc(1, sizeof(ALCcontext));
1635 if(ALContext)
1637 ALContext->MaxActiveSources = 256;
1638 ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) *
1639 ALContext->MaxActiveSources);
1642 if(!ALContext || !ALContext->ActiveSources)
1644 free(ALContext);
1645 alcSetError(device, ALC_OUT_OF_MEMORY);
1646 ProcessContext(NULL);
1647 if(device->NumContexts == 0)
1648 ALCdevice_StopPlayback(device);
1649 return NULL;
1652 device->Contexts[device->NumContexts++] = ALContext;
1653 ALContext->Device = device;
1655 InitContext(ALContext);
1657 ALContext->next = g_pContextList;
1658 g_pContextList = ALContext;
1659 g_ulContextCount++;
1661 ProcessContext(NULL);
1663 return ALContext;
1668 alcDestroyContext
1670 Remove a Context
1672 ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
1674 ALCdevice *Device;
1675 ALCcontext **list;
1676 ALuint i;
1678 if(!IsContext(context))
1680 alcSetError(NULL, ALC_INVALID_CONTEXT);
1681 return;
1684 Device = context->Device;
1686 if(Device->NumContexts == 1)
1687 ALCdevice_StopPlayback(Device);
1689 SuspendContext(NULL);
1691 if(context == GlobalContext)
1692 GlobalContext = NULL;
1694 for(i = 0;i < Device->NumContexts;i++)
1696 if(Device->Contexts[i] == context)
1698 Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
1699 Device->NumContexts--;
1700 break;
1704 // Lock context
1705 SuspendContext(context);
1707 if(context->SourceMap.size > 0)
1709 #ifdef _DEBUG
1710 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size);
1711 #endif
1712 ReleaseALSources(context);
1714 ResetUIntMap(&context->SourceMap);
1716 if(context->EffectSlotMap.size > 0)
1718 #ifdef _DEBUG
1719 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size);
1720 #endif
1721 ReleaseALAuxiliaryEffectSlots(context);
1723 ResetUIntMap(&context->EffectSlotMap);
1725 free(context->ActiveSources);
1726 context->ActiveSources = NULL;
1727 context->MaxActiveSources = 0;
1728 context->ActiveSourceCount = 0;
1730 list = &g_pContextList;
1731 while(*list != context)
1732 list = &(*list)->next;
1734 *list = (*list)->next;
1735 g_ulContextCount--;
1737 // Unlock context
1738 ProcessContext(context);
1739 ProcessContext(NULL);
1741 ExitContext(context);
1743 // Free memory (MUST do this after ProcessContext)
1744 memset(context, 0, sizeof(ALCcontext));
1745 free(context);
1750 alcGetCurrentContext
1752 Returns the currently active Context
1754 ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
1756 ALCcontext *pContext;
1758 if((pContext=GetContextSuspended()) != NULL)
1759 ProcessContext(pContext);
1761 return pContext;
1765 alcGetThreadContext
1767 Returns the currently active thread-local Context
1769 ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
1771 ALCcontext *pContext = NULL;
1773 SuspendContext(NULL);
1775 pContext = tls_get(LocalContext);
1776 if(pContext && !IsContext(pContext))
1778 tls_set(LocalContext, NULL);
1779 pContext = NULL;
1782 ProcessContext(NULL);
1784 return pContext;
1789 alcGetContextsDevice
1791 Returns the Device that a particular Context is attached to
1793 ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
1795 ALCdevice *pDevice = NULL;
1797 SuspendContext(NULL);
1798 if(IsContext(pContext))
1799 pDevice = pContext->Device;
1800 else
1801 alcSetError(NULL, ALC_INVALID_CONTEXT);
1802 ProcessContext(NULL);
1804 return pDevice;
1809 alcMakeContextCurrent
1811 Makes the given Context the active Context
1813 ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
1815 ALboolean bReturn = AL_TRUE;
1817 SuspendContext(NULL);
1819 // context must be a valid Context or NULL
1820 if(context == NULL || IsContext(context))
1822 GlobalContext = context;
1823 tls_set(LocalContext, NULL);
1825 else
1827 alcSetError(NULL, ALC_INVALID_CONTEXT);
1828 bReturn = AL_FALSE;
1831 ProcessContext(NULL);
1833 return bReturn;
1837 alcSetThreadContext
1839 Makes the given Context the active Context for the current thread
1841 ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
1843 ALboolean bReturn = AL_TRUE;
1845 SuspendContext(NULL);
1847 // context must be a valid Context or NULL
1848 if(context == NULL || IsContext(context))
1849 tls_set(LocalContext, context);
1850 else
1852 alcSetError(NULL, ALC_INVALID_CONTEXT);
1853 bReturn = AL_FALSE;
1856 ProcessContext(NULL);
1858 return bReturn;
1862 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1863 void SetDefaultChannelOrder(ALCdevice *device)
1865 switch(aluChannelsFromFormat(device->Format))
1867 case 1: device->DevChannels[FRONT_CENTER] = 0; break;
1869 case 2: device->DevChannels[FRONT_LEFT] = 0;
1870 device->DevChannels[FRONT_RIGHT] = 1; break;
1872 case 4: device->DevChannels[FRONT_LEFT] = 0;
1873 device->DevChannels[FRONT_RIGHT] = 1;
1874 device->DevChannels[BACK_LEFT] = 2;
1875 device->DevChannels[BACK_RIGHT] = 3; break;
1877 case 6: device->DevChannels[FRONT_LEFT] = 0;
1878 device->DevChannels[FRONT_RIGHT] = 1;
1879 device->DevChannels[BACK_LEFT] = 2;
1880 device->DevChannels[BACK_RIGHT] = 3;
1881 device->DevChannels[FRONT_CENTER] = 4;
1882 device->DevChannels[LFE] = 5; break;
1884 case 7: device->DevChannels[FRONT_LEFT] = 0;
1885 device->DevChannels[FRONT_RIGHT] = 1;
1886 device->DevChannels[FRONT_CENTER] = 2;
1887 device->DevChannels[LFE] = 3;
1888 device->DevChannels[BACK_CENTER] = 4;
1889 device->DevChannels[SIDE_LEFT] = 5;
1890 device->DevChannels[SIDE_RIGHT] = 6; break;
1892 case 8: device->DevChannels[FRONT_LEFT] = 0;
1893 device->DevChannels[FRONT_RIGHT] = 1;
1894 device->DevChannels[BACK_LEFT] = 2;
1895 device->DevChannels[BACK_RIGHT] = 3;
1896 device->DevChannels[FRONT_CENTER] = 4;
1897 device->DevChannels[LFE] = 5;
1898 device->DevChannels[SIDE_LEFT] = 6;
1899 device->DevChannels[SIDE_RIGHT] = 7; break;
1902 // Sets the default order used by WaveFormatEx
1903 void SetDefaultWFXChannelOrder(ALCdevice *device)
1905 switch(aluChannelsFromFormat(device->Format))
1907 case 1: device->DevChannels[FRONT_CENTER] = 0; break;
1909 case 2: device->DevChannels[FRONT_LEFT] = 0;
1910 device->DevChannels[FRONT_RIGHT] = 1; break;
1912 case 4: device->DevChannels[FRONT_LEFT] = 0;
1913 device->DevChannels[FRONT_RIGHT] = 1;
1914 device->DevChannels[BACK_LEFT] = 2;
1915 device->DevChannels[BACK_RIGHT] = 3; break;
1917 case 6: device->DevChannels[FRONT_LEFT] = 0;
1918 device->DevChannels[FRONT_RIGHT] = 1;
1919 device->DevChannels[FRONT_CENTER] = 2;
1920 device->DevChannels[LFE] = 3;
1921 device->DevChannels[BACK_LEFT] = 4;
1922 device->DevChannels[BACK_RIGHT] = 5; break;
1924 case 7: device->DevChannels[FRONT_LEFT] = 0;
1925 device->DevChannels[FRONT_RIGHT] = 1;
1926 device->DevChannels[FRONT_CENTER] = 2;
1927 device->DevChannels[LFE] = 3;
1928 device->DevChannels[BACK_CENTER] = 4;
1929 device->DevChannels[SIDE_LEFT] = 5;
1930 device->DevChannels[SIDE_RIGHT] = 6; break;
1932 case 8: device->DevChannels[FRONT_LEFT] = 0;
1933 device->DevChannels[FRONT_RIGHT] = 1;
1934 device->DevChannels[FRONT_CENTER] = 2;
1935 device->DevChannels[LFE] = 3;
1936 device->DevChannels[BACK_LEFT] = 4;
1937 device->DevChannels[BACK_RIGHT] = 5;
1938 device->DevChannels[SIDE_LEFT] = 6;
1939 device->DevChannels[SIDE_RIGHT] = 7; break;
1943 static ALenum GetFormatFromString(const char *str)
1945 if(strcasecmp(str, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32;
1946 if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32;
1947 if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32;
1948 if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32;
1949 if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32;
1950 if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32;
1952 if(strcasecmp(str, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16;
1953 if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16;
1954 if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16;
1955 if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16;
1956 if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16;
1957 if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16;
1959 if(strcasecmp(str, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8;
1960 if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8;
1961 if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8;
1962 if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8;
1963 if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8;
1964 if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8;
1966 AL_PRINT("Unknown format: \"%s\"\n", str);
1967 return AL_FORMAT_STEREO16;
1971 alcOpenDevice
1973 Open the Device specified.
1975 ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
1977 ALboolean bDeviceFound = AL_FALSE;
1978 const ALCchar *fmt;
1979 ALCdevice *device;
1980 ALint i;
1982 if(deviceName && !deviceName[0])
1983 deviceName = NULL;
1985 device = calloc(1, sizeof(ALCdevice));
1986 if(!device)
1988 alcSetError(NULL, ALC_OUT_OF_MEMORY);
1989 return NULL;
1992 //Validate device
1993 device->Connected = ALC_TRUE;
1994 device->IsCaptureDevice = AL_FALSE;
1995 device->LastError = ALC_NO_ERROR;
1997 device->Bs2b = NULL;
1998 device->szDeviceName = NULL;
2000 device->Contexts = NULL;
2001 device->NumContexts = 0;
2003 InitUIntMap(&device->BufferMap);
2004 InitUIntMap(&device->EffectMap);
2005 InitUIntMap(&device->FilterMap);
2006 InitUIntMap(&device->DatabufferMap);
2008 //Set output format
2009 device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
2010 if(device->Frequency < 8000)
2011 device->Frequency = 8000;
2013 fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
2014 device->Format = GetFormatFromString(fmt);
2016 device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
2017 if(device->NumUpdates < 2)
2018 device->NumUpdates = 4;
2020 device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024);
2021 if(device->UpdateSize <= 0)
2022 device->UpdateSize = 1024;
2024 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
2025 if((ALint)device->MaxNoOfSources <= 0)
2026 device->MaxNoOfSources = 256;
2028 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
2029 if((ALint)device->AuxiliaryEffectSlotMax <= 0)
2030 device->AuxiliaryEffectSlotMax = 4;
2032 device->NumStereoSources = 1;
2033 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
2035 device->NumAuxSends = GetConfigValueInt(NULL, "sends", 1);
2036 if(device->NumAuxSends > MAX_SENDS)
2037 device->NumAuxSends = MAX_SENDS;
2039 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
2041 device->DuplicateStereo = GetConfigValueBool(NULL, "stereodup", 1);
2043 device->HeadDampen = 0.0f;
2045 // Find a playback device to open
2046 SuspendContext(NULL);
2047 for(i = 0;BackendList[i].Init;i++)
2049 device->Funcs = &BackendList[i].Funcs;
2050 if(ALCdevice_OpenPlayback(device, deviceName))
2052 device->next = g_pDeviceList;
2053 g_pDeviceList = device;
2054 g_ulDeviceCount++;
2056 bDeviceFound = AL_TRUE;
2057 break;
2060 ProcessContext(NULL);
2062 if(!bDeviceFound)
2064 // No suitable output device found
2065 alcSetError(NULL, ALC_INVALID_VALUE);
2066 free(device);
2067 device = NULL;
2070 return device;
2075 alcCloseDevice
2077 Close the specified Device
2079 ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
2081 ALCdevice **list;
2083 if(!IsDevice(pDevice) || pDevice->IsCaptureDevice)
2085 alcSetError(pDevice, ALC_INVALID_DEVICE);
2086 return ALC_FALSE;
2089 SuspendContext(NULL);
2091 list = &g_pDeviceList;
2092 while(*list != pDevice)
2093 list = &(*list)->next;
2095 *list = (*list)->next;
2096 g_ulDeviceCount--;
2098 ProcessContext(NULL);
2100 if(pDevice->NumContexts > 0)
2102 #ifdef _DEBUG
2103 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
2104 #endif
2105 while(pDevice->NumContexts > 0)
2106 alcDestroyContext(pDevice->Contexts[0]);
2108 ALCdevice_ClosePlayback(pDevice);
2110 if(pDevice->BufferMap.size > 0)
2112 #ifdef _DEBUG
2113 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferMap.size);
2114 #endif
2115 ReleaseALBuffers(pDevice);
2117 ResetUIntMap(&pDevice->BufferMap);
2119 if(pDevice->EffectMap.size > 0)
2121 #ifdef _DEBUG
2122 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size);
2123 #endif
2124 ReleaseALEffects(pDevice);
2126 ResetUIntMap(&pDevice->EffectMap);
2128 if(pDevice->FilterMap.size > 0)
2130 #ifdef _DEBUG
2131 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size);
2132 #endif
2133 ReleaseALFilters(pDevice);
2135 ResetUIntMap(&pDevice->FilterMap);
2137 if(pDevice->DatabufferMap.size > 0)
2139 #ifdef _DEBUG
2140 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice->DatabufferMap.size);
2141 #endif
2142 ReleaseALDatabuffers(pDevice);
2144 ResetUIntMap(&pDevice->DatabufferMap);
2146 free(pDevice->Bs2b);
2147 pDevice->Bs2b = NULL;
2149 free(pDevice->szDeviceName);
2150 pDevice->szDeviceName = NULL;
2152 free(pDevice->Contexts);
2153 pDevice->Contexts = NULL;
2155 //Release device structure
2156 memset(pDevice, 0, sizeof(ALCdevice));
2157 free(pDevice);
2159 return ALC_TRUE;
2163 ALCvoid ReleaseALC(ALCvoid)
2165 free(alcDeviceList); alcDeviceList = NULL;
2166 alcDeviceListSize = 0;
2167 free(alcAllDeviceList); alcAllDeviceList = NULL;
2168 alcAllDeviceListSize = 0;
2169 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
2170 alcCaptureDeviceListSize = 0;
2172 free(alcDefaultDeviceSpecifier);
2173 alcDefaultDeviceSpecifier = NULL;
2174 free(alcDefaultAllDeviceSpecifier);
2175 alcDefaultAllDeviceSpecifier = NULL;
2176 free(alcCaptureDefaultDeviceSpecifier);
2177 alcCaptureDefaultDeviceSpecifier = NULL;
2179 #ifdef _DEBUG
2180 if(g_ulDeviceCount > 0)
2181 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
2182 #endif
2184 while(g_pDeviceList)
2186 if(g_pDeviceList->IsCaptureDevice)
2187 alcCaptureCloseDevice(g_pDeviceList);
2188 else
2189 alcCloseDevice(g_pDeviceList);
2193 ///////////////////////////////////////////////////////