Allow accessing the buffer data as multiple data types in the mixer
[openal-soft.git] / Alc / ALc.c
blob31bb801957e61c1379da7f77ce00bd50a605dde9
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, 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 },
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 },
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_EXTX_sample_buffer_object AL_EXT_source_distance_model "
365 "AL_LOKI_quadriphonic AL_SOFT_buffer_sub_data";
367 // Mixing Priority Level
368 static ALint RTPrioLevel;
370 // Resampler Quality
371 resampler_t DefaultResampler;
373 // Output Log File
374 static FILE *LogFile;
376 ///////////////////////////////////////////////////////
379 ///////////////////////////////////////////////////////
380 // ALC Related helper functions
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 #else
404 #ifdef HAVE_GCC_DESTRUCTOR
405 static void alc_init(void) __attribute__((constructor));
406 static void alc_deinit(void) __attribute__((destructor));
407 #endif
408 #endif
410 static void alc_init(void)
412 int i;
413 const char *devs, *str;
415 str = getenv("ALSOFT_LOGFILE");
416 if(str && str[0])
418 LogFile = fopen(str, "w");
419 if(!LogFile)
420 fprintf(stderr, "AL lib: Failed to open log file '%s'\n", str);
422 if(!LogFile)
423 LogFile = stderr;
425 InitializeCriticalSection(&g_csMutex);
426 ALTHUNK_INIT();
427 ReadALConfig();
429 tls_create(&LocalContext);
431 RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0);
433 DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT);
434 if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
435 DefaultResampler = RESAMPLER_DEFAULT;
437 devs = GetConfigValue(NULL, "drivers", "");
438 if(devs[0])
440 int n;
441 size_t len;
442 const char *next = devs;
443 int endlist, delitem;
445 i = 0;
446 do {
447 devs = next;
448 next = strchr(devs, ',');
450 delitem = (devs[0] == '-');
451 if(devs[0] == '-') devs++;
453 if(!devs[0] || devs[0] == ',')
455 endlist = 0;
456 continue;
458 endlist = 1;
460 len = (next ? ((size_t)(next-devs)) : strlen(devs));
461 for(n = i;BackendList[n].Init;n++)
463 if(len == strlen(BackendList[n].name) &&
464 strncmp(BackendList[n].name, devs, len) == 0)
466 if(delitem)
468 do {
469 BackendList[n] = BackendList[n+1];
470 ++n;
471 } while(BackendList[n].Init);
473 else
475 BackendInfo Bkp = BackendList[n];
476 while(n > i)
478 BackendList[n] = BackendList[n-1];
479 --n;
481 BackendList[n] = Bkp;
483 i++;
485 break;
488 } while(next++);
490 if(endlist)
492 BackendList[i].name = NULL;
493 BackendList[i].Init = NULL;
494 BackendList[i].Deinit = NULL;
495 BackendList[i].Probe = NULL;
499 for(i = 0;BackendList[i].Init;i++)
500 BackendList[i].Init(&BackendList[i].Funcs);
502 str = GetConfigValue(NULL, "excludefx", "");
503 if(str[0])
505 const struct {
506 const char *name;
507 int type;
508 } EffectList[] = {
509 { "eaxreverb", EAXREVERB },
510 { "reverb", REVERB },
511 { "echo", ECHO },
512 { "modulator", MODULATOR },
513 { NULL, 0 }
515 int n;
516 size_t len;
517 const char *next = str;
519 do {
520 str = next;
521 next = strchr(str, ',');
523 if(!str[0] || next == str)
524 continue;
526 len = (next ? ((size_t)(next-str)) : strlen(str));
527 for(n = 0;EffectList[n].name;n++)
529 if(len == strlen(EffectList[n].name) &&
530 strncmp(EffectList[n].name, str, len) == 0)
531 DisabledEffects[EffectList[n].type] = AL_TRUE;
533 } while(next++);
537 static void alc_deinit(void)
539 int i;
541 ReleaseALC();
543 for(i = 0;BackendList[i].Deinit;i++)
544 BackendList[i].Deinit();
546 tls_delete(LocalContext);
548 FreeALConfig();
549 ALTHUNK_EXIT();
550 DeleteCriticalSection(&g_csMutex);
552 if(LogFile != stderr)
553 fclose(LogFile);
554 LogFile = NULL;
558 static void ProbeDeviceList()
560 ALint i;
562 free(alcDeviceList); alcDeviceList = NULL;
563 alcDeviceListSize = 0;
565 for(i = 0;BackendList[i].Probe;i++)
566 BackendList[i].Probe(DEVICE_PROBE);
569 static void ProbeAllDeviceList()
571 ALint i;
573 free(alcAllDeviceList); alcAllDeviceList = NULL;
574 alcAllDeviceListSize = 0;
576 for(i = 0;BackendList[i].Probe;i++)
577 BackendList[i].Probe(ALL_DEVICE_PROBE);
580 static void ProbeCaptureDeviceList()
582 ALint i;
584 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
585 alcCaptureDeviceListSize = 0;
587 for(i = 0;BackendList[i].Probe;i++)
588 BackendList[i].Probe(CAPTURE_DEVICE_PROBE);
592 #define DECL_APPEND_LIST_FUNC(type) \
593 void Append##type##List(const ALCchar *name) \
595 size_t len = strlen(name); \
596 void *temp; \
598 if(len == 0) \
599 return; \
601 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
602 if(!temp) \
604 AL_PRINT("Realloc failed to add %s!\n", name); \
605 return; \
607 alc##type##List = temp; \
608 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
609 alc##type##ListSize += len+1; \
610 alc##type##List[alc##type##ListSize] = 0; \
613 DECL_APPEND_LIST_FUNC(Device)
614 DECL_APPEND_LIST_FUNC(AllDevice)
615 DECL_APPEND_LIST_FUNC(CaptureDevice)
618 void al_print(const char *fname, unsigned int line, const char *fmt, ...)
620 const char *fn;
621 char str[256];
622 int i;
624 fn = strrchr(fname, '/');
625 if(!fn) fn = strrchr(fname, '\\');;
626 if(!fn) fn = fname;
627 else fn += 1;
629 i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
630 if(i < (int)sizeof(str) && i > 0)
632 va_list ap;
633 va_start(ap, fmt);
634 vsnprintf(str+i, sizeof(str)-i, fmt, ap);
635 va_end(ap);
637 str[sizeof(str)-1] = 0;
639 fprintf(LogFile, "%s", str);
640 fflush(LogFile);
643 void SetRTPriority(void)
645 ALboolean failed;
647 #ifdef _WIN32
648 if(RTPrioLevel > 0)
649 failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
650 else
651 failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
652 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
653 struct sched_param param;
655 if(RTPrioLevel > 0)
657 /* Use the minimum real-time priority possible for now (on Linux this
658 * should be 1 for SCHED_RR) */
659 param.sched_priority = sched_get_priority_min(SCHED_RR);
660 failed = !!pthread_setschedparam(pthread_self(), SCHED_RR, &param);
662 else
664 param.sched_priority = 0;
665 failed = !!pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);
667 #else
668 /* Real-time priority not available */
669 failed = (RTPrioLevel>0);
670 #endif
671 if(failed)
672 AL_PRINT("Failed to set priority level for thread\n");
676 void InitUIntMap(UIntMap *map)
678 map->array = NULL;
679 map->size = 0;
680 map->maxsize = 0;
683 void ResetUIntMap(UIntMap *map)
685 free(map->array);
686 map->array = NULL;
687 map->size = 0;
688 map->maxsize = 0;
691 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
693 ALsizei pos = 0;
695 if(map->size > 0)
697 ALsizei low = 0;
698 ALsizei high = map->size - 1;
699 while(low < high)
701 ALsizei mid = low + (high-low)/2;
702 if(map->array[mid].key < key)
703 low = mid + 1;
704 else
705 high = mid;
707 if(map->array[low].key < key)
708 low++;
709 pos = low;
712 if(pos == map->size || map->array[pos].key != key)
714 if(map->size == map->maxsize)
716 ALvoid *temp;
717 ALsizei newsize;
719 newsize = (map->maxsize ? (map->maxsize<<1) : 4);
720 if(newsize < map->maxsize)
721 return AL_OUT_OF_MEMORY;
723 temp = realloc(map->array, newsize*sizeof(map->array[0]));
724 if(!temp) return AL_OUT_OF_MEMORY;
725 map->array = temp;
726 map->maxsize = newsize;
729 map->size++;
730 if(pos < map->size-1)
731 memmove(&map->array[pos+1], &map->array[pos],
732 (map->size-1-pos)*sizeof(map->array[0]));
734 map->array[pos].key = key;
735 map->array[pos].value = value;
737 return AL_NO_ERROR;
740 void RemoveUIntMapKey(UIntMap *map, ALuint key)
742 if(map->size > 0)
744 ALsizei low = 0;
745 ALsizei high = map->size - 1;
746 while(low < high)
748 ALsizei mid = low + (high-low)/2;
749 if(map->array[mid].key < key)
750 low = mid + 1;
751 else
752 high = mid;
754 if(map->array[low].key == key)
756 if(low < map->size-1)
757 memmove(&map->array[low], &map->array[low+1],
758 (map->size-1-low)*sizeof(map->array[0]));
759 map->size--;
766 IsDevice
768 Check pDevice is a valid Device pointer
770 static ALCboolean IsDevice(ALCdevice *pDevice)
772 ALCdevice *pTempDevice;
774 SuspendContext(NULL);
776 pTempDevice = g_pDeviceList;
777 while(pTempDevice && pTempDevice != pDevice)
778 pTempDevice = pTempDevice->next;
780 ProcessContext(NULL);
782 return (pTempDevice ? ALC_TRUE : ALC_FALSE);
786 IsContext
788 Check pContext is a valid Context pointer
790 static ALCboolean IsContext(ALCcontext *pContext)
792 ALCcontext *pTempContext;
794 SuspendContext(NULL);
796 pTempContext = g_pContextList;
797 while (pTempContext && pTempContext != pContext)
798 pTempContext = pTempContext->next;
800 ProcessContext(NULL);
802 return (pTempContext ? ALC_TRUE : ALC_FALSE);
807 alcSetError
809 Store latest ALC Error
811 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
813 if(IsDevice(device))
814 device->LastError = errorCode;
815 else
816 g_eLastNullDeviceError = errorCode;
820 /* UpdateDeviceParams:
822 * Updates device parameters according to the attribute list.
824 static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
826 ALCuint freq, numMono, numStereo, numSends;
827 ALboolean running;
828 ALuint oldRate;
829 ALuint attrIdx;
830 ALuint i;
832 running = ((device->NumContexts > 0) ? AL_TRUE : AL_FALSE);
833 oldRate = device->Frequency;
835 // Check for attributes
836 if(attrList && attrList[0])
838 // If a context is already running on the device, stop playback so the
839 // device attributes can be updated
840 if(running)
842 ProcessContext(NULL);
843 ALCdevice_StopPlayback(device);
844 SuspendContext(NULL);
845 running = AL_FALSE;
848 freq = device->Frequency;
849 numMono = device->NumMonoSources;
850 numStereo = device->NumStereoSources;
851 numSends = device->NumAuxSends;
853 attrIdx = 0;
854 while(attrList[attrIdx])
856 if(attrList[attrIdx] == ALC_FREQUENCY &&
857 !ConfigValueExists(NULL, "frequency"))
859 freq = attrList[attrIdx + 1];
860 if(freq < 8000)
861 freq = 8000;
864 if(attrList[attrIdx] == ALC_STEREO_SOURCES)
866 numStereo = attrList[attrIdx + 1];
867 if(numStereo > device->MaxNoOfSources)
868 numStereo = device->MaxNoOfSources;
870 numMono = device->MaxNoOfSources - numStereo;
873 if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
874 !ConfigValueExists(NULL, "sends"))
876 numSends = attrList[attrIdx + 1];
877 if(numSends > MAX_SENDS)
878 numSends = MAX_SENDS;
881 attrIdx += 2;
884 device->UpdateSize = (ALuint64)device->UpdateSize * freq /
885 device->Frequency;
887 device->Frequency = freq;
888 device->NumMonoSources = numMono;
889 device->NumStereoSources = numStereo;
890 device->NumAuxSends = numSends;
893 if(running)
894 return ALC_TRUE;
896 if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
897 return ALC_FALSE;
899 aluInitPanning(device);
901 // Scale the number of samples played according to the new sample rate
902 device->SamplesPlayed *= device->Frequency;
903 device->SamplesPlayed += oldRate-1;
904 device->SamplesPlayed /= oldRate;
906 for(i = 0;i < OUTPUTCHANNELS;i++)
908 device->ClickRemoval[i] = 0.0f;
909 device->PendingClicks[i] = 0.0f;
912 for(i = 0;i < device->NumContexts;i++)
914 ALCcontext *context = device->Contexts[i];
915 ALsizei pos;
917 SuspendContext(context);
918 for(pos = 0;pos < context->EffectSlotMap.size;pos++)
920 ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
922 if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
924 ProcessContext(context);
925 return ALC_FALSE;
927 ALEffect_Update(slot->EffectState, context, &slot->effect);
930 for(pos = 0;pos < context->SourceMap.size;pos++)
932 ALsource *source = context->SourceMap.array[pos].value;
933 ALuint s = device->NumAuxSends;
934 while(s < MAX_SENDS)
936 if(source->Send[s].Slot)
937 source->Send[s].Slot->refcount--;
938 source->Send[s].Slot = NULL;
939 source->Send[s].WetFilter.type = 0;
940 source->Send[s].WetFilter.filter = 0;
941 s++;
943 source->NeedsUpdate = AL_TRUE;
945 ProcessContext(context);
948 if(device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
950 if(!device->Bs2b)
952 device->Bs2b = calloc(1, sizeof(*device->Bs2b));
953 bs2b_clear(device->Bs2b);
955 bs2b_set_srate(device->Bs2b, device->Frequency);
956 bs2b_set_level(device->Bs2b, device->Bs2bLevel);
958 else
960 free(device->Bs2b);
961 device->Bs2b = NULL;
964 if(aluChannelsFromFormat(device->Format) <= 2)
966 device->HeadDampen = GetConfigValueFloat(NULL, "head_dampen", DEFAULT_HEAD_DAMPEN);
967 device->HeadDampen = __min(device->HeadDampen, 1.0f);
968 device->HeadDampen = __max(device->HeadDampen, 0.0f);
970 else
971 device->HeadDampen = 0.0f;
973 return ALC_TRUE;
978 SuspendContext
980 Thread-safe entry
982 ALCvoid SuspendContext(ALCcontext *pContext)
984 (void)pContext;
985 EnterCriticalSection(&g_csMutex);
990 ProcessContext
992 Thread-safe exit
994 ALCvoid ProcessContext(ALCcontext *pContext)
996 (void)pContext;
997 LeaveCriticalSection(&g_csMutex);
1002 GetContextSuspended
1004 Returns the currently active Context, in a locked state
1006 ALCcontext *GetContextSuspended(void)
1008 ALCcontext *pContext = NULL;
1010 SuspendContext(NULL);
1012 pContext = tls_get(LocalContext);
1013 if(pContext && !IsContext(pContext))
1015 tls_set(LocalContext, NULL);
1016 pContext = NULL;
1018 if(!pContext)
1019 pContext = GlobalContext;
1021 if(pContext)
1022 SuspendContext(pContext);
1024 ProcessContext(NULL);
1026 return pContext;
1031 InitContext
1033 Initialize Context variables
1035 static ALvoid InitContext(ALCcontext *pContext)
1037 //Initialise listener
1038 pContext->Listener.Gain = 1.0f;
1039 pContext->Listener.MetersPerUnit = 1.0f;
1040 pContext->Listener.Position[0] = 0.0f;
1041 pContext->Listener.Position[1] = 0.0f;
1042 pContext->Listener.Position[2] = 0.0f;
1043 pContext->Listener.Velocity[0] = 0.0f;
1044 pContext->Listener.Velocity[1] = 0.0f;
1045 pContext->Listener.Velocity[2] = 0.0f;
1046 pContext->Listener.Forward[0] = 0.0f;
1047 pContext->Listener.Forward[1] = 0.0f;
1048 pContext->Listener.Forward[2] = -1.0f;
1049 pContext->Listener.Up[0] = 0.0f;
1050 pContext->Listener.Up[1] = 1.0f;
1051 pContext->Listener.Up[2] = 0.0f;
1053 //Validate pContext
1054 pContext->LastError = AL_NO_ERROR;
1055 pContext->Suspended = AL_FALSE;
1056 pContext->ActiveSourceCount = 0;
1057 InitUIntMap(&pContext->SourceMap);
1058 InitUIntMap(&pContext->EffectSlotMap);
1060 //Set globals
1061 pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
1062 pContext->SourceDistanceModel = AL_FALSE;
1063 pContext->DopplerFactor = 1.0f;
1064 pContext->DopplerVelocity = 1.0f;
1065 pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
1067 pContext->ExtensionList = alExtList;
1072 ExitContext
1074 Clean up Context, destroy any remaining Sources
1076 static ALCvoid ExitContext(ALCcontext *pContext)
1078 //Invalidate context
1079 pContext->LastError = AL_NO_ERROR;
1082 ///////////////////////////////////////////////////////
1085 ///////////////////////////////////////////////////////
1086 // ALC Functions calls
1089 // This should probably move to another c file but for now ...
1090 ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
1092 ALCboolean DeviceFound = ALC_FALSE;
1093 ALCdevice *device = NULL;
1094 ALCint i;
1096 if(SampleSize <= 0)
1098 alcSetError(NULL, ALC_INVALID_VALUE);
1099 return NULL;
1102 if(deviceName && !deviceName[0])
1103 deviceName = NULL;
1105 device = calloc(1, sizeof(ALCdevice));
1106 if(!device)
1108 alcSetError(NULL, ALC_OUT_OF_MEMORY);
1109 return NULL;
1112 //Validate device
1113 device->Connected = ALC_TRUE;
1114 device->IsCaptureDevice = AL_TRUE;
1116 device->szDeviceName = NULL;
1118 device->Frequency = frequency;
1119 device->Format = format;
1120 device->UpdateSize = SampleSize;
1121 device->NumUpdates = 1;
1123 SuspendContext(NULL);
1124 for(i = 0;BackendList[i].Init;i++)
1126 device->Funcs = &BackendList[i].Funcs;
1127 if(ALCdevice_OpenCapture(device, deviceName))
1129 device->next = g_pDeviceList;
1130 g_pDeviceList = device;
1131 g_ulDeviceCount++;
1133 DeviceFound = ALC_TRUE;
1134 break;
1137 ProcessContext(NULL);
1139 if(!DeviceFound)
1141 alcSetError(NULL, ALC_INVALID_VALUE);
1142 free(device);
1143 device = NULL;
1146 return device;
1149 ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
1151 ALCdevice **list;
1153 if(!IsDevice(pDevice) || !pDevice->IsCaptureDevice)
1155 alcSetError(pDevice, ALC_INVALID_DEVICE);
1156 return ALC_FALSE;
1159 SuspendContext(NULL);
1161 list = &g_pDeviceList;
1162 while(*list != pDevice)
1163 list = &(*list)->next;
1165 *list = (*list)->next;
1166 g_ulDeviceCount--;
1168 ProcessContext(NULL);
1170 ALCdevice_CloseCapture(pDevice);
1172 free(pDevice->szDeviceName);
1173 pDevice->szDeviceName = NULL;
1175 free(pDevice);
1177 return ALC_TRUE;
1180 ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
1182 SuspendContext(NULL);
1183 if(!IsDevice(device) || !device->IsCaptureDevice)
1184 alcSetError(device, ALC_INVALID_DEVICE);
1185 else if(device->Connected)
1186 ALCdevice_StartCapture(device);
1187 ProcessContext(NULL);
1190 ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
1192 SuspendContext(NULL);
1193 if(!IsDevice(device) || !device->IsCaptureDevice)
1194 alcSetError(device, ALC_INVALID_DEVICE);
1195 else
1196 ALCdevice_StopCapture(device);
1197 ProcessContext(NULL);
1200 ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
1202 SuspendContext(NULL);
1203 if(!IsDevice(device) || !device->IsCaptureDevice)
1204 alcSetError(device, ALC_INVALID_DEVICE);
1205 else
1206 ALCdevice_CaptureSamples(device, buffer, samples);
1207 ProcessContext(NULL);
1211 alcGetError
1213 Return last ALC generated error code
1215 ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
1217 ALCenum errorCode;
1219 if(IsDevice(device))
1221 errorCode = device->LastError;
1222 device->LastError = ALC_NO_ERROR;
1224 else
1226 errorCode = g_eLastNullDeviceError;
1227 g_eLastNullDeviceError = ALC_NO_ERROR;
1229 return errorCode;
1234 alcSuspendContext
1236 Not functional
1238 ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *pContext)
1240 SuspendContext(NULL);
1241 if(IsContext(pContext))
1242 pContext->Suspended = AL_TRUE;
1243 ProcessContext(NULL);
1248 alcProcessContext
1250 Not functional
1252 ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *pContext)
1254 SuspendContext(NULL);
1255 if(IsContext(pContext))
1256 pContext->Suspended = AL_FALSE;
1257 ProcessContext(NULL);
1262 alcGetString
1264 Returns information about the Device, and error strings
1266 ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
1268 const ALCchar *value = NULL;
1270 switch (param)
1272 case ALC_NO_ERROR:
1273 value = alcNoError;
1274 break;
1276 case ALC_INVALID_ENUM:
1277 value = alcErrInvalidEnum;
1278 break;
1280 case ALC_INVALID_VALUE:
1281 value = alcErrInvalidValue;
1282 break;
1284 case ALC_INVALID_DEVICE:
1285 value = alcErrInvalidDevice;
1286 break;
1288 case ALC_INVALID_CONTEXT:
1289 value = alcErrInvalidContext;
1290 break;
1292 case ALC_OUT_OF_MEMORY:
1293 value = alcErrOutOfMemory;
1294 break;
1296 case ALC_DEVICE_SPECIFIER:
1297 if(IsDevice(pDevice))
1298 value = pDevice->szDeviceName;
1299 else
1301 ProbeDeviceList();
1302 value = alcDeviceList;
1304 break;
1306 case ALC_ALL_DEVICES_SPECIFIER:
1307 ProbeAllDeviceList();
1308 value = alcAllDeviceList;
1309 break;
1311 case ALC_CAPTURE_DEVICE_SPECIFIER:
1312 if(IsDevice(pDevice))
1313 value = pDevice->szDeviceName;
1314 else
1316 ProbeCaptureDeviceList();
1317 value = alcCaptureDeviceList;
1319 break;
1321 /* Default devices are always first in the list */
1322 case ALC_DEFAULT_DEVICE_SPECIFIER:
1323 if(!alcDeviceList)
1324 ProbeDeviceList();
1326 free(alcDefaultDeviceSpecifier);
1327 alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
1328 if(!alcDefaultDeviceSpecifier)
1329 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1330 value = alcDefaultDeviceSpecifier;
1331 break;
1333 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
1334 if(!alcAllDeviceList)
1335 ProbeAllDeviceList();
1337 free(alcDefaultAllDeviceSpecifier);
1338 alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
1339 alcAllDeviceList : "");
1340 if(!alcDefaultAllDeviceSpecifier)
1341 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1342 value = alcDefaultAllDeviceSpecifier;
1343 break;
1345 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
1346 if(!alcCaptureDeviceList)
1347 ProbeCaptureDeviceList();
1349 free(alcCaptureDefaultDeviceSpecifier);
1350 alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
1351 alcCaptureDeviceList : "");
1352 if(!alcCaptureDefaultDeviceSpecifier)
1353 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1354 value = alcCaptureDefaultDeviceSpecifier;
1355 break;
1357 case ALC_EXTENSIONS:
1358 if(IsDevice(pDevice))
1359 value = alcExtensionList;
1360 else
1361 value = alcNoDeviceExtList;
1362 break;
1364 default:
1365 alcSetError(pDevice, ALC_INVALID_ENUM);
1366 break;
1369 return value;
1374 alcGetIntegerv
1376 Returns information about the Device and the version of Open AL
1378 ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
1380 if(size == 0 || data == NULL)
1382 alcSetError(device, ALC_INVALID_VALUE);
1383 return;
1386 if(IsDevice(device) && device->IsCaptureDevice)
1388 SuspendContext(NULL);
1390 // Capture device
1391 switch (param)
1393 case ALC_CAPTURE_SAMPLES:
1394 *data = ALCdevice_AvailableSamples(device);
1395 break;
1397 case ALC_CONNECTED:
1398 *data = device->Connected;
1399 break;
1401 default:
1402 alcSetError(device, ALC_INVALID_ENUM);
1403 break;
1406 ProcessContext(NULL);
1407 return;
1410 // Playback Device
1411 switch (param)
1413 case ALC_MAJOR_VERSION:
1414 *data = alcMajorVersion;
1415 break;
1417 case ALC_MINOR_VERSION:
1418 *data = alcMinorVersion;
1419 break;
1421 case ALC_EFX_MAJOR_VERSION:
1422 *data = alcEFXMajorVersion;
1423 break;
1425 case ALC_EFX_MINOR_VERSION:
1426 *data = alcEFXMinorVersion;
1427 break;
1429 case ALC_MAX_AUXILIARY_SENDS:
1430 if(!IsDevice(device))
1431 alcSetError(device, ALC_INVALID_DEVICE);
1432 else
1433 *data = device->NumAuxSends;
1434 break;
1436 case ALC_ATTRIBUTES_SIZE:
1437 if(!IsDevice(device))
1438 alcSetError(device, ALC_INVALID_DEVICE);
1439 else
1440 *data = 13;
1441 break;
1443 case ALC_ALL_ATTRIBUTES:
1444 if(!IsDevice(device))
1445 alcSetError(device, ALC_INVALID_DEVICE);
1446 else if (size < 13)
1447 alcSetError(device, ALC_INVALID_VALUE);
1448 else
1450 int i = 0;
1452 SuspendContext(NULL);
1453 data[i++] = ALC_FREQUENCY;
1454 data[i++] = device->Frequency;
1456 data[i++] = ALC_REFRESH;
1457 data[i++] = device->Frequency / device->UpdateSize;
1459 data[i++] = ALC_SYNC;
1460 data[i++] = ALC_FALSE;
1462 data[i++] = ALC_MONO_SOURCES;
1463 data[i++] = device->NumMonoSources;
1465 data[i++] = ALC_STEREO_SOURCES;
1466 data[i++] = device->NumStereoSources;
1468 data[i++] = ALC_MAX_AUXILIARY_SENDS;
1469 data[i++] = device->NumAuxSends;
1471 data[i++] = 0;
1472 ProcessContext(NULL);
1474 break;
1476 case ALC_FREQUENCY:
1477 if(!IsDevice(device))
1478 alcSetError(device, ALC_INVALID_DEVICE);
1479 else
1480 *data = device->Frequency;
1481 break;
1483 case ALC_REFRESH:
1484 if(!IsDevice(device))
1485 alcSetError(device, ALC_INVALID_DEVICE);
1486 else
1487 *data = device->Frequency / device->UpdateSize;
1488 break;
1490 case ALC_SYNC:
1491 if(!IsDevice(device))
1492 alcSetError(device, ALC_INVALID_DEVICE);
1493 else
1494 *data = ALC_FALSE;
1495 break;
1497 case ALC_MONO_SOURCES:
1498 if(!IsDevice(device))
1499 alcSetError(device, ALC_INVALID_DEVICE);
1500 else
1501 *data = device->NumMonoSources;
1502 break;
1504 case ALC_STEREO_SOURCES:
1505 if(!IsDevice(device))
1506 alcSetError(device, ALC_INVALID_DEVICE);
1507 else
1508 *data = device->NumStereoSources;
1509 break;
1511 case ALC_CONNECTED:
1512 if(!IsDevice(device))
1513 alcSetError(device, ALC_INVALID_DEVICE);
1514 else
1515 *data = device->Connected;
1516 break;
1518 case ALC_GET_TIME_EXT:
1519 if(!IsDevice(device))
1520 alcSetError(device, ALC_INVALID_DEVICE);
1521 else if(size < 2)
1522 alcSetError(device, ALC_INVALID_VALUE);
1523 else
1525 ALuint64 t = ALCdevice_GetTime(device);
1526 t -= t%device->TimeRes;
1527 data[0] = t&0xffffffff;
1528 data[1] = t>>32;
1530 break;
1532 case ALC_GET_TIME_RES_EXT:
1533 if(!IsDevice(device))
1534 alcSetError(device, ALC_INVALID_DEVICE);
1535 else if(size < 2)
1536 alcSetError(device, ALC_INVALID_VALUE);
1537 else
1539 data[0] = device->TimeRes&0xffffffff;
1540 data[1] = device->TimeRes>>32;
1542 break;
1544 default:
1545 alcSetError(device, ALC_INVALID_ENUM);
1546 break;
1552 alcIsExtensionPresent
1554 Determines if there is support for a particular extension
1556 ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
1558 ALCboolean bResult = ALC_FALSE;
1559 const char *ptr;
1560 size_t len;
1562 if(!extName)
1564 alcSetError(device, ALC_INVALID_VALUE);
1565 return ALC_FALSE;
1568 len = strlen(extName);
1569 ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
1570 while(ptr && *ptr)
1572 if(strncasecmp(ptr, extName, len) == 0 &&
1573 (ptr[len] == '\0' || isspace(ptr[len])))
1575 bResult = ALC_TRUE;
1576 break;
1578 if((ptr=strchr(ptr, ' ')) != NULL)
1580 do {
1581 ++ptr;
1582 } while(isspace(*ptr));
1586 return bResult;
1591 alcGetProcAddress
1593 Retrieves the function address for a particular extension function
1595 ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
1597 ALsizei i = 0;
1599 if(!funcName)
1601 alcSetError(device, ALC_INVALID_VALUE);
1602 return NULL;
1605 while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
1606 i++;
1607 return alcFunctions[i].address;
1612 alcGetEnumValue
1614 Get the value for a particular ALC Enumerated Value
1616 ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
1618 ALsizei i = 0;
1620 if(!enumName)
1622 alcSetError(device, ALC_INVALID_VALUE);
1623 return (ALCenum)0;
1626 while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) != 0)
1627 i++;
1628 return enumeration[i].value;
1633 alcCreateContext
1635 Create and attach a Context to a particular Device.
1637 ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
1639 ALCcontext *ALContext;
1640 void *temp;
1642 SuspendContext(NULL);
1644 if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
1646 alcSetError(device, ALC_INVALID_DEVICE);
1647 ProcessContext(NULL);
1648 return NULL;
1651 // Reset Context Last Error code
1652 device->LastError = ALC_NO_ERROR;
1654 if(UpdateDeviceParams(device, attrList) == ALC_FALSE)
1656 alcSetError(device, ALC_INVALID_DEVICE);
1657 aluHandleDisconnect(device);
1658 ProcessContext(NULL);
1659 ALCdevice_StopPlayback(device);
1660 return NULL;
1663 ALContext = NULL;
1664 temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
1665 if(temp)
1667 device->Contexts = temp;
1669 ALContext = calloc(1, sizeof(ALCcontext));
1670 if(ALContext)
1672 ALContext->MaxActiveSources = 256;
1673 ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) *
1674 ALContext->MaxActiveSources);
1677 if(!ALContext || !ALContext->ActiveSources)
1679 free(ALContext);
1680 alcSetError(device, ALC_OUT_OF_MEMORY);
1681 ProcessContext(NULL);
1682 if(device->NumContexts == 0)
1683 ALCdevice_StopPlayback(device);
1684 return NULL;
1687 device->Contexts[device->NumContexts++] = ALContext;
1688 ALContext->Device = device;
1690 InitContext(ALContext);
1692 ALContext->next = g_pContextList;
1693 g_pContextList = ALContext;
1694 g_ulContextCount++;
1696 ProcessContext(NULL);
1698 return ALContext;
1703 alcDestroyContext
1705 Remove a Context
1707 ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
1709 ALCdevice *Device;
1710 ALCcontext **list;
1711 ALuint i;
1713 if(!IsContext(context))
1715 alcSetError(NULL, ALC_INVALID_CONTEXT);
1716 return;
1719 Device = context->Device;
1721 if(Device->NumContexts == 1)
1722 ALCdevice_StopPlayback(Device);
1724 SuspendContext(NULL);
1726 if(context == GlobalContext)
1727 GlobalContext = NULL;
1729 for(i = 0;i < Device->NumContexts;i++)
1731 if(Device->Contexts[i] == context)
1733 Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
1734 Device->NumContexts--;
1735 break;
1739 // Lock context
1740 SuspendContext(context);
1742 if(context->SourceMap.size > 0)
1744 #ifdef _DEBUG
1745 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size);
1746 #endif
1747 ReleaseALSources(context);
1749 ResetUIntMap(&context->SourceMap);
1751 if(context->EffectSlotMap.size > 0)
1753 #ifdef _DEBUG
1754 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size);
1755 #endif
1756 ReleaseALAuxiliaryEffectSlots(context);
1758 ResetUIntMap(&context->EffectSlotMap);
1760 free(context->ActiveSources);
1761 context->ActiveSources = NULL;
1762 context->MaxActiveSources = 0;
1763 context->ActiveSourceCount = 0;
1765 list = &g_pContextList;
1766 while(*list != context)
1767 list = &(*list)->next;
1769 *list = (*list)->next;
1770 g_ulContextCount--;
1772 // Unlock context
1773 ProcessContext(context);
1774 ProcessContext(NULL);
1776 ExitContext(context);
1778 // Free memory (MUST do this after ProcessContext)
1779 memset(context, 0, sizeof(ALCcontext));
1780 free(context);
1785 alcGetCurrentContext
1787 Returns the currently active Context
1789 ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
1791 ALCcontext *pContext;
1793 if((pContext=GetContextSuspended()) != NULL)
1794 ProcessContext(pContext);
1796 return pContext;
1800 alcGetThreadContext
1802 Returns the currently active thread-local Context
1804 ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
1806 ALCcontext *pContext = NULL;
1808 SuspendContext(NULL);
1810 pContext = tls_get(LocalContext);
1811 if(pContext && !IsContext(pContext))
1813 tls_set(LocalContext, NULL);
1814 pContext = NULL;
1817 ProcessContext(NULL);
1819 return pContext;
1824 alcGetContextsDevice
1826 Returns the Device that a particular Context is attached to
1828 ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
1830 ALCdevice *pDevice = NULL;
1832 SuspendContext(NULL);
1833 if(IsContext(pContext))
1834 pDevice = pContext->Device;
1835 else
1836 alcSetError(NULL, ALC_INVALID_CONTEXT);
1837 ProcessContext(NULL);
1839 return pDevice;
1844 alcMakeContextCurrent
1846 Makes the given Context the active Context
1848 ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
1850 ALboolean bReturn = AL_TRUE;
1852 SuspendContext(NULL);
1854 // context must be a valid Context or NULL
1855 if(context == NULL || IsContext(context))
1857 GlobalContext = context;
1858 tls_set(LocalContext, NULL);
1860 else
1862 alcSetError(NULL, ALC_INVALID_CONTEXT);
1863 bReturn = AL_FALSE;
1866 ProcessContext(NULL);
1868 return bReturn;
1872 alcSetThreadContext
1874 Makes the given Context the active Context for the current thread
1876 ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
1878 ALboolean bReturn = AL_TRUE;
1880 SuspendContext(NULL);
1882 // context must be a valid Context or NULL
1883 if(context == NULL || IsContext(context))
1884 tls_set(LocalContext, context);
1885 else
1887 alcSetError(NULL, ALC_INVALID_CONTEXT);
1888 bReturn = AL_FALSE;
1891 ProcessContext(NULL);
1893 return bReturn;
1897 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1898 void SetDefaultChannelOrder(ALCdevice *device)
1900 switch(aluChannelsFromFormat(device->Format))
1902 case 1: device->DevChannels[FRONT_CENTER] = 0; break;
1904 case 2: device->DevChannels[FRONT_LEFT] = 0;
1905 device->DevChannels[FRONT_RIGHT] = 1; break;
1907 case 4: device->DevChannels[FRONT_LEFT] = 0;
1908 device->DevChannels[FRONT_RIGHT] = 1;
1909 device->DevChannels[BACK_LEFT] = 2;
1910 device->DevChannels[BACK_RIGHT] = 3; break;
1912 case 6: device->DevChannels[FRONT_LEFT] = 0;
1913 device->DevChannels[FRONT_RIGHT] = 1;
1914 device->DevChannels[BACK_LEFT] = 2;
1915 device->DevChannels[BACK_RIGHT] = 3;
1916 device->DevChannels[FRONT_CENTER] = 4;
1917 device->DevChannels[LFE] = 5; break;
1919 case 7: device->DevChannels[FRONT_LEFT] = 0;
1920 device->DevChannels[FRONT_RIGHT] = 1;
1921 device->DevChannels[FRONT_CENTER] = 2;
1922 device->DevChannels[LFE] = 3;
1923 device->DevChannels[BACK_CENTER] = 4;
1924 device->DevChannels[SIDE_LEFT] = 5;
1925 device->DevChannels[SIDE_RIGHT] = 6; break;
1927 case 8: device->DevChannels[FRONT_LEFT] = 0;
1928 device->DevChannels[FRONT_RIGHT] = 1;
1929 device->DevChannels[BACK_LEFT] = 2;
1930 device->DevChannels[BACK_RIGHT] = 3;
1931 device->DevChannels[FRONT_CENTER] = 4;
1932 device->DevChannels[LFE] = 5;
1933 device->DevChannels[SIDE_LEFT] = 6;
1934 device->DevChannels[SIDE_RIGHT] = 7; break;
1937 // Sets the default order used by WaveFormatEx
1938 void SetDefaultWFXChannelOrder(ALCdevice *device)
1940 switch(aluChannelsFromFormat(device->Format))
1942 case 1: device->DevChannels[FRONT_CENTER] = 0; break;
1944 case 2: device->DevChannels[FRONT_LEFT] = 0;
1945 device->DevChannels[FRONT_RIGHT] = 1; break;
1947 case 4: device->DevChannels[FRONT_LEFT] = 0;
1948 device->DevChannels[FRONT_RIGHT] = 1;
1949 device->DevChannels[BACK_LEFT] = 2;
1950 device->DevChannels[BACK_RIGHT] = 3; break;
1952 case 6: device->DevChannels[FRONT_LEFT] = 0;
1953 device->DevChannels[FRONT_RIGHT] = 1;
1954 device->DevChannels[FRONT_CENTER] = 2;
1955 device->DevChannels[LFE] = 3;
1956 device->DevChannels[BACK_LEFT] = 4;
1957 device->DevChannels[BACK_RIGHT] = 5; break;
1959 case 7: device->DevChannels[FRONT_LEFT] = 0;
1960 device->DevChannels[FRONT_RIGHT] = 1;
1961 device->DevChannels[FRONT_CENTER] = 2;
1962 device->DevChannels[LFE] = 3;
1963 device->DevChannels[BACK_CENTER] = 4;
1964 device->DevChannels[SIDE_LEFT] = 5;
1965 device->DevChannels[SIDE_RIGHT] = 6; break;
1967 case 8: device->DevChannels[FRONT_LEFT] = 0;
1968 device->DevChannels[FRONT_RIGHT] = 1;
1969 device->DevChannels[FRONT_CENTER] = 2;
1970 device->DevChannels[LFE] = 3;
1971 device->DevChannels[BACK_LEFT] = 4;
1972 device->DevChannels[BACK_RIGHT] = 5;
1973 device->DevChannels[SIDE_LEFT] = 6;
1974 device->DevChannels[SIDE_RIGHT] = 7; break;
1978 static ALenum GetFormatFromString(const char *str)
1980 if(strcasecmp(str, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32;
1981 if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32;
1982 if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32;
1983 if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32;
1984 if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32;
1985 if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32;
1987 if(strcasecmp(str, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16;
1988 if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16;
1989 if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16;
1990 if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16;
1991 if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16;
1992 if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16;
1994 if(strcasecmp(str, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8;
1995 if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8;
1996 if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8;
1997 if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8;
1998 if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8;
1999 if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8;
2001 AL_PRINT("Unknown format: \"%s\"\n", str);
2002 return AL_FORMAT_STEREO16;
2006 alcOpenDevice
2008 Open the Device specified.
2010 ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
2012 ALboolean bDeviceFound = AL_FALSE;
2013 const ALCchar *fmt;
2014 ALCdevice *device;
2015 ALint i;
2017 if(deviceName && !deviceName[0])
2018 deviceName = NULL;
2020 device = calloc(1, sizeof(ALCdevice));
2021 if(!device)
2023 alcSetError(NULL, ALC_OUT_OF_MEMORY);
2024 return NULL;
2027 //Validate device
2028 device->Connected = ALC_TRUE;
2029 device->IsCaptureDevice = AL_FALSE;
2030 device->LastError = ALC_NO_ERROR;
2032 device->Bs2b = NULL;
2033 device->szDeviceName = NULL;
2035 device->Contexts = NULL;
2036 device->NumContexts = 0;
2038 device->SamplesPlayed = 0;
2040 device->TimeRes = 1;
2042 InitUIntMap(&device->BufferMap);
2043 InitUIntMap(&device->EffectMap);
2044 InitUIntMap(&device->FilterMap);
2045 InitUIntMap(&device->DatabufferMap);
2047 //Set output format
2048 device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
2049 if(device->Frequency < 8000)
2050 device->Frequency = 8000;
2052 fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
2053 device->Format = GetFormatFromString(fmt);
2055 device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
2056 if(device->NumUpdates < 2)
2057 device->NumUpdates = 4;
2059 device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024);
2060 if(device->UpdateSize <= 0)
2061 device->UpdateSize = 1024;
2063 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
2064 if((ALint)device->MaxNoOfSources <= 0)
2065 device->MaxNoOfSources = 256;
2067 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
2068 if((ALint)device->AuxiliaryEffectSlotMax <= 0)
2069 device->AuxiliaryEffectSlotMax = 4;
2071 device->NumStereoSources = 1;
2072 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
2074 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
2075 if(device->NumAuxSends > MAX_SENDS)
2076 device->NumAuxSends = MAX_SENDS;
2078 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
2080 device->DuplicateStereo = GetConfigValueBool(NULL, "stereodup", 1);
2082 device->HeadDampen = 0.0f;
2084 // Find a playback device to open
2085 SuspendContext(NULL);
2086 for(i = 0;BackendList[i].Init;i++)
2088 device->Funcs = &BackendList[i].Funcs;
2089 if(ALCdevice_OpenPlayback(device, deviceName))
2091 device->next = g_pDeviceList;
2092 g_pDeviceList = device;
2093 g_ulDeviceCount++;
2095 bDeviceFound = AL_TRUE;
2096 break;
2099 ProcessContext(NULL);
2101 if(!bDeviceFound)
2103 // No suitable output device found
2104 alcSetError(NULL, ALC_INVALID_VALUE);
2105 free(device);
2106 device = NULL;
2109 return device;
2114 alcCloseDevice
2116 Close the specified Device
2118 ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
2120 ALCdevice **list;
2122 if(!IsDevice(pDevice) || pDevice->IsCaptureDevice)
2124 alcSetError(pDevice, ALC_INVALID_DEVICE);
2125 return ALC_FALSE;
2128 SuspendContext(NULL);
2130 list = &g_pDeviceList;
2131 while(*list != pDevice)
2132 list = &(*list)->next;
2134 *list = (*list)->next;
2135 g_ulDeviceCount--;
2137 ProcessContext(NULL);
2139 if(pDevice->NumContexts > 0)
2141 #ifdef _DEBUG
2142 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
2143 #endif
2144 while(pDevice->NumContexts > 0)
2145 alcDestroyContext(pDevice->Contexts[0]);
2147 ALCdevice_ClosePlayback(pDevice);
2149 if(pDevice->BufferMap.size > 0)
2151 #ifdef _DEBUG
2152 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferMap.size);
2153 #endif
2154 ReleaseALBuffers(pDevice);
2156 ResetUIntMap(&pDevice->BufferMap);
2158 if(pDevice->EffectMap.size > 0)
2160 #ifdef _DEBUG
2161 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size);
2162 #endif
2163 ReleaseALEffects(pDevice);
2165 ResetUIntMap(&pDevice->EffectMap);
2167 if(pDevice->FilterMap.size > 0)
2169 #ifdef _DEBUG
2170 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size);
2171 #endif
2172 ReleaseALFilters(pDevice);
2174 ResetUIntMap(&pDevice->FilterMap);
2176 if(pDevice->DatabufferMap.size > 0)
2178 #ifdef _DEBUG
2179 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice->DatabufferMap.size);
2180 #endif
2181 ReleaseALDatabuffers(pDevice);
2183 ResetUIntMap(&pDevice->DatabufferMap);
2185 free(pDevice->Bs2b);
2186 pDevice->Bs2b = NULL;
2188 free(pDevice->szDeviceName);
2189 pDevice->szDeviceName = NULL;
2191 free(pDevice->Contexts);
2192 pDevice->Contexts = NULL;
2194 //Release device structure
2195 memset(pDevice, 0, sizeof(ALCdevice));
2196 free(pDevice);
2198 return ALC_TRUE;
2202 ALCvoid ReleaseALC(ALCvoid)
2204 free(alcDeviceList); alcDeviceList = NULL;
2205 alcDeviceListSize = 0;
2206 free(alcAllDeviceList); alcAllDeviceList = NULL;
2207 alcAllDeviceListSize = 0;
2208 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
2209 alcCaptureDeviceListSize = 0;
2211 free(alcDefaultDeviceSpecifier);
2212 alcDefaultDeviceSpecifier = NULL;
2213 free(alcDefaultAllDeviceSpecifier);
2214 alcDefaultAllDeviceSpecifier = NULL;
2215 free(alcCaptureDefaultDeviceSpecifier);
2216 alcCaptureDefaultDeviceSpecifier = NULL;
2218 #ifdef _DEBUG
2219 if(g_ulDeviceCount > 0)
2220 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
2221 #endif
2223 while(g_pDeviceList)
2225 if(g_pDeviceList->IsCaptureDevice)
2226 alcCaptureCloseDevice(g_pDeviceList);
2227 else
2228 alcCloseDevice(g_pDeviceList);
2232 ///////////////////////////////////////////////////////