Add an option to emulate EAX reverb using standard reverb
[openal-soft/android.git] / Alc / ALc.c
blob905fee2280f41a4ac8069fd18d141c3bee363826
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 #if defined(HAVE_GUIDDEF_H) || defined(HAVE_INITGUID_H)
24 #define INITGUID
25 #include <windows.h>
26 #ifdef HAVE_GUIDDEF_H
27 #include <guiddef.h>
28 #else
29 #include <initguid.h>
30 #endif
32 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
33 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
35 DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xbcde0395, 0xe52f, 0x467c, 0x8e,0x3d, 0xc4,0x57,0x92,0x91,0x69,0x2e);
36 DEFINE_GUID(IID_IMMDeviceEnumerator, 0xa95664d2, 0x9614, 0x4f35, 0xa7,0x46, 0xde,0x8d,0xb6,0x36,0x17,0xe6);
37 DEFINE_GUID(IID_IAudioClient, 0x1cb9ad4c, 0xdbfa, 0x4c32, 0xb1,0x78, 0xc2,0xf5,0x68,0xa7,0x03,0xb2);
38 DEFINE_GUID(IID_IAudioRenderClient, 0xf294acfc, 0x3146, 0x4483, 0xa7,0xbf, 0xad,0xdc,0xa7,0xc2,0x60,0xe2);
40 #endif
42 #include <math.h>
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <memory.h>
46 #include <ctype.h>
47 #ifdef HAVE_DLFCN_H
48 #include <dlfcn.h>
49 #endif
51 #include "alMain.h"
52 #include "alSource.h"
53 #include "AL/al.h"
54 #include "AL/alc.h"
55 #include "alThunk.h"
56 #include "alSource.h"
57 #include "alBuffer.h"
58 #include "alAuxEffectSlot.h"
59 #include "bs2b.h"
60 #include "alu.h"
63 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
64 typedef struct BackendInfo {
65 const char *name;
66 void (*Init)(BackendFuncs*);
67 void (*Deinit)(void);
68 void (*Probe)(enum DevProbe);
69 BackendFuncs Funcs;
70 } BackendInfo;
71 static BackendInfo BackendList[] = {
72 #ifdef HAVE_PULSEAUDIO
73 { "pulse", alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs },
74 #endif
75 #ifdef HAVE_ALSA
76 { "alsa", alc_alsa_init, alc_alsa_deinit, alc_alsa_probe, EmptyFuncs },
77 #endif
78 #ifdef HAVE_COREAUDIO
79 { "core", alc_ca_init, alc_ca_deinit, alc_ca_probe, EmptyFuncs },
80 #endif
81 #ifdef HAVE_OSS
82 { "oss", alc_oss_init, alc_oss_deinit, alc_oss_probe, EmptyFuncs },
83 #endif
84 #ifdef HAVE_SOLARIS
85 { "solaris", alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs },
86 #endif
87 #ifdef HAVE_SNDIO
88 { "sndio", alc_sndio_init, alc_sndio_deinit, alc_sndio_probe, EmptyFuncs },
89 #endif
90 #ifdef HAVE_MMDEVAPI
91 { "mmdevapi", alcMMDevApiInit, alcMMDevApiDeinit, alcMMDevApiProbe, EmptyFuncs },
92 #endif
93 #ifdef HAVE_DSOUND
94 { "dsound", alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs },
95 #endif
96 #ifdef HAVE_WINMM
97 { "winmm", alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs },
98 #endif
99 #ifdef HAVE_PORTAUDIO
100 { "port", alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs },
101 #endif
102 #ifdef HAVE_OPENSL
103 { "opensl", alc_opensl_init, alc_opensl_deinit, alc_opensl_probe, EmptyFuncs },
104 #endif
106 { "null", alc_null_init, alc_null_deinit, alc_null_probe, EmptyFuncs },
107 #ifdef HAVE_WAVE
108 { "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs },
109 #endif
111 { NULL, NULL, NULL, NULL, EmptyFuncs }
113 static BackendInfo BackendLoopback = {
114 "loopback", alc_loopback_init, alc_loopback_deinit, alc_loopback_probe, EmptyFuncs
116 #undef EmptyFuncs
118 ///////////////////////////////////////////////////////
119 // STRING and EXTENSIONS
121 typedef struct ALCfunction {
122 const ALCchar *funcName;
123 ALCvoid *address;
124 } ALCfunction;
126 typedef struct ALCenums {
127 const ALCchar *enumName;
128 ALCenum value;
129 } ALCenums;
132 static const ALCfunction alcFunctions[] = {
133 { "alcCreateContext", (ALCvoid *) alcCreateContext },
134 { "alcMakeContextCurrent", (ALCvoid *) alcMakeContextCurrent },
135 { "alcProcessContext", (ALCvoid *) alcProcessContext },
136 { "alcSuspendContext", (ALCvoid *) alcSuspendContext },
137 { "alcDestroyContext", (ALCvoid *) alcDestroyContext },
138 { "alcGetCurrentContext", (ALCvoid *) alcGetCurrentContext },
139 { "alcGetContextsDevice", (ALCvoid *) alcGetContextsDevice },
140 { "alcOpenDevice", (ALCvoid *) alcOpenDevice },
141 { "alcCloseDevice", (ALCvoid *) alcCloseDevice },
142 { "alcGetError", (ALCvoid *) alcGetError },
143 { "alcIsExtensionPresent", (ALCvoid *) alcIsExtensionPresent },
144 { "alcGetProcAddress", (ALCvoid *) alcGetProcAddress },
145 { "alcGetEnumValue", (ALCvoid *) alcGetEnumValue },
146 { "alcGetString", (ALCvoid *) alcGetString },
147 { "alcGetIntegerv", (ALCvoid *) alcGetIntegerv },
148 { "alcCaptureOpenDevice", (ALCvoid *) alcCaptureOpenDevice },
149 { "alcCaptureCloseDevice", (ALCvoid *) alcCaptureCloseDevice },
150 { "alcCaptureStart", (ALCvoid *) alcCaptureStart },
151 { "alcCaptureStop", (ALCvoid *) alcCaptureStop },
152 { "alcCaptureSamples", (ALCvoid *) alcCaptureSamples },
154 { "alcSetThreadContext", (ALCvoid *) alcSetThreadContext },
155 { "alcGetThreadContext", (ALCvoid *) alcGetThreadContext },
157 { "alcLoopbackOpenDeviceSOFT", (ALCvoid *) alcLoopbackOpenDeviceSOFT},
158 { "alcIsRenderFormatSupportedSOFT",(ALCvoid *) alcIsRenderFormatSupportedSOFT},
159 { "alcRenderSamplesSOFT", (ALCvoid *) alcRenderSamplesSOFT },
161 { "alEnable", (ALCvoid *) alEnable },
162 { "alDisable", (ALCvoid *) alDisable },
163 { "alIsEnabled", (ALCvoid *) alIsEnabled },
164 { "alGetString", (ALCvoid *) alGetString },
165 { "alGetBooleanv", (ALCvoid *) alGetBooleanv },
166 { "alGetIntegerv", (ALCvoid *) alGetIntegerv },
167 { "alGetFloatv", (ALCvoid *) alGetFloatv },
168 { "alGetDoublev", (ALCvoid *) alGetDoublev },
169 { "alGetBoolean", (ALCvoid *) alGetBoolean },
170 { "alGetInteger", (ALCvoid *) alGetInteger },
171 { "alGetFloat", (ALCvoid *) alGetFloat },
172 { "alGetDouble", (ALCvoid *) alGetDouble },
173 { "alGetError", (ALCvoid *) alGetError },
174 { "alIsExtensionPresent", (ALCvoid *) alIsExtensionPresent },
175 { "alGetProcAddress", (ALCvoid *) alGetProcAddress },
176 { "alGetEnumValue", (ALCvoid *) alGetEnumValue },
177 { "alListenerf", (ALCvoid *) alListenerf },
178 { "alListener3f", (ALCvoid *) alListener3f },
179 { "alListenerfv", (ALCvoid *) alListenerfv },
180 { "alListeneri", (ALCvoid *) alListeneri },
181 { "alListener3i", (ALCvoid *) alListener3i },
182 { "alListeneriv", (ALCvoid *) alListeneriv },
183 { "alGetListenerf", (ALCvoid *) alGetListenerf },
184 { "alGetListener3f", (ALCvoid *) alGetListener3f },
185 { "alGetListenerfv", (ALCvoid *) alGetListenerfv },
186 { "alGetListeneri", (ALCvoid *) alGetListeneri },
187 { "alGetListener3i", (ALCvoid *) alGetListener3i },
188 { "alGetListeneriv", (ALCvoid *) alGetListeneriv },
189 { "alGenSources", (ALCvoid *) alGenSources },
190 { "alDeleteSources", (ALCvoid *) alDeleteSources },
191 { "alIsSource", (ALCvoid *) alIsSource },
192 { "alSourcef", (ALCvoid *) alSourcef },
193 { "alSource3f", (ALCvoid *) alSource3f },
194 { "alSourcefv", (ALCvoid *) alSourcefv },
195 { "alSourcei", (ALCvoid *) alSourcei },
196 { "alSource3i", (ALCvoid *) alSource3i },
197 { "alSourceiv", (ALCvoid *) alSourceiv },
198 { "alGetSourcef", (ALCvoid *) alGetSourcef },
199 { "alGetSource3f", (ALCvoid *) alGetSource3f },
200 { "alGetSourcefv", (ALCvoid *) alGetSourcefv },
201 { "alGetSourcei", (ALCvoid *) alGetSourcei },
202 { "alGetSource3i", (ALCvoid *) alGetSource3i },
203 { "alGetSourceiv", (ALCvoid *) alGetSourceiv },
204 { "alSourcePlayv", (ALCvoid *) alSourcePlayv },
205 { "alSourceStopv", (ALCvoid *) alSourceStopv },
206 { "alSourceRewindv", (ALCvoid *) alSourceRewindv },
207 { "alSourcePausev", (ALCvoid *) alSourcePausev },
208 { "alSourcePlay", (ALCvoid *) alSourcePlay },
209 { "alSourceStop", (ALCvoid *) alSourceStop },
210 { "alSourceRewind", (ALCvoid *) alSourceRewind },
211 { "alSourcePause", (ALCvoid *) alSourcePause },
212 { "alSourceQueueBuffers", (ALCvoid *) alSourceQueueBuffers },
213 { "alSourceUnqueueBuffers", (ALCvoid *) alSourceUnqueueBuffers },
214 { "alGenBuffers", (ALCvoid *) alGenBuffers },
215 { "alDeleteBuffers", (ALCvoid *) alDeleteBuffers },
216 { "alIsBuffer", (ALCvoid *) alIsBuffer },
217 { "alBufferData", (ALCvoid *) alBufferData },
218 { "alBufferf", (ALCvoid *) alBufferf },
219 { "alBuffer3f", (ALCvoid *) alBuffer3f },
220 { "alBufferfv", (ALCvoid *) alBufferfv },
221 { "alBufferi", (ALCvoid *) alBufferi },
222 { "alBuffer3i", (ALCvoid *) alBuffer3i },
223 { "alBufferiv", (ALCvoid *) alBufferiv },
224 { "alGetBufferf", (ALCvoid *) alGetBufferf },
225 { "alGetBuffer3f", (ALCvoid *) alGetBuffer3f },
226 { "alGetBufferfv", (ALCvoid *) alGetBufferfv },
227 { "alGetBufferi", (ALCvoid *) alGetBufferi },
228 { "alGetBuffer3i", (ALCvoid *) alGetBuffer3i },
229 { "alGetBufferiv", (ALCvoid *) alGetBufferiv },
230 { "alDopplerFactor", (ALCvoid *) alDopplerFactor },
231 { "alDopplerVelocity", (ALCvoid *) alDopplerVelocity },
232 { "alSpeedOfSound", (ALCvoid *) alSpeedOfSound },
233 { "alDistanceModel", (ALCvoid *) alDistanceModel },
235 { "alGenFilters", (ALCvoid *) alGenFilters },
236 { "alDeleteFilters", (ALCvoid *) alDeleteFilters },
237 { "alIsFilter", (ALCvoid *) alIsFilter },
238 { "alFilteri", (ALCvoid *) alFilteri },
239 { "alFilteriv", (ALCvoid *) alFilteriv },
240 { "alFilterf", (ALCvoid *) alFilterf },
241 { "alFilterfv", (ALCvoid *) alFilterfv },
242 { "alGetFilteri", (ALCvoid *) alGetFilteri },
243 { "alGetFilteriv", (ALCvoid *) alGetFilteriv },
244 { "alGetFilterf", (ALCvoid *) alGetFilterf },
245 { "alGetFilterfv", (ALCvoid *) alGetFilterfv },
247 { "alGenEffects", (ALCvoid *) alGenEffects },
248 { "alDeleteEffects", (ALCvoid *) alDeleteEffects },
249 { "alIsEffect", (ALCvoid *) alIsEffect },
250 { "alEffecti", (ALCvoid *) alEffecti },
251 { "alEffectiv", (ALCvoid *) alEffectiv },
252 { "alEffectf", (ALCvoid *) alEffectf },
253 { "alEffectfv", (ALCvoid *) alEffectfv },
254 { "alGetEffecti", (ALCvoid *) alGetEffecti },
255 { "alGetEffectiv", (ALCvoid *) alGetEffectiv },
256 { "alGetEffectf", (ALCvoid *) alGetEffectf },
257 { "alGetEffectfv", (ALCvoid *) alGetEffectfv },
259 { "alGenAuxiliaryEffectSlots", (ALCvoid *) alGenAuxiliaryEffectSlots},
260 { "alDeleteAuxiliaryEffectSlots",(ALCvoid *) alDeleteAuxiliaryEffectSlots},
261 { "alIsAuxiliaryEffectSlot", (ALCvoid *) alIsAuxiliaryEffectSlot },
262 { "alAuxiliaryEffectSloti", (ALCvoid *) alAuxiliaryEffectSloti },
263 { "alAuxiliaryEffectSlotiv", (ALCvoid *) alAuxiliaryEffectSlotiv },
264 { "alAuxiliaryEffectSlotf", (ALCvoid *) alAuxiliaryEffectSlotf },
265 { "alAuxiliaryEffectSlotfv", (ALCvoid *) alAuxiliaryEffectSlotfv },
266 { "alGetAuxiliaryEffectSloti", (ALCvoid *) alGetAuxiliaryEffectSloti},
267 { "alGetAuxiliaryEffectSlotiv", (ALCvoid *) alGetAuxiliaryEffectSlotiv},
268 { "alGetAuxiliaryEffectSlotf", (ALCvoid *) alGetAuxiliaryEffectSlotf},
269 { "alGetAuxiliaryEffectSlotfv", (ALCvoid *) alGetAuxiliaryEffectSlotfv},
271 { "alBufferSubDataSOFT", (ALCvoid *) alBufferSubDataSOFT },
273 { "alBufferSamplesSOFT", (ALCvoid *) alBufferSamplesSOFT },
274 { "alBufferSubSamplesSOFT", (ALCvoid *) alBufferSubSamplesSOFT },
275 { "alGetBufferSamplesSOFT", (ALCvoid *) alGetBufferSamplesSOFT },
276 { "alIsBufferFormatSupportedSOFT",(ALCvoid *) alIsBufferFormatSupportedSOFT},
278 { "alDeferUpdatesSOFT", (ALCvoid *) alDeferUpdatesSOFT },
279 { "alProcessUpdatesSOFT", (ALCvoid *) alProcessUpdatesSOFT },
281 { NULL, (ALCvoid *) NULL }
284 static const ALCenums enumeration[] = {
285 // Types
286 { "ALC_INVALID", ALC_INVALID },
287 { "ALC_FALSE", ALC_FALSE },
288 { "ALC_TRUE", ALC_TRUE },
290 // ALC Properties
291 { "ALC_MAJOR_VERSION", ALC_MAJOR_VERSION },
292 { "ALC_MINOR_VERSION", ALC_MINOR_VERSION },
293 { "ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE },
294 { "ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES },
295 { "ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER },
296 { "ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER },
297 { "ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER },
298 { "ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER },
299 { "ALC_EXTENSIONS", ALC_EXTENSIONS },
300 { "ALC_FREQUENCY", ALC_FREQUENCY },
301 { "ALC_REFRESH", ALC_REFRESH },
302 { "ALC_SYNC", ALC_SYNC },
303 { "ALC_MONO_SOURCES", ALC_MONO_SOURCES },
304 { "ALC_STEREO_SOURCES", ALC_STEREO_SOURCES },
305 { "ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER },
306 { "ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER},
307 { "ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES },
308 { "ALC_CONNECTED", ALC_CONNECTED },
310 // EFX Properties
311 { "ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION },
312 { "ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION },
313 { "ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS },
315 // Loopback device Properties
316 { "ALC_FORMAT_CHANNELS_SOFT", ALC_FORMAT_CHANNELS_SOFT },
317 { "ALC_FORMAT_TYPE_SOFT", ALC_FORMAT_TYPE_SOFT },
319 // Buffer Channel Configurations
320 { "ALC_MONO", ALC_MONO },
321 { "ALC_STEREO", ALC_STEREO },
322 { "ALC_QUAD", ALC_QUAD },
323 { "ALC_5POINT1", ALC_5POINT1 },
324 { "ALC_6POINT1", ALC_6POINT1 },
325 { "ALC_7POINT1", ALC_7POINT1 },
327 // Buffer Sample Types
328 { "ALC_BYTE", ALC_BYTE },
329 { "ALC_UNSIGNED_BYTE", ALC_UNSIGNED_BYTE },
330 { "ALC_SHORT", ALC_SHORT },
331 { "ALC_UNSIGNED_SHORT", ALC_UNSIGNED_SHORT },
332 { "ALC_INT", ALC_INT },
333 { "ALC_UNSIGNED_INT", ALC_UNSIGNED_INT },
334 { "ALC_FLOAT", ALC_FLOAT },
336 // ALC Error Message
337 { "ALC_NO_ERROR", ALC_NO_ERROR },
338 { "ALC_INVALID_DEVICE", ALC_INVALID_DEVICE },
339 { "ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT },
340 { "ALC_INVALID_ENUM", ALC_INVALID_ENUM },
341 { "ALC_INVALID_VALUE", ALC_INVALID_VALUE },
342 { "ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY },
344 { NULL, (ALCenum)0 }
346 // Error strings
347 static const ALCchar alcNoError[] = "No Error";
348 static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
349 static const ALCchar alcErrInvalidContext[] = "Invalid Context";
350 static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
351 static const ALCchar alcErrInvalidValue[] = "Invalid Value";
352 static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
354 /* Device lists. Sizes only include the first ending null character, not the
355 * second */
356 static ALCchar *alcDeviceList;
357 static size_t alcDeviceListSize;
358 static ALCchar *alcAllDeviceList;
359 static size_t alcAllDeviceListSize;
360 static ALCchar *alcCaptureDeviceList;
361 static size_t alcCaptureDeviceListSize;
362 // Default is always the first in the list
363 static ALCchar *alcDefaultDeviceSpecifier;
364 static ALCchar *alcDefaultAllDeviceSpecifier;
365 static ALCchar *alcCaptureDefaultDeviceSpecifier;
368 static const ALCchar alcNoDeviceExtList[] =
369 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
370 "ALC_EXT_thread_local_context ALC_SOFTX_loopback_device";
371 static const ALCchar alcExtensionList[] =
372 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
373 "ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX "
374 "ALC_EXT_thread_local_context ALC_SOFTX_loopback_device";
375 static const ALCint alcMajorVersion = 1;
376 static const ALCint alcMinorVersion = 1;
378 static const ALCint alcEFXMajorVersion = 1;
379 static const ALCint alcEFXMinorVersion = 0;
381 ///////////////////////////////////////////////////////
384 ///////////////////////////////////////////////////////
385 // Global Variables
387 static CRITICAL_SECTION ListLock;
389 /* Device List */
390 static ALCdevice *g_pDeviceList = NULL;
391 static ALCuint g_ulDeviceCount = 0;
393 // Context List
394 static ALCcontext *g_pContextList = NULL;
395 static ALCuint g_ulContextCount = 0;
397 // Thread-local current context
398 static tls_type LocalContext;
399 // Process-wide current context
400 static ALCcontext *GlobalContext;
402 // Context Error
403 static ALCenum g_eLastNullDeviceError = ALC_NO_ERROR;
405 // Default context extensions
406 static const ALchar alExtList[] =
407 "AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 "
408 "AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW "
409 "AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model "
410 "AL_LOKI_quadriphonic AL_SOFTX_buffer_samples AL_SOFT_buffer_sub_data "
411 "AL_SOFT_loop_points AL_SOFTX_non_virtual_channels";
413 // Mixing Priority Level
414 static ALint RTPrioLevel;
416 // Output Log File
417 static FILE *LogFile;
419 // Output Log Level
420 #ifdef _DEBUG
421 enum LogLevel LogLevel = LogWarning;
422 #else
423 enum LogLevel LogLevel = LogError;
424 #endif
426 // Cone scalar
427 ALdouble ConeScale = 0.5;
429 // Localized Z scalar for mono sources
430 ALdouble ZScale = 1.0;
432 ///////////////////////////////////////////////////////
435 ///////////////////////////////////////////////////////
436 // ALC Related helper functions
437 static void ReleaseALC(void);
439 static void alc_initconfig(void);
441 #if defined(_WIN32)
442 static void alc_init(void);
443 static void alc_deinit(void);
445 #ifndef AL_LIBTYPE_STATIC
446 BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
448 (void)lpReserved;
450 // Perform actions based on the reason for calling.
451 switch(ul_reason_for_call)
453 case DLL_PROCESS_ATTACH:
454 DisableThreadLibraryCalls(hModule);
455 alc_init();
456 break;
458 case DLL_PROCESS_DETACH:
459 alc_deinit();
460 break;
462 return TRUE;
464 #elif defined(_MSC_VER)
465 #pragma section(".CRT$XCU",read)
466 static void alc_constructor(void);
467 static void alc_destructor(void);
468 __declspec(allocate(".CRT$XCU")) void (__cdecl* alc_constructor_)(void) = alc_constructor;
470 static void alc_constructor(void)
472 atexit(alc_destructor);
473 alc_init();
476 static void alc_destructor(void)
478 alc_deinit();
480 #elif defined(HAVE_GCC_DESTRUCTOR)
481 static void alc_init(void) __attribute__((constructor));
482 static void alc_deinit(void) __attribute__((destructor));
483 #else
484 #error "No static initialization available on this platform!"
485 #endif
486 #elif defined(HAVE_GCC_DESTRUCTOR)
487 static void alc_init(void) __attribute__((constructor));
488 static void alc_deinit(void) __attribute__((destructor));
489 #else
490 #error "No global initialization available on this platform!"
491 #endif
493 static void alc_init(void)
495 const char *str;
497 LogFile = stderr;
499 str = getenv("__ALSOFT_HALF_ANGLE_CONES");
500 if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
501 ConeScale = 1.0;
503 str = getenv("__ALSOFT_REVERSE_Z");
504 if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
505 ZScale = -1.0;
507 tls_create(&LocalContext);
508 InitializeCriticalSection(&ListLock);
509 ALTHUNK_INIT();
511 #ifdef _WIN32
512 alc_initconfig();
513 #endif
516 static void alc_deinit(void)
518 int i;
520 ReleaseALC();
522 for(i = 0;BackendList[i].Deinit;i++)
523 BackendList[i].Deinit();
524 BackendLoopback.Deinit();
526 FreeALConfig();
527 ALTHUNK_EXIT();
528 DeleteCriticalSection(&ListLock);
529 tls_delete(LocalContext);
531 if(LogFile != stderr)
532 fclose(LogFile);
533 LogFile = NULL;
536 static void alc_initconfig(void)
538 int i;
539 const char *devs, *str;
541 str = getenv("ALSOFT_LOGLEVEL");
542 if(str)
544 long lvl = strtol(str, NULL, 0);
545 if(lvl >= NoLog && lvl <= LogTrace)
546 LogLevel = lvl;
549 str = getenv("ALSOFT_LOGFILE");
550 if(str && str[0])
552 FILE *logfile = fopen(str, "wat");
553 if(logfile) LogFile = logfile;
554 else ERR("Failed to open log file '%s'\n", str);
557 ReadALConfig();
559 InitHrtf();
561 RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0);
563 DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT);
564 if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
565 DefaultResampler = RESAMPLER_DEFAULT;
567 ReverbBoost *= aluPow(10.0f, GetConfigValueFloat("reverb", "boost", 0.0f) /
568 20.0f);
569 EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE);
571 devs = GetConfigValue(NULL, "drivers", "");
572 if(devs[0])
574 int n;
575 size_t len;
576 const char *next = devs;
577 int endlist, delitem;
579 i = 0;
580 do {
581 devs = next;
582 next = strchr(devs, ',');
584 delitem = (devs[0] == '-');
585 if(devs[0] == '-') devs++;
587 if(!devs[0] || devs[0] == ',')
589 endlist = 0;
590 continue;
592 endlist = 1;
594 len = (next ? ((size_t)(next-devs)) : strlen(devs));
595 for(n = i;BackendList[n].Init;n++)
597 if(len == strlen(BackendList[n].name) &&
598 strncmp(BackendList[n].name, devs, len) == 0)
600 if(delitem)
602 do {
603 BackendList[n] = BackendList[n+1];
604 ++n;
605 } while(BackendList[n].Init);
607 else
609 BackendInfo Bkp = BackendList[n];
610 while(n > i)
612 BackendList[n] = BackendList[n-1];
613 --n;
615 BackendList[n] = Bkp;
617 i++;
619 break;
622 } while(next++);
624 if(endlist)
626 BackendList[i].name = NULL;
627 BackendList[i].Init = NULL;
628 BackendList[i].Deinit = NULL;
629 BackendList[i].Probe = NULL;
633 for(i = 0;BackendList[i].Init;i++)
634 BackendList[i].Init(&BackendList[i].Funcs);
635 BackendLoopback.Init(&BackendLoopback.Funcs);
637 str = GetConfigValue(NULL, "excludefx", "");
638 if(str[0])
640 int n;
641 size_t len;
642 const char *next = str;
644 do {
645 str = next;
646 next = strchr(str, ',');
648 if(!str[0] || next == str)
649 continue;
651 len = (next ? ((size_t)(next-str)) : strlen(str));
652 for(n = 0;EffectList[n].name;n++)
654 if(len == strlen(EffectList[n].name) &&
655 strncmp(EffectList[n].name, str, len) == 0)
656 DisabledEffects[EffectList[n].type] = AL_TRUE;
658 } while(next++);
662 #ifndef _WIN32
663 static pthread_once_t once_control = PTHREAD_ONCE_INIT;
664 #define DO_INITCONFIG() pthread_once(&once_control, alc_initconfig)
665 #else
666 #define DO_INITCONFIG()
667 #endif
669 static void ProbeList(ALCchar **list, size_t *listsize, int type)
671 ALint i;
673 free(*list);
674 *list = NULL;
675 *listsize = 0;
677 DO_INITCONFIG();
678 for(i = 0;BackendList[i].Probe;i++)
679 BackendList[i].Probe(type);
682 static void ProbeDeviceList()
683 { ProbeList(&alcDeviceList, &alcDeviceListSize, DEVICE_PROBE); }
684 static void ProbeAllDeviceList()
685 { ProbeList(&alcAllDeviceList, &alcAllDeviceListSize, ALL_DEVICE_PROBE); }
686 static void ProbeCaptureDeviceList()
687 { ProbeList(&alcCaptureDeviceList, &alcCaptureDeviceListSize, CAPTURE_DEVICE_PROBE); }
690 static void AppendList(const ALCchar *name, ALCchar **List, size_t *ListSize)
692 size_t len = strlen(name);
693 void *temp;
695 if(len == 0)
696 return;
698 temp = realloc(*List, (*ListSize) + len + 2);
699 if(!temp)
701 ERR("Realloc failed to add %s!\n", name);
702 return;
704 *List = temp;
706 memcpy((*List)+(*ListSize), name, len+1);
707 *ListSize += len+1;
708 (*List)[*ListSize] = 0;
711 #define DECL_APPEND_LIST_FUNC(type) \
712 void Append##type##List(const ALCchar *name) \
713 { AppendList(name, &alc##type##List, &alc##type##ListSize); }
715 DECL_APPEND_LIST_FUNC(Device)
716 DECL_APPEND_LIST_FUNC(AllDevice)
717 DECL_APPEND_LIST_FUNC(CaptureDevice)
719 #undef DECL_APPEND_LIST_FUNC
722 void al_print(const char *fname, unsigned int line, const char *fmt, ...)
724 const char *fn;
725 char str[256];
726 int i;
728 fn = strrchr(fname, '/');
729 if(!fn) fn = strrchr(fname, '\\');
730 if(!fn) fn = fname;
731 else fn += 1;
733 i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
734 if(i < (int)sizeof(str) && i > 0)
736 va_list ap;
737 va_start(ap, fmt);
738 vsnprintf(str+i, sizeof(str)-i, fmt, ap);
739 va_end(ap);
741 str[sizeof(str)-1] = 0;
743 fprintf(LogFile, "%s", str);
744 fflush(LogFile);
747 void SetRTPriority(void)
749 ALboolean failed;
751 #ifdef _WIN32
752 if(RTPrioLevel > 0)
753 failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
754 else
755 failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
756 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM) && !defined(__OpenBSD__)
757 struct sched_param param;
759 if(RTPrioLevel > 0)
761 /* Use the minimum real-time priority possible for now (on Linux this
762 * should be 1 for SCHED_RR) */
763 param.sched_priority = sched_get_priority_min(SCHED_RR);
764 failed = !!pthread_setschedparam(pthread_self(), SCHED_RR, &param);
766 else
768 param.sched_priority = 0;
769 failed = !!pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);
771 #else
772 /* Real-time priority not available */
773 failed = (RTPrioLevel>0);
774 #endif
775 if(failed)
776 ERR("Failed to set priority level for thread\n");
780 void InitUIntMap(UIntMap *map)
782 map->array = NULL;
783 map->size = 0;
784 map->maxsize = 0;
787 void ResetUIntMap(UIntMap *map)
789 free(map->array);
790 map->array = NULL;
791 map->size = 0;
792 map->maxsize = 0;
795 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
797 ALsizei pos = 0;
799 if(map->size > 0)
801 ALsizei low = 0;
802 ALsizei high = map->size - 1;
803 while(low < high)
805 ALsizei mid = low + (high-low)/2;
806 if(map->array[mid].key < key)
807 low = mid + 1;
808 else
809 high = mid;
811 if(map->array[low].key < key)
812 low++;
813 pos = low;
816 if(pos == map->size || map->array[pos].key != key)
818 if(map->size == map->maxsize)
820 ALvoid *temp;
821 ALsizei newsize;
823 newsize = (map->maxsize ? (map->maxsize<<1) : 4);
824 if(newsize < map->maxsize)
825 return AL_OUT_OF_MEMORY;
827 temp = realloc(map->array, newsize*sizeof(map->array[0]));
828 if(!temp) return AL_OUT_OF_MEMORY;
829 map->array = temp;
830 map->maxsize = newsize;
833 map->size++;
834 if(pos < map->size-1)
835 memmove(&map->array[pos+1], &map->array[pos],
836 (map->size-1-pos)*sizeof(map->array[0]));
838 map->array[pos].key = key;
839 map->array[pos].value = value;
841 return AL_NO_ERROR;
844 void RemoveUIntMapKey(UIntMap *map, ALuint key)
846 if(map->size > 0)
848 ALsizei low = 0;
849 ALsizei high = map->size - 1;
850 while(low < high)
852 ALsizei mid = low + (high-low)/2;
853 if(map->array[mid].key < key)
854 low = mid + 1;
855 else
856 high = mid;
858 if(map->array[low].key == key)
860 if(low < map->size-1)
861 memmove(&map->array[low], &map->array[low+1],
862 (map->size-1-low)*sizeof(map->array[0]));
863 map->size--;
868 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key)
870 if(map->size > 0)
872 ALsizei low = 0;
873 ALsizei high = map->size - 1;
874 while(low < high)
876 ALsizei mid = low + (high-low)/2;
877 if(map->array[mid].key < key)
878 low = mid + 1;
879 else
880 high = mid;
882 if(map->array[low].key == key)
883 return map->array[low].value;
885 return NULL;
889 const ALCchar *DevFmtTypeString(enum DevFmtType type)
891 switch(type)
893 case DevFmtByte: return "Signed Byte";
894 case DevFmtUByte: return "Unsigned Byte";
895 case DevFmtShort: return "Signed Short";
896 case DevFmtUShort: return "Unsigned Short";
897 case DevFmtFloat: return "Float";
899 return "(unknown type)";
901 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans)
903 switch(chans)
905 case DevFmtMono: return "Mono";
906 case DevFmtStereo: return "Stereo";
907 case DevFmtQuad: return "Quadraphonic";
908 case DevFmtX51: return "5.1 Surround";
909 case DevFmtX51Side: return "5.1 Side";
910 case DevFmtX61: return "6.1 Surround";
911 case DevFmtX71: return "7.1 Surround";
913 return "(unknown channels)";
916 ALuint BytesFromDevFmt(enum DevFmtType type)
918 switch(type)
920 case DevFmtByte: return sizeof(ALbyte);
921 case DevFmtUByte: return sizeof(ALubyte);
922 case DevFmtShort: return sizeof(ALshort);
923 case DevFmtUShort: return sizeof(ALushort);
924 case DevFmtFloat: return sizeof(ALfloat);
926 return 0;
928 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
930 switch(chans)
932 case DevFmtMono: return 1;
933 case DevFmtStereo: return 2;
934 case DevFmtQuad: return 4;
935 case DevFmtX51: return 6;
936 case DevFmtX51Side: return 6;
937 case DevFmtX61: return 7;
938 case DevFmtX71: return 8;
940 return 0;
942 ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans,
943 enum DevFmtType *type)
945 switch(format)
947 case AL_FORMAT_MONO8:
948 *chans = DevFmtMono;
949 *type = DevFmtUByte;
950 return AL_TRUE;
951 case AL_FORMAT_MONO16:
952 *chans = DevFmtMono;
953 *type = DevFmtShort;
954 return AL_TRUE;
955 case AL_FORMAT_MONO_FLOAT32:
956 *chans = DevFmtMono;
957 *type = DevFmtFloat;
958 return AL_TRUE;
959 case AL_FORMAT_STEREO8:
960 *chans = DevFmtStereo;
961 *type = DevFmtUByte;
962 return AL_TRUE;
963 case AL_FORMAT_STEREO16:
964 *chans = DevFmtStereo;
965 *type = DevFmtShort;
966 return AL_TRUE;
967 case AL_FORMAT_STEREO_FLOAT32:
968 *chans = DevFmtStereo;
969 *type = DevFmtFloat;
970 return AL_TRUE;
971 case AL_FORMAT_QUAD8:
972 *chans = DevFmtQuad;
973 *type = DevFmtUByte;
974 return AL_TRUE;
975 case AL_FORMAT_QUAD16:
976 *chans = DevFmtQuad;
977 *type = DevFmtShort;
978 return AL_TRUE;
979 case AL_FORMAT_QUAD32:
980 *chans = DevFmtQuad;
981 *type = DevFmtFloat;
982 return AL_TRUE;
983 case AL_FORMAT_51CHN8:
984 *chans = DevFmtX51;
985 *type = DevFmtUByte;
986 return AL_TRUE;
987 case AL_FORMAT_51CHN16:
988 *chans = DevFmtX51;
989 *type = DevFmtShort;
990 return AL_TRUE;
991 case AL_FORMAT_51CHN32:
992 *chans = DevFmtX51;
993 *type = DevFmtFloat;
994 return AL_TRUE;
995 case AL_FORMAT_61CHN8:
996 *chans = DevFmtX61;
997 *type = DevFmtUByte;
998 return AL_TRUE;
999 case AL_FORMAT_61CHN16:
1000 *chans = DevFmtX61;
1001 *type = DevFmtShort;
1002 return AL_TRUE;
1003 case AL_FORMAT_61CHN32:
1004 *chans = DevFmtX61;
1005 *type = DevFmtFloat;
1006 return AL_TRUE;
1007 case AL_FORMAT_71CHN8:
1008 *chans = DevFmtX71;
1009 *type = DevFmtUByte;
1010 return AL_TRUE;
1011 case AL_FORMAT_71CHN16:
1012 *chans = DevFmtX71;
1013 *type = DevFmtShort;
1014 return AL_TRUE;
1015 case AL_FORMAT_71CHN32:
1016 *chans = DevFmtX71;
1017 *type = DevFmtFloat;
1018 return AL_TRUE;
1020 return AL_FALSE;
1023 static ALCboolean IsValidALCType(ALCenum type)
1025 switch(type)
1027 case ALC_BYTE:
1028 case ALC_UNSIGNED_BYTE:
1029 case ALC_SHORT:
1030 case ALC_UNSIGNED_SHORT:
1031 case ALC_INT:
1032 case ALC_UNSIGNED_INT:
1033 case ALC_FLOAT:
1034 return ALC_TRUE;
1036 return ALC_FALSE;
1039 static ALCboolean IsValidALCChannels(ALCenum channels)
1041 switch(channels)
1043 case ALC_MONO:
1044 case ALC_STEREO:
1045 case ALC_QUAD:
1046 case ALC_5POINT1:
1047 case ALC_6POINT1:
1048 case ALC_7POINT1:
1049 return ALC_TRUE;
1051 return ALC_FALSE;
1055 #ifndef _WIN32
1056 void InitializeCriticalSection(CRITICAL_SECTION *cs)
1058 pthread_mutexattr_t attrib;
1059 int ret;
1061 ret = pthread_mutexattr_init(&attrib);
1062 assert(ret == 0);
1064 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
1065 #ifdef HAVE_PTHREAD_NP_H
1066 if(ret != 0)
1067 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
1068 #endif
1069 assert(ret == 0);
1070 ret = pthread_mutex_init(cs, &attrib);
1071 assert(ret == 0);
1073 pthread_mutexattr_destroy(&attrib);
1075 void DeleteCriticalSection(CRITICAL_SECTION *cs)
1077 int ret;
1078 ret = pthread_mutex_destroy(cs);
1079 assert(ret == 0);
1081 void EnterCriticalSection(CRITICAL_SECTION *cs)
1083 int ret;
1084 ret = pthread_mutex_lock(cs);
1085 assert(ret == 0);
1087 void LeaveCriticalSection(CRITICAL_SECTION *cs)
1089 int ret;
1090 ret = pthread_mutex_unlock(cs);
1091 assert(ret == 0);
1094 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
1095 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
1096 * Additionally, Win32 is supposed to measure the time since Windows started,
1097 * as opposed to the actual time. */
1098 ALuint timeGetTime(void)
1100 #if _POSIX_TIMERS > 0
1101 struct timespec ts;
1102 int ret = -1;
1104 #if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK >= 0)
1105 #if _POSIX_MONOTONIC_CLOCK == 0
1106 static int hasmono = 0;
1107 if(hasmono > 0 || (hasmono == 0 &&
1108 (hasmono=sysconf(_SC_MONOTONIC_CLOCK)) > 0))
1109 #endif
1110 ret = clock_gettime(CLOCK_MONOTONIC, &ts);
1111 #endif
1112 if(ret != 0)
1113 ret = clock_gettime(CLOCK_REALTIME, &ts);
1114 assert(ret == 0);
1116 return ts.tv_nsec/1000000 + ts.tv_sec*1000;
1117 #else
1118 struct timeval tv;
1119 int ret;
1121 ret = gettimeofday(&tv, NULL);
1122 assert(ret == 0);
1124 return tv.tv_usec/1000 + tv.tv_sec*1000;
1125 #endif
1127 #endif
1129 #if defined(_WIN32)
1130 void *LoadLib(const char *name)
1131 { return LoadLibraryA(name); }
1133 void CloseLib(void *handle)
1134 { FreeLibrary((HANDLE)handle); }
1136 void *GetSymbol(void *handle, const char *name)
1138 void *ret;
1140 ret = (void*)GetProcAddress((HANDLE)handle, name);
1141 if(ret == NULL)
1142 ERR("Failed to load %s\n", name);
1143 return ret;
1146 #elif defined(HAVE_DLFCN_H)
1148 void *LoadLib(const char *name)
1150 const char *err;
1151 void *handle;
1153 dlerror();
1154 handle = dlopen(name, RTLD_NOW);
1155 if((err=dlerror()) != NULL)
1156 handle = NULL;
1157 return handle;
1160 void CloseLib(void *handle)
1161 { dlclose(handle); }
1163 void *GetSymbol(void *handle, const char *name)
1165 const char *err;
1166 void *sym;
1168 dlerror();
1169 sym = dlsym(handle, name);
1170 if((err=dlerror()) != NULL)
1172 ERR("Failed to load %s: %s\n", name, err);
1173 sym = NULL;
1175 return sym;
1177 #endif
1179 static void LockLists(void)
1181 EnterCriticalSection(&ListLock);
1184 static void UnlockLists(void)
1186 LeaveCriticalSection(&ListLock);
1190 IsDevice
1192 Check pDevice is a valid Device pointer
1194 static ALCboolean IsDevice(ALCdevice *pDevice)
1196 ALCdevice *pTempDevice;
1198 pTempDevice = g_pDeviceList;
1199 while(pTempDevice && pTempDevice != pDevice)
1200 pTempDevice = pTempDevice->next;
1202 return (pTempDevice ? ALC_TRUE : ALC_FALSE);
1206 IsContext
1208 Check pContext is a valid Context pointer
1210 static ALCboolean IsContext(ALCcontext *pContext)
1212 ALCcontext *pTempContext;
1214 pTempContext = g_pContextList;
1215 while (pTempContext && pTempContext != pContext)
1216 pTempContext = pTempContext->next;
1218 return (pTempContext ? ALC_TRUE : ALC_FALSE);
1223 alcSetError
1225 Store latest ALC Error
1227 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
1229 LockLists();
1230 if(IsDevice(device))
1231 device->LastError = errorCode;
1232 else
1233 g_eLastNullDeviceError = errorCode;
1234 UnlockLists();
1238 /* UpdateDeviceParams:
1240 * Updates device parameters according to the attribute list.
1242 static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
1244 ALuint i;
1246 // Check for attributes
1247 if(attrList && attrList[0])
1249 ALCuint freq, numMono, numStereo, numSends;
1250 enum DevFmtChannels schans;
1251 enum DevFmtType stype;
1252 ALuint attrIdx;
1254 // If a context is already running on the device, stop playback so the
1255 // device attributes can be updated
1256 if((device->Flags&DEVICE_RUNNING))
1257 ALCdevice_StopPlayback(device);
1258 device->Flags &= ~DEVICE_RUNNING;
1260 freq = device->Frequency;
1261 schans = device->FmtChans;
1262 stype = device->FmtType;
1263 numMono = device->NumMonoSources;
1264 numStereo = device->NumStereoSources;
1265 numSends = device->NumAuxSends;
1267 freq = GetConfigValueInt(NULL, "frequency", freq);
1268 if(freq < 8000) freq = 8000;
1270 attrIdx = 0;
1271 while(attrList[attrIdx])
1273 if(attrList[attrIdx] == ALC_FORMAT_CHANNELS_SOFT &&
1274 device->IsLoopbackDevice)
1276 ALCint val = attrList[attrIdx + 1];
1277 if(!IsValidALCChannels(val) || !ChannelsFromDevFmt(val))
1279 alcSetError(device, ALC_INVALID_VALUE);
1280 return ALC_FALSE;
1282 schans = val;
1285 if(attrList[attrIdx] == ALC_FORMAT_TYPE_SOFT &&
1286 device->IsLoopbackDevice)
1288 ALCint val = attrList[attrIdx + 1];
1289 if(!IsValidALCType(val) || !BytesFromDevFmt(val))
1291 alcSetError(device, ALC_INVALID_VALUE);
1292 return ALC_FALSE;
1294 stype = val;
1297 if(attrList[attrIdx] == ALC_FREQUENCY)
1299 if(device->IsLoopbackDevice)
1301 freq = attrList[attrIdx + 1];
1302 if(freq < 8000)
1304 alcSetError(device, ALC_INVALID_VALUE);
1305 return ALC_FALSE;
1308 else if(!ConfigValueExists(NULL, "frequency"))
1310 freq = attrList[attrIdx + 1];
1311 if(freq < 8000) freq = 8000;
1312 device->Flags |= DEVICE_FREQUENCY_REQUEST;
1316 if(attrList[attrIdx] == ALC_STEREO_SOURCES)
1318 numStereo = attrList[attrIdx + 1];
1319 if(numStereo > device->MaxNoOfSources)
1320 numStereo = device->MaxNoOfSources;
1322 numMono = device->MaxNoOfSources - numStereo;
1325 if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
1326 !ConfigValueExists(NULL, "sends"))
1328 numSends = attrList[attrIdx + 1];
1329 if(numSends > MAX_SENDS)
1330 numSends = MAX_SENDS;
1333 attrIdx += 2;
1336 device->UpdateSize = (ALuint64)device->UpdateSize * freq /
1337 device->Frequency;
1339 device->Frequency = freq;
1340 device->FmtChans = schans;
1341 device->FmtType = stype;
1342 device->NumMonoSources = numMono;
1343 device->NumStereoSources = numStereo;
1344 device->NumAuxSends = numSends;
1347 if((device->Flags&DEVICE_RUNNING))
1348 return ALC_TRUE;
1350 LockDevice(device);
1351 TRACE("Format pre-setup: %s%s, %s, %uhz%s, %u update size x%d\n",
1352 DevFmtChannelsString(device->FmtChans),
1353 (device->Flags&DEVICE_CHANNELS_REQUEST)?" (requested)":"",
1354 DevFmtTypeString(device->FmtType), device->Frequency,
1355 (device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
1356 device->UpdateSize, device->NumUpdates);
1357 if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
1359 UnlockDevice(device);
1360 return ALC_FALSE;
1362 device->Flags |= DEVICE_RUNNING;
1363 TRACE("Format post-setup: %s%s, %s, %uhz%s, %u update size x%d\n",
1364 DevFmtChannelsString(device->FmtChans),
1365 (device->Flags&DEVICE_CHANNELS_REQUEST)?" (requested)":"",
1366 DevFmtTypeString(device->FmtType), device->Frequency,
1367 (device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
1368 device->UpdateSize, device->NumUpdates);
1370 aluInitPanning(device);
1372 for(i = 0;i < MAXCHANNELS;i++)
1374 device->ClickRemoval[i] = 0.0f;
1375 device->PendingClicks[i] = 0.0f;
1378 if(!device->IsLoopbackDevice && GetConfigValueBool(NULL, "hrtf", AL_FALSE))
1379 device->Flags |= DEVICE_USE_HRTF;
1380 if((device->Flags&DEVICE_USE_HRTF) && !IsHrtfCompatible(device))
1381 device->Flags &= ~DEVICE_USE_HRTF;
1382 TRACE("HRTF %s\n", (device->Flags&DEVICE_USE_HRTF)?"enabled":"disabled");
1384 if(!(device->Flags&DEVICE_USE_HRTF) && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
1386 if(!device->Bs2b)
1388 device->Bs2b = calloc(1, sizeof(*device->Bs2b));
1389 bs2b_clear(device->Bs2b);
1391 bs2b_set_srate(device->Bs2b, device->Frequency);
1392 bs2b_set_level(device->Bs2b, device->Bs2bLevel);
1393 TRACE("BS2B level %d\n", device->Bs2bLevel);
1395 else
1397 free(device->Bs2b);
1398 device->Bs2b = NULL;
1399 TRACE("BS2B disabled\n");
1402 device->Flags &= ~DEVICE_DUPLICATE_STEREO;
1403 switch(device->FmtChans)
1405 case DevFmtMono:
1406 case DevFmtStereo:
1407 break;
1408 case DevFmtQuad:
1409 case DevFmtX51:
1410 case DevFmtX51Side:
1411 case DevFmtX61:
1412 case DevFmtX71:
1413 if(GetConfigValueBool(NULL, "stereodup", AL_TRUE))
1414 device->Flags |= DEVICE_DUPLICATE_STEREO;
1415 break;
1417 TRACE("Stereo duplication %s\n", (device->Flags&DEVICE_DUPLICATE_STEREO)?"enabled":"disabled");
1419 for(i = 0;i < device->NumContexts;i++)
1421 ALCcontext *context = device->Contexts[i];
1422 ALsizei pos;
1424 context->UpdateSources = AL_FALSE;
1425 for(pos = 0;pos < context->EffectSlotMap.size;pos++)
1427 ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
1429 if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
1431 UnlockDevice(device);
1432 ALCdevice_StopPlayback(device);
1433 device->Flags &= ~DEVICE_RUNNING;
1434 return ALC_FALSE;
1436 slot->NeedsUpdate = AL_FALSE;
1437 ALEffect_Update(slot->EffectState, context, slot);
1440 for(pos = 0;pos < context->SourceMap.size;pos++)
1442 ALsource *source = context->SourceMap.array[pos].value;
1443 ALuint s = device->NumAuxSends;
1444 while(s < MAX_SENDS)
1446 if(source->Send[s].Slot)
1447 source->Send[s].Slot->refcount--;
1448 source->Send[s].Slot = NULL;
1449 source->Send[s].WetFilter.type = 0;
1450 source->Send[s].WetFilter.filter = 0;
1451 s++;
1453 source->NeedsUpdate = AL_FALSE;
1454 ALsource_Update(source, context);
1457 UnlockDevice(device);
1459 return ALC_TRUE;
1463 ALCvoid LockDevice(ALCdevice *device)
1465 EnterCriticalSection(&device->Mutex);
1468 ALCvoid UnlockDevice(ALCdevice *device)
1470 LeaveCriticalSection(&device->Mutex);
1474 LockContext
1476 Thread-safe entry
1478 ALCvoid LockContext(ALCcontext *context)
1480 EnterCriticalSection(&context->Device->Mutex);
1485 UnlockContext
1487 Thread-safe exit
1489 ALCvoid UnlockContext(ALCcontext *context)
1491 LeaveCriticalSection(&context->Device->Mutex);
1496 GetLockedContext
1498 Returns the currently active Context, in a locked state
1500 ALCcontext *GetLockedContext(void)
1502 ALCcontext *pContext = NULL;
1504 LockLists();
1506 pContext = tls_get(LocalContext);
1507 if(pContext && !IsContext(pContext))
1509 tls_set(LocalContext, NULL);
1510 pContext = NULL;
1512 if(!pContext)
1513 pContext = GlobalContext;
1514 if(pContext)
1515 LockContext(pContext);
1517 UnlockLists();
1519 return pContext;
1524 InitContext
1526 Initialize Context variables
1528 static ALvoid InitContext(ALCcontext *pContext)
1530 //Initialise listener
1531 pContext->Listener.Gain = 1.0f;
1532 pContext->Listener.MetersPerUnit = 1.0f;
1533 pContext->Listener.Position[0] = 0.0f;
1534 pContext->Listener.Position[1] = 0.0f;
1535 pContext->Listener.Position[2] = 0.0f;
1536 pContext->Listener.Velocity[0] = 0.0f;
1537 pContext->Listener.Velocity[1] = 0.0f;
1538 pContext->Listener.Velocity[2] = 0.0f;
1539 pContext->Listener.Forward[0] = 0.0f;
1540 pContext->Listener.Forward[1] = 0.0f;
1541 pContext->Listener.Forward[2] = -1.0f;
1542 pContext->Listener.Up[0] = 0.0f;
1543 pContext->Listener.Up[1] = 1.0f;
1544 pContext->Listener.Up[2] = 0.0f;
1546 //Validate pContext
1547 pContext->LastError = AL_NO_ERROR;
1548 pContext->UpdateSources = AL_FALSE;
1549 pContext->ActiveSourceCount = 0;
1550 InitUIntMap(&pContext->SourceMap);
1551 InitUIntMap(&pContext->EffectSlotMap);
1553 //Set globals
1554 pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
1555 pContext->SourceDistanceModel = AL_FALSE;
1556 pContext->DopplerFactor = 1.0f;
1557 pContext->DopplerVelocity = 1.0f;
1558 pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
1559 pContext->DeferUpdates = AL_FALSE;
1561 pContext->ExtensionList = alExtList;
1566 ExitContext
1568 Clean up Context, destroy any remaining Sources
1570 static ALCvoid ExitContext(ALCcontext *pContext)
1572 //Invalidate context
1573 pContext->LastError = AL_NO_ERROR;
1576 ///////////////////////////////////////////////////////
1579 ///////////////////////////////////////////////////////
1580 // ALC Functions calls
1583 // This should probably move to another c file but for now ...
1584 ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
1586 ALCboolean DeviceFound = ALC_FALSE;
1587 ALCdevice *device = NULL;
1588 ALCint i;
1590 DO_INITCONFIG();
1592 if(SampleSize <= 0)
1594 alcSetError(NULL, ALC_INVALID_VALUE);
1595 return NULL;
1598 if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0))
1599 deviceName = NULL;
1601 device = calloc(1, sizeof(ALCdevice));
1602 if(!device)
1604 alcSetError(NULL, ALC_OUT_OF_MEMORY);
1605 return NULL;
1608 //Validate device
1609 device->Connected = ALC_TRUE;
1610 device->IsCaptureDevice = AL_TRUE;
1611 device->IsLoopbackDevice = AL_FALSE;
1612 InitializeCriticalSection(&device->Mutex);
1614 device->szDeviceName = NULL;
1616 device->Flags |= DEVICE_FREQUENCY_REQUEST;
1617 device->Frequency = frequency;
1619 device->Flags |= DEVICE_CHANNELS_REQUEST;
1620 if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
1622 free(device);
1623 alcSetError(NULL, ALC_INVALID_ENUM);
1624 return NULL;
1627 device->UpdateSize = SampleSize;
1628 device->NumUpdates = 1;
1630 LockLists();
1631 for(i = 0;BackendList[i].Init;i++)
1633 device->Funcs = &BackendList[i].Funcs;
1634 if(ALCdevice_OpenCapture(device, deviceName))
1636 device->next = g_pDeviceList;
1637 g_pDeviceList = device;
1638 g_ulDeviceCount++;
1640 DeviceFound = ALC_TRUE;
1641 break;
1644 UnlockLists();
1646 if(!DeviceFound)
1648 alcSetError(NULL, ALC_INVALID_VALUE);
1649 free(device);
1650 device = NULL;
1653 return device;
1656 ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
1658 ALCdevice **list;
1660 LockLists();
1661 list = &g_pDeviceList;
1662 while(*list && *list != pDevice)
1663 list = &(*list)->next;
1665 if(!*list || !(*list)->IsCaptureDevice)
1667 alcSetError(*list, ALC_INVALID_DEVICE);
1668 UnlockLists();
1669 return ALC_FALSE;
1672 *list = (*list)->next;
1673 g_ulDeviceCount--;
1675 UnlockLists();
1677 LockDevice(pDevice);
1678 ALCdevice_CloseCapture(pDevice);
1679 UnlockDevice(pDevice);
1681 free(pDevice->szDeviceName);
1682 pDevice->szDeviceName = NULL;
1684 DeleteCriticalSection(&pDevice->Mutex);
1686 free(pDevice);
1688 return ALC_TRUE;
1691 ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
1693 LockLists();
1694 if(!IsDevice(device) || !device->IsCaptureDevice)
1696 alcSetError(device, ALC_INVALID_DEVICE);
1697 UnlockLists();
1698 return;
1700 LockDevice(device);
1701 UnlockLists();
1702 if(device->Connected)
1703 ALCdevice_StartCapture(device);
1704 UnlockDevice(device);
1707 ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
1709 LockLists();
1710 if(!IsDevice(device) || !device->IsCaptureDevice)
1712 alcSetError(device, ALC_INVALID_DEVICE);
1713 UnlockLists();
1714 return;
1716 LockDevice(device);
1717 UnlockLists();
1718 if(device->Connected)
1719 ALCdevice_StopCapture(device);
1720 UnlockDevice(device);
1723 ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
1725 LockLists();
1726 if(!IsDevice(device) || !device->IsCaptureDevice)
1728 alcSetError(device, ALC_INVALID_DEVICE);
1729 UnlockLists();
1730 return;
1732 LockDevice(device);
1733 UnlockLists();
1734 if(device->Connected)
1735 ALCdevice_CaptureSamples(device, buffer, samples);
1736 UnlockDevice(device);
1740 alcGetError
1742 Return last ALC generated error code
1744 ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
1746 ALCenum errorCode;
1748 LockLists();
1749 if(IsDevice(device))
1751 errorCode = device->LastError;
1752 device->LastError = ALC_NO_ERROR;
1754 else
1756 errorCode = g_eLastNullDeviceError;
1757 g_eLastNullDeviceError = ALC_NO_ERROR;
1759 UnlockLists();
1760 return errorCode;
1765 alcSuspendContext
1767 Not functional
1769 ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *Context)
1771 (void)Context;
1776 alcProcessContext
1778 Not functional
1780 ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *Context)
1782 (void)Context;
1787 alcGetString
1789 Returns information about the Device, and error strings
1791 ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
1793 const ALCchar *value = NULL;
1795 switch(param)
1797 case ALC_NO_ERROR:
1798 value = alcNoError;
1799 break;
1801 case ALC_INVALID_ENUM:
1802 value = alcErrInvalidEnum;
1803 break;
1805 case ALC_INVALID_VALUE:
1806 value = alcErrInvalidValue;
1807 break;
1809 case ALC_INVALID_DEVICE:
1810 value = alcErrInvalidDevice;
1811 break;
1813 case ALC_INVALID_CONTEXT:
1814 value = alcErrInvalidContext;
1815 break;
1817 case ALC_OUT_OF_MEMORY:
1818 value = alcErrOutOfMemory;
1819 break;
1821 case ALC_DEVICE_SPECIFIER:
1822 LockLists();
1823 if(IsDevice(pDevice))
1824 value = pDevice->szDeviceName;
1825 else
1827 ProbeDeviceList();
1828 value = alcDeviceList;
1830 UnlockLists();
1831 break;
1833 case ALC_ALL_DEVICES_SPECIFIER:
1834 ProbeAllDeviceList();
1835 value = alcAllDeviceList;
1836 break;
1838 case ALC_CAPTURE_DEVICE_SPECIFIER:
1839 LockLists();
1840 if(IsDevice(pDevice))
1841 value = pDevice->szDeviceName;
1842 else
1844 ProbeCaptureDeviceList();
1845 value = alcCaptureDeviceList;
1847 UnlockLists();
1848 break;
1850 /* Default devices are always first in the list */
1851 case ALC_DEFAULT_DEVICE_SPECIFIER:
1852 if(!alcDeviceList)
1853 ProbeDeviceList();
1855 free(alcDefaultDeviceSpecifier);
1856 alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
1857 if(!alcDefaultDeviceSpecifier)
1858 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1859 value = alcDefaultDeviceSpecifier;
1860 break;
1862 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
1863 if(!alcAllDeviceList)
1864 ProbeAllDeviceList();
1866 free(alcDefaultAllDeviceSpecifier);
1867 alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
1868 alcAllDeviceList : "");
1869 if(!alcDefaultAllDeviceSpecifier)
1870 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1871 value = alcDefaultAllDeviceSpecifier;
1872 break;
1874 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
1875 if(!alcCaptureDeviceList)
1876 ProbeCaptureDeviceList();
1878 free(alcCaptureDefaultDeviceSpecifier);
1879 alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
1880 alcCaptureDeviceList : "");
1881 if(!alcCaptureDefaultDeviceSpecifier)
1882 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
1883 value = alcCaptureDefaultDeviceSpecifier;
1884 break;
1886 case ALC_EXTENSIONS:
1887 LockLists();
1888 if(IsDevice(pDevice))
1889 value = alcExtensionList;
1890 else
1891 value = alcNoDeviceExtList;
1892 UnlockLists();
1893 break;
1895 default:
1896 alcSetError(pDevice, ALC_INVALID_ENUM);
1897 break;
1900 return value;
1905 alcGetIntegerv
1907 Returns information about the Device and the version of Open AL
1909 ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
1911 if(size == 0 || data == NULL)
1913 alcSetError(device, ALC_INVALID_VALUE);
1914 return;
1917 LockLists();
1918 if(!IsDevice(device))
1920 switch(param)
1922 case ALC_MAJOR_VERSION:
1923 *data = alcMajorVersion;
1924 break;
1925 case ALC_MINOR_VERSION:
1926 *data = alcMinorVersion;
1927 break;
1929 case ALC_ATTRIBUTES_SIZE:
1930 case ALC_ALL_ATTRIBUTES:
1931 case ALC_FREQUENCY:
1932 case ALC_REFRESH:
1933 case ALC_SYNC:
1934 case ALC_MONO_SOURCES:
1935 case ALC_STEREO_SOURCES:
1936 case ALC_CAPTURE_SAMPLES:
1937 case ALC_FORMAT_CHANNELS_SOFT:
1938 case ALC_FORMAT_TYPE_SOFT:
1939 alcSetError(NULL, ALC_INVALID_DEVICE);
1940 break;
1942 default:
1943 alcSetError(NULL, ALC_INVALID_ENUM);
1944 break;
1947 else if(device->IsCaptureDevice)
1949 switch(param)
1951 case ALC_CAPTURE_SAMPLES:
1952 LockDevice(device);
1953 *data = ALCdevice_AvailableSamples(device);
1954 UnlockDevice(device);
1955 break;
1957 case ALC_CONNECTED:
1958 *data = device->Connected;
1959 break;
1961 default:
1962 alcSetError(device, ALC_INVALID_ENUM);
1963 break;
1966 else /* render device */
1968 switch(param)
1970 case ALC_MAJOR_VERSION:
1971 *data = alcMajorVersion;
1972 break;
1974 case ALC_MINOR_VERSION:
1975 *data = alcMinorVersion;
1976 break;
1978 case ALC_EFX_MAJOR_VERSION:
1979 *data = alcEFXMajorVersion;
1980 break;
1982 case ALC_EFX_MINOR_VERSION:
1983 *data = alcEFXMinorVersion;
1984 break;
1986 case ALC_ATTRIBUTES_SIZE:
1987 *data = 13;
1988 break;
1990 case ALC_ALL_ATTRIBUTES:
1991 if(size < 13)
1992 alcSetError(device, ALC_INVALID_VALUE);
1993 else
1995 int i = 0;
1997 data[i++] = ALC_FREQUENCY;
1998 data[i++] = device->Frequency;
2000 if(!device->IsLoopbackDevice)
2002 data[i++] = ALC_REFRESH;
2003 data[i++] = device->Frequency / device->UpdateSize;
2005 data[i++] = ALC_SYNC;
2006 data[i++] = ALC_FALSE;
2008 else
2010 data[i++] = ALC_FORMAT_CHANNELS_SOFT;
2011 data[i++] = device->FmtChans;
2013 data[i++] = ALC_FORMAT_TYPE_SOFT;
2014 data[i++] = device->FmtType;
2017 data[i++] = ALC_MONO_SOURCES;
2018 data[i++] = device->NumMonoSources;
2020 data[i++] = ALC_STEREO_SOURCES;
2021 data[i++] = device->NumStereoSources;
2023 data[i++] = ALC_MAX_AUXILIARY_SENDS;
2024 data[i++] = device->NumAuxSends;
2026 data[i++] = 0;
2028 break;
2030 case ALC_FREQUENCY:
2031 *data = device->Frequency;
2032 break;
2034 case ALC_REFRESH:
2035 if(device->IsLoopbackDevice)
2036 alcSetError(device, ALC_INVALID_DEVICE);
2037 else
2038 *data = device->Frequency / device->UpdateSize;
2039 break;
2041 case ALC_SYNC:
2042 if(device->IsLoopbackDevice)
2043 alcSetError(device, ALC_INVALID_DEVICE);
2044 else
2045 *data = ALC_FALSE;
2046 break;
2048 case ALC_FORMAT_CHANNELS_SOFT:
2049 if(!device->IsLoopbackDevice)
2050 alcSetError(device, ALC_INVALID_DEVICE);
2051 else
2052 *data = device->FmtChans;
2053 break;
2055 case ALC_FORMAT_TYPE_SOFT:
2056 if(!device->IsLoopbackDevice)
2057 alcSetError(device, ALC_INVALID_DEVICE);
2058 else
2059 *data = device->FmtType;
2060 break;
2062 case ALC_MONO_SOURCES:
2063 *data = device->NumMonoSources;
2064 break;
2066 case ALC_STEREO_SOURCES:
2067 *data = device->NumStereoSources;
2068 break;
2070 case ALC_MAX_AUXILIARY_SENDS:
2071 *data = device->NumAuxSends;
2072 break;
2074 case ALC_CONNECTED:
2075 *data = device->Connected;
2076 break;
2078 default:
2079 alcSetError(device, ALC_INVALID_ENUM);
2080 break;
2083 UnlockLists();
2088 alcIsExtensionPresent
2090 Determines if there is support for a particular extension
2092 ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
2094 ALCboolean bResult = ALC_FALSE;
2095 const char *ptr;
2096 size_t len;
2098 if(!extName)
2100 alcSetError(device, ALC_INVALID_VALUE);
2101 return ALC_FALSE;
2104 len = strlen(extName);
2105 LockLists();
2106 ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
2107 UnlockLists();
2108 while(ptr && *ptr)
2110 if(strncasecmp(ptr, extName, len) == 0 &&
2111 (ptr[len] == '\0' || isspace(ptr[len])))
2113 bResult = ALC_TRUE;
2114 break;
2116 if((ptr=strchr(ptr, ' ')) != NULL)
2118 do {
2119 ++ptr;
2120 } while(isspace(*ptr));
2124 return bResult;
2129 alcGetProcAddress
2131 Retrieves the function address for a particular extension function
2133 ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
2135 ALsizei i = 0;
2137 if(!funcName)
2139 alcSetError(device, ALC_INVALID_VALUE);
2140 return NULL;
2143 while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
2144 i++;
2145 return alcFunctions[i].address;
2150 alcGetEnumValue
2152 Get the value for a particular ALC Enumerated Value
2154 ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
2156 ALsizei i = 0;
2158 if(!enumName)
2160 alcSetError(device, ALC_INVALID_VALUE);
2161 return (ALCenum)0;
2164 while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) != 0)
2165 i++;
2166 return enumeration[i].value;
2171 alcCreateContext
2173 Create and attach a Context to a particular Device.
2175 ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
2177 ALCcontext *ALContext;
2178 void *temp;
2180 LockLists();
2181 if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
2183 alcSetError(device, ALC_INVALID_DEVICE);
2184 UnlockLists();
2185 return NULL;
2188 // Reset Context Last Error code
2189 device->LastError = ALC_NO_ERROR;
2191 if(UpdateDeviceParams(device, attrList) == ALC_FALSE)
2193 alcSetError(device, ALC_INVALID_DEVICE);
2194 aluHandleDisconnect(device);
2195 UnlockLists();
2196 return NULL;
2199 LockDevice(device);
2200 ALContext = NULL;
2201 temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
2202 if(temp)
2204 device->Contexts = temp;
2206 ALContext = calloc(1, sizeof(ALCcontext));
2207 if(ALContext)
2209 ALContext->MaxActiveSources = 256;
2210 ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) *
2211 ALContext->MaxActiveSources);
2214 if(!ALContext || !ALContext->ActiveSources)
2216 free(ALContext);
2217 alcSetError(device, ALC_OUT_OF_MEMORY);
2218 UnlockDevice(device);
2219 if(device->NumContexts == 0)
2221 ALCdevice_StopPlayback(device);
2222 device->Flags &= ~DEVICE_RUNNING;
2224 UnlockLists();
2225 return NULL;
2228 device->Contexts[device->NumContexts++] = ALContext;
2229 ALContext->Device = device;
2231 InitContext(ALContext);
2232 UnlockDevice(device);
2234 ALContext->next = g_pContextList;
2235 g_pContextList = ALContext;
2236 g_ulContextCount++;
2238 UnlockLists();
2240 return ALContext;
2245 alcDestroyContext
2247 Remove a Context
2249 ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
2251 ALCdevice *Device;
2252 ALCcontext **list;
2253 ALuint i;
2255 LockLists();
2256 list = &g_pContextList;
2257 while(*list && *list != context)
2258 list = &(*list)->next;
2260 if(!*list)
2262 alcSetError(NULL, ALC_INVALID_CONTEXT);
2263 UnlockLists();
2264 return;
2267 *list = (*list)->next;
2268 g_ulContextCount--;
2270 if(context == tls_get(LocalContext))
2271 tls_set(LocalContext, NULL);
2272 if(context == GlobalContext)
2273 GlobalContext = NULL;
2275 Device = context->Device;
2276 LockDevice(Device);
2277 for(i = 0;i < Device->NumContexts;i++)
2279 if(Device->Contexts[i] == context)
2281 Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
2282 Device->NumContexts--;
2283 break;
2286 UnlockDevice(Device);
2288 if(Device->NumContexts == 0)
2290 ALCdevice_StopPlayback(Device);
2291 Device->Flags &= ~DEVICE_RUNNING;
2293 UnlockLists();
2295 if(context->SourceMap.size > 0)
2297 ERR("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size);
2298 ReleaseALSources(context);
2300 ResetUIntMap(&context->SourceMap);
2302 if(context->EffectSlotMap.size > 0)
2304 ERR("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size);
2305 ReleaseALAuxiliaryEffectSlots(context);
2307 ResetUIntMap(&context->EffectSlotMap);
2309 free(context->ActiveSources);
2310 context->ActiveSources = NULL;
2311 context->MaxActiveSources = 0;
2312 context->ActiveSourceCount = 0;
2314 ExitContext(context);
2316 memset(context, 0, sizeof(ALCcontext));
2317 free(context);
2322 alcGetCurrentContext
2324 Returns the currently active Context
2326 ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
2328 ALCcontext *Context;
2330 LockLists();
2331 Context = tls_get(LocalContext);
2332 if(Context && !IsContext(Context))
2334 tls_set(LocalContext, NULL);
2335 Context = NULL;
2337 if(!Context)
2338 Context = GlobalContext;
2339 UnlockLists();
2341 return Context;
2345 alcGetThreadContext
2347 Returns the currently active thread-local Context
2349 ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
2351 ALCcontext *pContext = NULL;
2353 LockLists();
2355 pContext = tls_get(LocalContext);
2356 if(pContext && !IsContext(pContext))
2358 tls_set(LocalContext, NULL);
2359 pContext = NULL;
2362 UnlockLists();
2364 return pContext;
2369 alcGetContextsDevice
2371 Returns the Device that a particular Context is attached to
2373 ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
2375 ALCdevice *pDevice = NULL;
2377 LockLists();
2378 if(IsContext(pContext))
2379 pDevice = pContext->Device;
2380 else
2381 alcSetError(NULL, ALC_INVALID_CONTEXT);
2382 UnlockLists();
2384 return pDevice;
2389 alcMakeContextCurrent
2391 Makes the given Context the active Context
2393 ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
2395 ALboolean bReturn = AL_TRUE;
2397 LockLists();
2399 // context must be a valid Context or NULL
2400 if(context == NULL || IsContext(context))
2402 GlobalContext = context;
2403 tls_set(LocalContext, NULL);
2405 else
2407 alcSetError(NULL, ALC_INVALID_CONTEXT);
2408 bReturn = AL_FALSE;
2411 UnlockLists();
2413 return bReturn;
2417 alcSetThreadContext
2419 Makes the given Context the active Context for the current thread
2421 ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
2423 ALboolean bReturn = AL_TRUE;
2425 LockLists();
2427 // context must be a valid Context or NULL
2428 if(context == NULL || IsContext(context))
2429 tls_set(LocalContext, context);
2430 else
2432 alcSetError(NULL, ALC_INVALID_CONTEXT);
2433 bReturn = AL_FALSE;
2436 UnlockLists();
2438 return bReturn;
2442 // Sets the default channel order used by most non-WaveFormatEx-based APIs
2443 void SetDefaultChannelOrder(ALCdevice *device)
2445 switch(device->FmtChans)
2447 case DevFmtX51: device->DevChannels[0] = FRONT_LEFT;
2448 device->DevChannels[1] = FRONT_RIGHT;
2449 device->DevChannels[2] = BACK_LEFT;
2450 device->DevChannels[3] = BACK_RIGHT;
2451 device->DevChannels[4] = FRONT_CENTER;
2452 device->DevChannels[5] = LFE;
2453 return;
2455 case DevFmtX71: device->DevChannels[0] = FRONT_LEFT;
2456 device->DevChannels[1] = FRONT_RIGHT;
2457 device->DevChannels[2] = BACK_LEFT;
2458 device->DevChannels[3] = BACK_RIGHT;
2459 device->DevChannels[4] = FRONT_CENTER;
2460 device->DevChannels[5] = LFE;
2461 device->DevChannels[6] = SIDE_LEFT;
2462 device->DevChannels[7] = SIDE_RIGHT;
2463 return;
2465 /* Same as WFX order */
2466 case DevFmtMono:
2467 case DevFmtStereo:
2468 case DevFmtQuad:
2469 case DevFmtX51Side:
2470 case DevFmtX61:
2471 break;
2473 SetDefaultWFXChannelOrder(device);
2475 // Sets the default order used by WaveFormatEx
2476 void SetDefaultWFXChannelOrder(ALCdevice *device)
2478 switch(device->FmtChans)
2480 case DevFmtMono: device->DevChannels[0] = FRONT_CENTER; break;
2482 case DevFmtStereo: device->DevChannels[0] = FRONT_LEFT;
2483 device->DevChannels[1] = FRONT_RIGHT; break;
2485 case DevFmtQuad: device->DevChannels[0] = FRONT_LEFT;
2486 device->DevChannels[1] = FRONT_RIGHT;
2487 device->DevChannels[2] = BACK_LEFT;
2488 device->DevChannels[3] = BACK_RIGHT; break;
2490 case DevFmtX51: device->DevChannels[0] = FRONT_LEFT;
2491 device->DevChannels[1] = FRONT_RIGHT;
2492 device->DevChannels[2] = FRONT_CENTER;
2493 device->DevChannels[3] = LFE;
2494 device->DevChannels[4] = BACK_LEFT;
2495 device->DevChannels[5] = BACK_RIGHT; break;
2497 case DevFmtX51Side: device->DevChannels[0] = FRONT_LEFT;
2498 device->DevChannels[1] = FRONT_RIGHT;
2499 device->DevChannels[2] = FRONT_CENTER;
2500 device->DevChannels[3] = LFE;
2501 device->DevChannels[4] = SIDE_LEFT;
2502 device->DevChannels[5] = SIDE_RIGHT; break;
2504 case DevFmtX61: device->DevChannels[0] = FRONT_LEFT;
2505 device->DevChannels[1] = FRONT_RIGHT;
2506 device->DevChannels[2] = FRONT_CENTER;
2507 device->DevChannels[3] = LFE;
2508 device->DevChannels[4] = BACK_CENTER;
2509 device->DevChannels[5] = SIDE_LEFT;
2510 device->DevChannels[6] = SIDE_RIGHT; break;
2512 case DevFmtX71: device->DevChannels[0] = FRONT_LEFT;
2513 device->DevChannels[1] = FRONT_RIGHT;
2514 device->DevChannels[2] = FRONT_CENTER;
2515 device->DevChannels[3] = LFE;
2516 device->DevChannels[4] = BACK_LEFT;
2517 device->DevChannels[5] = BACK_RIGHT;
2518 device->DevChannels[6] = SIDE_LEFT;
2519 device->DevChannels[7] = SIDE_RIGHT; break;
2523 static void GetFormatFromString(const char *str, enum DevFmtChannels *chans, enum DevFmtType *type)
2525 if(strcasecmp(str, "AL_FORMAT_MONO32") == 0)
2527 *chans = DevFmtMono;
2528 *type = DevFmtFloat;
2529 return;
2531 if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0)
2533 *chans = DevFmtStereo;
2534 *type = DevFmtFloat;
2535 return;
2537 if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0)
2539 *chans = DevFmtQuad;
2540 *type = DevFmtFloat;
2541 return;
2543 if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0)
2545 *chans = DevFmtX51;
2546 *type = DevFmtFloat;
2547 return;
2549 if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0)
2551 *chans = DevFmtX61;
2552 *type = DevFmtFloat;
2553 return;
2555 if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0)
2557 *chans = DevFmtX71;
2558 *type = DevFmtFloat;
2559 return;
2562 if(strcasecmp(str, "AL_FORMAT_MONO16") == 0)
2564 *chans = DevFmtMono;
2565 *type = DevFmtShort;
2566 return;
2568 if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0)
2570 *chans = DevFmtStereo;
2571 *type = DevFmtShort;
2572 return;
2574 if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0)
2576 *chans = DevFmtQuad;
2577 *type = DevFmtShort;
2578 return;
2580 if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0)
2582 *chans = DevFmtX51;
2583 *type = DevFmtShort;
2584 return;
2586 if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0)
2588 *chans = DevFmtX61;
2589 *type = DevFmtShort;
2590 return;
2592 if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0)
2594 *chans = DevFmtX71;
2595 *type = DevFmtShort;
2596 return;
2599 if(strcasecmp(str, "AL_FORMAT_MONO8") == 0)
2601 *chans = DevFmtMono;
2602 *type = DevFmtByte;
2603 return;
2605 if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0)
2607 *chans = DevFmtStereo;
2608 *type = DevFmtByte;
2609 return;
2611 if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0)
2613 *chans = DevFmtQuad;
2614 *type = DevFmtByte;
2615 return;
2617 if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0)
2619 *chans = DevFmtX51;
2620 *type = DevFmtByte;
2621 return;
2623 if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0)
2625 *chans = DevFmtX61;
2626 *type = DevFmtByte;
2627 return;
2629 if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0)
2631 *chans = DevFmtX71;
2632 *type = DevFmtByte;
2633 return;
2636 ERR("Unknown format: \"%s\"\n", str);
2637 *chans = DevFmtStereo;
2638 *type = DevFmtShort;
2642 alcOpenDevice
2644 Open the Device specified.
2646 ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
2648 ALboolean bDeviceFound = AL_FALSE;
2649 const ALCchar *fmt;
2650 ALCdevice *device;
2651 ALint i;
2653 DO_INITCONFIG();
2655 if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0))
2656 deviceName = NULL;
2658 device = calloc(1, sizeof(ALCdevice));
2659 if(!device)
2661 alcSetError(NULL, ALC_OUT_OF_MEMORY);
2662 return NULL;
2665 //Validate device
2666 device->Connected = ALC_TRUE;
2667 device->IsCaptureDevice = AL_FALSE;
2668 device->IsLoopbackDevice = AL_FALSE;
2669 InitializeCriticalSection(&device->Mutex);
2670 device->LastError = ALC_NO_ERROR;
2672 device->Flags = 0;
2673 device->Bs2b = NULL;
2674 device->szDeviceName = NULL;
2676 device->Contexts = NULL;
2677 device->NumContexts = 0;
2679 InitUIntMap(&device->BufferMap);
2680 InitUIntMap(&device->EffectMap);
2681 InitUIntMap(&device->FilterMap);
2683 //Set output format
2684 if(ConfigValueExists(NULL, "frequency"))
2685 device->Flags |= DEVICE_FREQUENCY_REQUEST;
2686 device->Frequency = GetConfigValueInt(NULL, "frequency", DEFAULT_OUTPUT_RATE);
2687 if(device->Frequency < 8000)
2688 device->Frequency = 8000;
2690 if(ConfigValueExists(NULL, "format"))
2691 device->Flags |= DEVICE_CHANNELS_REQUEST;
2692 fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
2693 GetFormatFromString(fmt, &device->FmtChans, &device->FmtType);
2695 device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
2696 if(device->NumUpdates < 2)
2697 device->NumUpdates = 4;
2699 device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024);
2700 if(device->UpdateSize <= 0)
2701 device->UpdateSize = 1024;
2703 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
2704 if(device->MaxNoOfSources <= 0)
2705 device->MaxNoOfSources = 256;
2707 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
2708 if(device->AuxiliaryEffectSlotMax <= 0)
2709 device->AuxiliaryEffectSlotMax = 4;
2711 device->NumStereoSources = 1;
2712 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
2714 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
2715 if(device->NumAuxSends > MAX_SENDS)
2716 device->NumAuxSends = MAX_SENDS;
2718 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
2720 // Find a playback device to open
2721 LockLists();
2722 for(i = 0;BackendList[i].Init;i++)
2724 device->Funcs = &BackendList[i].Funcs;
2725 if(ALCdevice_OpenPlayback(device, deviceName))
2727 device->next = g_pDeviceList;
2728 g_pDeviceList = device;
2729 g_ulDeviceCount++;
2731 bDeviceFound = AL_TRUE;
2732 break;
2735 UnlockLists();
2737 if(!bDeviceFound)
2739 // No suitable output device found
2740 alcSetError(NULL, ALC_INVALID_VALUE);
2741 free(device);
2742 device = NULL;
2745 return device;
2750 alcCloseDevice
2752 Close the specified Device
2754 ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
2756 ALCdevice **list;
2758 LockLists();
2759 list = &g_pDeviceList;
2760 while(*list && *list != pDevice)
2761 list = &(*list)->next;
2763 if(!*list || (*list)->IsCaptureDevice)
2765 alcSetError(*list, ALC_INVALID_DEVICE);
2766 UnlockLists();
2767 return ALC_FALSE;
2770 *list = (*list)->next;
2771 g_ulDeviceCount--;
2773 UnlockLists();
2775 if(pDevice->NumContexts > 0)
2777 WARN("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
2778 while(pDevice->NumContexts > 0)
2779 alcDestroyContext(pDevice->Contexts[0]);
2781 ALCdevice_ClosePlayback(pDevice);
2783 if(pDevice->BufferMap.size > 0)
2785 WARN("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferMap.size);
2786 ReleaseALBuffers(pDevice);
2788 ResetUIntMap(&pDevice->BufferMap);
2790 if(pDevice->EffectMap.size > 0)
2792 WARN("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size);
2793 ReleaseALEffects(pDevice);
2795 ResetUIntMap(&pDevice->EffectMap);
2797 if(pDevice->FilterMap.size > 0)
2799 WARN("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size);
2800 ReleaseALFilters(pDevice);
2802 ResetUIntMap(&pDevice->FilterMap);
2804 free(pDevice->Bs2b);
2805 pDevice->Bs2b = NULL;
2807 free(pDevice->szDeviceName);
2808 pDevice->szDeviceName = NULL;
2810 free(pDevice->Contexts);
2811 pDevice->Contexts = NULL;
2813 DeleteCriticalSection(&pDevice->Mutex);
2815 //Release device structure
2816 memset(pDevice, 0, sizeof(ALCdevice));
2817 free(pDevice);
2819 return ALC_TRUE;
2823 ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
2825 ALCdevice *device;
2827 DO_INITCONFIG();
2829 device = calloc(1, sizeof(ALCdevice));
2830 if(!device)
2832 alcSetError(NULL, ALC_OUT_OF_MEMORY);
2833 return NULL;
2836 //Validate device
2837 device->Connected = ALC_TRUE;
2838 device->IsCaptureDevice = AL_FALSE;
2839 device->IsLoopbackDevice = AL_TRUE;
2840 InitializeCriticalSection(&device->Mutex);
2841 device->LastError = ALC_NO_ERROR;
2843 device->Flags = 0;
2844 device->Bs2b = NULL;
2845 device->szDeviceName = NULL;
2847 device->Contexts = NULL;
2848 device->NumContexts = 0;
2850 InitUIntMap(&device->BufferMap);
2851 InitUIntMap(&device->EffectMap);
2852 InitUIntMap(&device->FilterMap);
2854 //Set output format
2855 device->Frequency = 44100;
2856 device->FmtChans = DevFmtStereo;
2857 device->FmtType = DevFmtShort;
2859 device->NumUpdates = 0;
2860 device->UpdateSize = 0;
2862 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
2863 if(device->MaxNoOfSources <= 0)
2864 device->MaxNoOfSources = 256;
2866 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
2867 if(device->AuxiliaryEffectSlotMax <= 0)
2868 device->AuxiliaryEffectSlotMax = 4;
2870 device->NumStereoSources = 1;
2871 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
2873 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
2874 if(device->NumAuxSends > MAX_SENDS)
2875 device->NumAuxSends = MAX_SENDS;
2877 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
2879 // Open the "backend"
2880 LockLists();
2881 device->Funcs = &BackendLoopback.Funcs;
2882 ALCdevice_OpenPlayback(device, "Loopback");
2884 device->next = g_pDeviceList;
2885 g_pDeviceList = device;
2886 g_ulDeviceCount++;
2887 UnlockLists();
2889 return device;
2892 ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type)
2894 ALCboolean ret = ALC_FALSE;
2896 LockLists();
2897 if(!IsDevice(device) || !device->IsLoopbackDevice)
2898 alcSetError(device, ALC_INVALID_DEVICE);
2899 else if(freq <= 0)
2900 alcSetError(device, ALC_INVALID_VALUE);
2901 else if(!IsValidALCType(type) || !IsValidALCChannels(channels))
2902 alcSetError(device, ALC_INVALID_ENUM);
2903 else
2905 if(BytesFromDevFmt(type) > 0 && ChannelsFromDevFmt(channels) > 0 &&
2906 freq >= 8000)
2907 ret = ALC_TRUE;
2909 UnlockLists();
2911 return ret;
2914 ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
2916 LockLists();
2917 if(!IsDevice(device) || !device->IsLoopbackDevice)
2918 alcSetError(device, ALC_INVALID_DEVICE);
2919 else if(samples < 0)
2920 alcSetError(device, ALC_INVALID_VALUE);
2921 else
2922 aluMixData(device, buffer, samples);
2923 UnlockLists();
2927 static void ReleaseALC(void)
2929 free(alcDeviceList); alcDeviceList = NULL;
2930 alcDeviceListSize = 0;
2931 free(alcAllDeviceList); alcAllDeviceList = NULL;
2932 alcAllDeviceListSize = 0;
2933 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
2934 alcCaptureDeviceListSize = 0;
2936 free(alcDefaultDeviceSpecifier);
2937 alcDefaultDeviceSpecifier = NULL;
2938 free(alcDefaultAllDeviceSpecifier);
2939 alcDefaultAllDeviceSpecifier = NULL;
2940 free(alcCaptureDefaultDeviceSpecifier);
2941 alcCaptureDefaultDeviceSpecifier = NULL;
2943 if(g_ulDeviceCount > 0)
2944 WARN("ReleaseALC(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
2946 while(g_pDeviceList)
2948 if(g_pDeviceList->IsCaptureDevice)
2949 alcCaptureCloseDevice(g_pDeviceList);
2950 else
2951 alcCloseDevice(g_pDeviceList);
2955 ///////////////////////////////////////////////////////