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
36 #include "alAuxEffectSlot.h"
37 #include "alDatabuffer.h"
42 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
43 typedef struct BackendInfo
{
45 void (*Init
)(BackendFuncs
*);
50 static BackendInfo BackendList
[] = {
51 #ifdef HAVE_PULSEAUDIO
52 { "pulse", alc_pulse_init
, alc_pulse_deinit
, alc_pulse_probe
, EmptyFuncs
},
55 { "alsa", alc_alsa_init
, alc_alsa_deinit
, alc_alsa_probe
, EmptyFuncs
},
58 { "oss", alc_oss_init
, alc_oss_deinit
, alc_oss_probe
, EmptyFuncs
},
61 { "solaris", alc_solaris_init
, alc_solaris_deinit
, alc_solaris_probe
, EmptyFuncs
},
64 { "dsound", alcDSoundInit
, alcDSoundDeinit
, alcDSoundProbe
, EmptyFuncs
},
67 { "winmm", alcWinMMInit
, alcWinMMDeinit
, alcWinMMProbe
, EmptyFuncs
},
70 { "port", alc_pa_init
, alc_pa_deinit
, alc_pa_probe
, EmptyFuncs
},
73 { "null", alc_null_init
, alc_null_deinit
, alc_null_probe
, EmptyFuncs
},
75 { "wave", alc_wave_init
, alc_wave_deinit
, alc_wave_probe
, EmptyFuncs
},
78 { NULL
, NULL
, NULL
, NULL
, 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
;
96 typedef struct ALCenums
{
97 const ALCchar
*enumName
;
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 { "alBufferSubDataSOFT", (ALCvoid
*) alBufferSubDataSOFT
},
239 { "alGenDatabuffersEXT", (ALCvoid
*) alGenDatabuffersEXT
},
240 { "alDeleteDatabuffersEXT", (ALCvoid
*) alDeleteDatabuffersEXT
},
241 { "alIsDatabufferEXT", (ALCvoid
*) alIsDatabufferEXT
},
242 { "alDatabufferDataEXT", (ALCvoid
*) alDatabufferDataEXT
},
243 { "alDatabufferSubDataEXT", (ALCvoid
*) alDatabufferSubDataEXT
},
244 { "alGetDatabufferSubDataEXT", (ALCvoid
*) alGetDatabufferSubDataEXT
},
245 { "alDatabufferfEXT", (ALCvoid
*) alDatabufferfEXT
},
246 { "alDatabufferfvEXT", (ALCvoid
*) alDatabufferfvEXT
},
247 { "alDatabufferiEXT", (ALCvoid
*) alDatabufferiEXT
},
248 { "alDatabufferivEXT", (ALCvoid
*) alDatabufferivEXT
},
249 { "alGetDatabufferfEXT", (ALCvoid
*) alGetDatabufferfEXT
},
250 { "alGetDatabufferfvEXT", (ALCvoid
*) alGetDatabufferfvEXT
},
251 { "alGetDatabufferiEXT", (ALCvoid
*) alGetDatabufferiEXT
},
252 { "alGetDatabufferivEXT", (ALCvoid
*) alGetDatabufferivEXT
},
253 { "alSelectDatabufferEXT", (ALCvoid
*) alSelectDatabufferEXT
},
254 { "alMapDatabufferEXT", (ALCvoid
*) alMapDatabufferEXT
},
255 { "alUnmapDatabufferEXT", (ALCvoid
*) alUnmapDatabufferEXT
},
257 { NULL
, (ALCvoid
*) NULL
}
260 static const ALCenums enumeration
[] = {
262 { "ALC_INVALID", ALC_INVALID
},
263 { "ALC_FALSE", ALC_FALSE
},
264 { "ALC_TRUE", ALC_TRUE
},
267 { "ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
268 { "ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
269 { "ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
270 { "ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
271 { "ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
272 { "ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
273 { "ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
274 { "ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
275 { "ALC_EXTENSIONS", ALC_EXTENSIONS
},
276 { "ALC_FREQUENCY", ALC_FREQUENCY
},
277 { "ALC_REFRESH", ALC_REFRESH
},
278 { "ALC_SYNC", ALC_SYNC
},
279 { "ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
280 { "ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
281 { "ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
282 { "ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
283 { "ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
284 { "ALC_CONNECTED", ALC_CONNECTED
},
287 { "ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
288 { "ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
289 { "ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
292 { "ALC_NO_ERROR", ALC_NO_ERROR
},
293 { "ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
294 { "ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
295 { "ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
296 { "ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
297 { "ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
301 static const ALCchar alcNoError
[] = "No Error";
302 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
303 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
304 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
305 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
306 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
308 /* Device lists. Sizes only include the first ending null character, not the
310 static ALCchar
*alcDeviceList
;
311 static size_t alcDeviceListSize
;
312 static ALCchar
*alcAllDeviceList
;
313 static size_t alcAllDeviceListSize
;
314 static ALCchar
*alcCaptureDeviceList
;
315 static size_t alcCaptureDeviceListSize
;
316 // Default is always the first in the list
317 static ALCchar
*alcDefaultDeviceSpecifier
;
318 static ALCchar
*alcDefaultAllDeviceSpecifier
;
319 static ALCchar
*alcCaptureDefaultDeviceSpecifier
;
322 static const ALCchar alcNoDeviceExtList
[] =
323 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
324 "ALC_EXT_thread_local_context";
325 static const ALCchar alcExtensionList
[] =
326 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
327 "ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context";
328 static const ALCint alcMajorVersion
= 1;
329 static const ALCint alcMinorVersion
= 1;
331 static const ALCint alcEFXMajorVersion
= 1;
332 static const ALCint alcEFXMinorVersion
= 0;
334 ///////////////////////////////////////////////////////
337 ///////////////////////////////////////////////////////
340 static ALCdevice
*g_pDeviceList
= NULL
;
341 static ALCuint g_ulDeviceCount
= 0;
343 static CRITICAL_SECTION g_csMutex
;
346 static ALCcontext
*g_pContextList
= NULL
;
347 static ALCuint g_ulContextCount
= 0;
349 // Thread-local current context
350 static tls_type LocalContext
;
351 // Process-wide current context
352 static ALCcontext
*GlobalContext
;
355 static ALCenum g_eLastNullDeviceError
= ALC_NO_ERROR
;
357 // Default context extensions
358 static const ALchar alExtList
[] =
359 "AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 "
360 "AL_EXT_LINEAR_DISTANCE AL_EXTX_loop_points AL_EXT_MCFORMATS AL_EXT_MULAW "
361 "AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model "
362 "AL_LOKI_quadriphonic AL_SOFT_buffer_sub_data";
364 // Mixing Priority Level
365 static ALint RTPrioLevel
;
368 static FILE *LogFile
;
370 ///////////////////////////////////////////////////////
373 ///////////////////////////////////////////////////////
374 // ALC Related helper functions
375 static void ReleaseALC(void);
377 #ifdef HAVE_GCC_DESTRUCTOR
378 static void alc_init(void) __attribute__((constructor
));
379 static void alc_deinit(void) __attribute__((destructor
));
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
)
389 // Perform actions based on the reason for calling.
390 switch(ul_reason_for_call
)
392 case DLL_PROCESS_ATTACH
:
393 DisableThreadLibraryCalls(hModule
);
397 case DLL_PROCESS_DETACH
:
406 static void alc_init(void)
409 const char *devs
, *str
;
411 str
= getenv("ALSOFT_LOGFILE");
414 LogFile
= fopen(str
, "w");
416 fprintf(stderr
, "AL lib: Failed to open log file '%s'\n", str
);
421 InitializeCriticalSection(&g_csMutex
);
425 tls_create(&LocalContext
);
427 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
429 DefaultResampler
= GetConfigValueInt(NULL
, "resampler", RESAMPLER_DEFAULT
);
430 if(DefaultResampler
>= RESAMPLER_MAX
|| DefaultResampler
<= RESAMPLER_MIN
)
431 DefaultResampler
= RESAMPLER_DEFAULT
;
433 devs
= GetConfigValue(NULL
, "drivers", "");
438 const char *next
= devs
;
439 int endlist
, delitem
;
444 next
= strchr(devs
, ',');
446 delitem
= (devs
[0] == '-');
447 if(devs
[0] == '-') devs
++;
449 if(!devs
[0] || devs
[0] == ',')
456 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
457 for(n
= i
;BackendList
[n
].Init
;n
++)
459 if(len
== strlen(BackendList
[n
].name
) &&
460 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
465 BackendList
[n
] = BackendList
[n
+1];
467 } while(BackendList
[n
].Init
);
471 BackendInfo Bkp
= BackendList
[n
];
474 BackendList
[n
] = BackendList
[n
-1];
477 BackendList
[n
] = Bkp
;
488 BackendList
[i
].name
= NULL
;
489 BackendList
[i
].Init
= NULL
;
490 BackendList
[i
].Deinit
= NULL
;
491 BackendList
[i
].Probe
= NULL
;
495 for(i
= 0;BackendList
[i
].Init
;i
++)
496 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
498 str
= GetConfigValue(NULL
, "excludefx", "");
505 { "eaxreverb", EAXREVERB
},
506 { "reverb", REVERB
},
508 { "modulator", MODULATOR
},
513 const char *next
= str
;
517 next
= strchr(str
, ',');
519 if(!str
[0] || next
== str
)
522 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
523 for(n
= 0;EffectList
[n
].name
;n
++)
525 if(len
== strlen(EffectList
[n
].name
) &&
526 strncmp(EffectList
[n
].name
, str
, len
) == 0)
527 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
533 static void alc_deinit(void)
539 for(i
= 0;BackendList
[i
].Deinit
;i
++)
540 BackendList
[i
].Deinit();
542 tls_delete(LocalContext
);
546 DeleteCriticalSection(&g_csMutex
);
548 if(LogFile
!= stderr
)
554 static void ProbeDeviceList()
558 free(alcDeviceList
); alcDeviceList
= NULL
;
559 alcDeviceListSize
= 0;
561 for(i
= 0;BackendList
[i
].Probe
;i
++)
562 BackendList
[i
].Probe(DEVICE_PROBE
);
565 static void ProbeAllDeviceList()
569 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
570 alcAllDeviceListSize
= 0;
572 for(i
= 0;BackendList
[i
].Probe
;i
++)
573 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
576 static void ProbeCaptureDeviceList()
580 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
581 alcCaptureDeviceListSize
= 0;
583 for(i
= 0;BackendList
[i
].Probe
;i
++)
584 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
588 #define DECL_APPEND_LIST_FUNC(type) \
589 void Append##type##List(const ALCchar *name) \
591 size_t len = strlen(name); \
597 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
600 AL_PRINT("Realloc failed to add %s!\n", name); \
603 alc##type##List = temp; \
604 memcpy(alc##type##List+alc##type##ListSize, name, len+1); \
605 alc##type##ListSize += len+1; \
606 alc##type##List[alc##type##ListSize] = 0; \
609 DECL_APPEND_LIST_FUNC(Device
)
610 DECL_APPEND_LIST_FUNC(AllDevice
)
611 DECL_APPEND_LIST_FUNC(CaptureDevice
)
614 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
620 fn
= strrchr(fname
, '/');
621 if(!fn
) fn
= strrchr(fname
, '\\');;
625 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
626 if(i
< (int)sizeof(str
) && i
> 0)
630 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
633 str
[sizeof(str
)-1] = 0;
635 fprintf(LogFile
, "%s", str
);
639 void SetRTPriority(void)
645 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
647 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
648 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
649 struct sched_param param
;
653 /* Use the minimum real-time priority possible for now (on Linux this
654 * should be 1 for SCHED_RR) */
655 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
656 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
660 param
.sched_priority
= 0;
661 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
664 /* Real-time priority not available */
665 failed
= (RTPrioLevel
>0);
668 AL_PRINT("Failed to set priority level for thread\n");
672 void InitUIntMap(UIntMap
*map
)
679 void ResetUIntMap(UIntMap
*map
)
687 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
)
694 ALsizei high
= map
->size
- 1;
697 ALsizei mid
= low
+ (high
-low
)/2;
698 if(map
->array
[mid
].key
< key
)
703 if(map
->array
[low
].key
< key
)
708 if(pos
== map
->size
|| map
->array
[pos
].key
!= key
)
710 if(map
->size
== map
->maxsize
)
715 newsize
= (map
->maxsize
? (map
->maxsize
<<1) : 4);
716 if(newsize
< map
->maxsize
)
717 return AL_OUT_OF_MEMORY
;
719 temp
= realloc(map
->array
, newsize
*sizeof(map
->array
[0]));
720 if(!temp
) return AL_OUT_OF_MEMORY
;
722 map
->maxsize
= newsize
;
726 if(pos
< map
->size
-1)
727 memmove(&map
->array
[pos
+1], &map
->array
[pos
],
728 (map
->size
-1-pos
)*sizeof(map
->array
[0]));
730 map
->array
[pos
].key
= key
;
731 map
->array
[pos
].value
= value
;
736 void RemoveUIntMapKey(UIntMap
*map
, ALuint key
)
741 ALsizei high
= map
->size
- 1;
744 ALsizei mid
= low
+ (high
-low
)/2;
745 if(map
->array
[mid
].key
< key
)
750 if(map
->array
[low
].key
== key
)
752 if(low
< map
->size
-1)
753 memmove(&map
->array
[low
], &map
->array
[low
+1],
754 (map
->size
-1-low
)*sizeof(map
->array
[0]));
760 ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
)
765 ALsizei high
= map
->size
- 1;
768 ALsizei mid
= low
+ (high
-low
)/2;
769 if(map
->array
[mid
].key
< key
)
774 if(map
->array
[low
].key
== key
)
775 return map
->array
[low
].value
;
781 ALuint
BytesFromDevFmt(enum DevFmtType type
)
785 case DevFmtByte
: return sizeof(ALbyte
);
786 case DevFmtUByte
: return sizeof(ALubyte
);
787 case DevFmtShort
: return sizeof(ALshort
);
788 case DevFmtUShort
: return sizeof(ALushort
);
789 case DevFmtFloat
: return sizeof(ALfloat
);
793 ALuint
ChannelsFromDevFmt(enum DevFmtChannels chans
)
797 case DevFmtMono
: return 1;
798 case DevFmtStereo
: return 2;
799 case DevFmtQuad
: return 4;
800 case DevFmtX51
: return 6;
801 case DevFmtX61
: return 7;
802 case DevFmtX71
: return 8;
806 ALboolean
DecomposeDevFormat(ALenum format
, enum DevFmtChannels
*chans
,
807 enum DevFmtType
*type
)
811 case AL_FORMAT_MONO8
:
815 case AL_FORMAT_MONO16
:
819 case AL_FORMAT_MONO_FLOAT32
:
823 case AL_FORMAT_STEREO8
:
824 *chans
= DevFmtStereo
;
827 case AL_FORMAT_STEREO16
:
828 *chans
= DevFmtStereo
;
831 case AL_FORMAT_STEREO_FLOAT32
:
832 *chans
= DevFmtStereo
;
835 case AL_FORMAT_QUAD8
:
839 case AL_FORMAT_QUAD16
:
843 case AL_FORMAT_QUAD32
:
847 case AL_FORMAT_51CHN8
:
851 case AL_FORMAT_51CHN16
:
855 case AL_FORMAT_51CHN32
:
859 case AL_FORMAT_61CHN8
:
863 case AL_FORMAT_61CHN16
:
867 case AL_FORMAT_61CHN32
:
871 case AL_FORMAT_71CHN8
:
875 case AL_FORMAT_71CHN16
:
879 case AL_FORMAT_71CHN32
:
890 Check pDevice is a valid Device pointer
892 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
894 ALCdevice
*pTempDevice
;
896 SuspendContext(NULL
);
898 pTempDevice
= g_pDeviceList
;
899 while(pTempDevice
&& pTempDevice
!= pDevice
)
900 pTempDevice
= pTempDevice
->next
;
902 ProcessContext(NULL
);
904 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
910 Check pContext is a valid Context pointer
912 static ALCboolean
IsContext(ALCcontext
*pContext
)
914 ALCcontext
*pTempContext
;
916 SuspendContext(NULL
);
918 pTempContext
= g_pContextList
;
919 while (pTempContext
&& pTempContext
!= pContext
)
920 pTempContext
= pTempContext
->next
;
922 ProcessContext(NULL
);
924 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
931 Store latest ALC Error
933 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
936 device
->LastError
= errorCode
;
938 g_eLastNullDeviceError
= errorCode
;
942 /* UpdateDeviceParams:
944 * Updates device parameters according to the attribute list.
946 static ALCboolean
UpdateDeviceParams(ALCdevice
*device
, const ALCint
*attrList
)
948 ALCuint freq
, numMono
, numStereo
, numSends
;
954 running
= ((device
->NumContexts
> 0) ? AL_TRUE
: AL_FALSE
);
955 oldRate
= device
->Frequency
;
957 // Check for attributes
958 if(attrList
&& attrList
[0])
960 // If a context is already running on the device, stop playback so the
961 // device attributes can be updated
964 ProcessContext(NULL
);
965 ALCdevice_StopPlayback(device
);
966 SuspendContext(NULL
);
970 freq
= device
->Frequency
;
971 numMono
= device
->NumMonoSources
;
972 numStereo
= device
->NumStereoSources
;
973 numSends
= device
->NumAuxSends
;
976 while(attrList
[attrIdx
])
978 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
979 !ConfigValueExists(NULL
, "frequency"))
981 freq
= attrList
[attrIdx
+ 1];
986 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
988 numStereo
= attrList
[attrIdx
+ 1];
989 if(numStereo
> device
->MaxNoOfSources
)
990 numStereo
= device
->MaxNoOfSources
;
992 numMono
= device
->MaxNoOfSources
- numStereo
;
995 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
996 !ConfigValueExists(NULL
, "sends"))
998 numSends
= attrList
[attrIdx
+ 1];
999 if(numSends
> MAX_SENDS
)
1000 numSends
= MAX_SENDS
;
1006 device
->UpdateSize
= (ALuint64
)device
->UpdateSize
* freq
/
1009 device
->Frequency
= freq
;
1010 device
->NumMonoSources
= numMono
;
1011 device
->NumStereoSources
= numStereo
;
1012 device
->NumAuxSends
= numSends
;
1018 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1021 aluInitPanning(device
);
1023 for(i
= 0;i
< MAXCHANNELS
;i
++)
1025 device
->ClickRemoval
[i
] = 0.0f
;
1026 device
->PendingClicks
[i
] = 0.0f
;
1029 for(i
= 0;i
< device
->NumContexts
;i
++)
1031 ALCcontext
*context
= device
->Contexts
[i
];
1034 SuspendContext(context
);
1035 for(pos
= 0;pos
< context
->EffectSlotMap
.size
;pos
++)
1037 ALeffectslot
*slot
= context
->EffectSlotMap
.array
[pos
].value
;
1039 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1041 ProcessContext(context
);
1044 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1047 for(pos
= 0;pos
< context
->SourceMap
.size
;pos
++)
1049 ALsource
*source
= context
->SourceMap
.array
[pos
].value
;
1050 ALuint s
= device
->NumAuxSends
;
1051 while(s
< MAX_SENDS
)
1053 if(source
->Send
[s
].Slot
)
1054 source
->Send
[s
].Slot
->refcount
--;
1055 source
->Send
[s
].Slot
= NULL
;
1056 source
->Send
[s
].WetFilter
.type
= 0;
1057 source
->Send
[s
].WetFilter
.filter
= 0;
1060 source
->NeedsUpdate
= AL_TRUE
;
1062 ProcessContext(context
);
1065 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1069 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1070 bs2b_clear(device
->Bs2b
);
1072 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1073 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1078 device
->Bs2b
= NULL
;
1081 if(ChannelsFromDevFmt(device
->FmtChans
) <= 2)
1083 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1084 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1085 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1088 device
->HeadDampen
= 0.0f
;
1099 ALCvoid
SuspendContext(ALCcontext
*pContext
)
1102 EnterCriticalSection(&g_csMutex
);
1111 ALCvoid
ProcessContext(ALCcontext
*pContext
)
1114 LeaveCriticalSection(&g_csMutex
);
1121 Returns the currently active Context, in a locked state
1123 ALCcontext
*GetContextSuspended(void)
1125 ALCcontext
*pContext
= NULL
;
1127 SuspendContext(NULL
);
1129 pContext
= tls_get(LocalContext
);
1130 if(pContext
&& !IsContext(pContext
))
1132 tls_set(LocalContext
, NULL
);
1136 pContext
= GlobalContext
;
1139 SuspendContext(pContext
);
1141 ProcessContext(NULL
);
1150 Initialize Context variables
1152 static ALvoid
InitContext(ALCcontext
*pContext
)
1154 //Initialise listener
1155 pContext
->Listener
.Gain
= 1.0f
;
1156 pContext
->Listener
.MetersPerUnit
= 1.0f
;
1157 pContext
->Listener
.Position
[0] = 0.0f
;
1158 pContext
->Listener
.Position
[1] = 0.0f
;
1159 pContext
->Listener
.Position
[2] = 0.0f
;
1160 pContext
->Listener
.Velocity
[0] = 0.0f
;
1161 pContext
->Listener
.Velocity
[1] = 0.0f
;
1162 pContext
->Listener
.Velocity
[2] = 0.0f
;
1163 pContext
->Listener
.Forward
[0] = 0.0f
;
1164 pContext
->Listener
.Forward
[1] = 0.0f
;
1165 pContext
->Listener
.Forward
[2] = -1.0f
;
1166 pContext
->Listener
.Up
[0] = 0.0f
;
1167 pContext
->Listener
.Up
[1] = 1.0f
;
1168 pContext
->Listener
.Up
[2] = 0.0f
;
1171 pContext
->LastError
= AL_NO_ERROR
;
1172 pContext
->Suspended
= AL_FALSE
;
1173 pContext
->ActiveSourceCount
= 0;
1174 InitUIntMap(&pContext
->SourceMap
);
1175 InitUIntMap(&pContext
->EffectSlotMap
);
1178 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
1179 pContext
->SourceDistanceModel
= AL_FALSE
;
1180 pContext
->DopplerFactor
= 1.0f
;
1181 pContext
->DopplerVelocity
= 1.0f
;
1182 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
1184 pContext
->ExtensionList
= alExtList
;
1191 Clean up Context, destroy any remaining Sources
1193 static ALCvoid
ExitContext(ALCcontext
*pContext
)
1195 //Invalidate context
1196 pContext
->LastError
= AL_NO_ERROR
;
1199 ///////////////////////////////////////////////////////
1202 ///////////////////////////////////////////////////////
1203 // ALC Functions calls
1206 // This should probably move to another c file but for now ...
1207 ALC_API ALCdevice
* ALC_APIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
1209 ALCboolean DeviceFound
= ALC_FALSE
;
1210 ALCdevice
*device
= NULL
;
1215 alcSetError(NULL
, ALC_INVALID_VALUE
);
1219 if(deviceName
&& !deviceName
[0])
1222 device
= calloc(1, sizeof(ALCdevice
));
1225 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1230 device
->Connected
= ALC_TRUE
;
1231 device
->IsCaptureDevice
= AL_TRUE
;
1233 device
->szDeviceName
= NULL
;
1235 device
->Frequency
= frequency
;
1236 if(DecomposeDevFormat(format
, &device
->FmtChans
, &device
->FmtType
) == AL_FALSE
)
1239 alcSetError(NULL
, ALC_INVALID_ENUM
);
1243 device
->UpdateSize
= SampleSize
;
1244 device
->NumUpdates
= 1;
1246 SuspendContext(NULL
);
1247 for(i
= 0;BackendList
[i
].Init
;i
++)
1249 device
->Funcs
= &BackendList
[i
].Funcs
;
1250 if(ALCdevice_OpenCapture(device
, deviceName
))
1252 device
->next
= g_pDeviceList
;
1253 g_pDeviceList
= device
;
1256 DeviceFound
= ALC_TRUE
;
1260 ProcessContext(NULL
);
1264 alcSetError(NULL
, ALC_INVALID_VALUE
);
1272 ALC_API ALCboolean ALC_APIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
1276 if(!IsDevice(pDevice
) || !pDevice
->IsCaptureDevice
)
1278 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
1282 SuspendContext(NULL
);
1284 list
= &g_pDeviceList
;
1285 while(*list
!= pDevice
)
1286 list
= &(*list
)->next
;
1288 *list
= (*list
)->next
;
1291 ProcessContext(NULL
);
1293 ALCdevice_CloseCapture(pDevice
);
1295 free(pDevice
->szDeviceName
);
1296 pDevice
->szDeviceName
= NULL
;
1303 ALC_API
void ALC_APIENTRY
alcCaptureStart(ALCdevice
*device
)
1305 SuspendContext(NULL
);
1306 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
1307 alcSetError(device
, ALC_INVALID_DEVICE
);
1308 else if(device
->Connected
)
1309 ALCdevice_StartCapture(device
);
1310 ProcessContext(NULL
);
1313 ALC_API
void ALC_APIENTRY
alcCaptureStop(ALCdevice
*device
)
1315 SuspendContext(NULL
);
1316 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
1317 alcSetError(device
, ALC_INVALID_DEVICE
);
1319 ALCdevice_StopCapture(device
);
1320 ProcessContext(NULL
);
1323 ALC_API
void ALC_APIENTRY
alcCaptureSamples(ALCdevice
*device
, ALCvoid
*buffer
, ALCsizei samples
)
1325 SuspendContext(NULL
);
1326 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
1327 alcSetError(device
, ALC_INVALID_DEVICE
);
1329 ALCdevice_CaptureSamples(device
, buffer
, samples
);
1330 ProcessContext(NULL
);
1336 Return last ALC generated error code
1338 ALC_API ALCenum ALC_APIENTRY
alcGetError(ALCdevice
*device
)
1342 if(IsDevice(device
))
1344 errorCode
= device
->LastError
;
1345 device
->LastError
= ALC_NO_ERROR
;
1349 errorCode
= g_eLastNullDeviceError
;
1350 g_eLastNullDeviceError
= ALC_NO_ERROR
;
1361 ALC_API ALCvoid ALC_APIENTRY
alcSuspendContext(ALCcontext
*pContext
)
1363 SuspendContext(NULL
);
1364 if(IsContext(pContext
))
1365 pContext
->Suspended
= AL_TRUE
;
1366 ProcessContext(NULL
);
1375 ALC_API ALCvoid ALC_APIENTRY
alcProcessContext(ALCcontext
*pContext
)
1377 SuspendContext(NULL
);
1378 if(IsContext(pContext
))
1379 pContext
->Suspended
= AL_FALSE
;
1380 ProcessContext(NULL
);
1387 Returns information about the Device, and error strings
1389 ALC_API
const ALCchar
* ALC_APIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
1391 const ALCchar
*value
= NULL
;
1399 case ALC_INVALID_ENUM
:
1400 value
= alcErrInvalidEnum
;
1403 case ALC_INVALID_VALUE
:
1404 value
= alcErrInvalidValue
;
1407 case ALC_INVALID_DEVICE
:
1408 value
= alcErrInvalidDevice
;
1411 case ALC_INVALID_CONTEXT
:
1412 value
= alcErrInvalidContext
;
1415 case ALC_OUT_OF_MEMORY
:
1416 value
= alcErrOutOfMemory
;
1419 case ALC_DEVICE_SPECIFIER
:
1420 if(IsDevice(pDevice
))
1421 value
= pDevice
->szDeviceName
;
1425 value
= alcDeviceList
;
1429 case ALC_ALL_DEVICES_SPECIFIER
:
1430 ProbeAllDeviceList();
1431 value
= alcAllDeviceList
;
1434 case ALC_CAPTURE_DEVICE_SPECIFIER
:
1435 if(IsDevice(pDevice
))
1436 value
= pDevice
->szDeviceName
;
1439 ProbeCaptureDeviceList();
1440 value
= alcCaptureDeviceList
;
1444 /* Default devices are always first in the list */
1445 case ALC_DEFAULT_DEVICE_SPECIFIER
:
1449 free(alcDefaultDeviceSpecifier
);
1450 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
1451 if(!alcDefaultDeviceSpecifier
)
1452 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
1453 value
= alcDefaultDeviceSpecifier
;
1456 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
1457 if(!alcAllDeviceList
)
1458 ProbeAllDeviceList();
1460 free(alcDefaultAllDeviceSpecifier
);
1461 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
1462 alcAllDeviceList
: "");
1463 if(!alcDefaultAllDeviceSpecifier
)
1464 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
1465 value
= alcDefaultAllDeviceSpecifier
;
1468 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
1469 if(!alcCaptureDeviceList
)
1470 ProbeCaptureDeviceList();
1472 free(alcCaptureDefaultDeviceSpecifier
);
1473 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
1474 alcCaptureDeviceList
: "");
1475 if(!alcCaptureDefaultDeviceSpecifier
)
1476 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
1477 value
= alcCaptureDefaultDeviceSpecifier
;
1480 case ALC_EXTENSIONS
:
1481 if(IsDevice(pDevice
))
1482 value
= alcExtensionList
;
1484 value
= alcNoDeviceExtList
;
1488 alcSetError(pDevice
, ALC_INVALID_ENUM
);
1499 Returns information about the Device and the version of Open AL
1501 ALC_API ALCvoid ALC_APIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
1503 if(size
== 0 || data
== NULL
)
1505 alcSetError(device
, ALC_INVALID_VALUE
);
1509 if(IsDevice(device
) && device
->IsCaptureDevice
)
1511 SuspendContext(NULL
);
1516 case ALC_CAPTURE_SAMPLES
:
1517 *data
= ALCdevice_AvailableSamples(device
);
1521 *data
= device
->Connected
;
1525 alcSetError(device
, ALC_INVALID_ENUM
);
1529 ProcessContext(NULL
);
1536 case ALC_MAJOR_VERSION
:
1537 *data
= alcMajorVersion
;
1540 case ALC_MINOR_VERSION
:
1541 *data
= alcMinorVersion
;
1544 case ALC_EFX_MAJOR_VERSION
:
1545 *data
= alcEFXMajorVersion
;
1548 case ALC_EFX_MINOR_VERSION
:
1549 *data
= alcEFXMinorVersion
;
1552 case ALC_MAX_AUXILIARY_SENDS
:
1553 if(!IsDevice(device
))
1554 alcSetError(device
, ALC_INVALID_DEVICE
);
1556 *data
= device
->NumAuxSends
;
1559 case ALC_ATTRIBUTES_SIZE
:
1560 if(!IsDevice(device
))
1561 alcSetError(device
, ALC_INVALID_DEVICE
);
1566 case ALC_ALL_ATTRIBUTES
:
1567 if(!IsDevice(device
))
1568 alcSetError(device
, ALC_INVALID_DEVICE
);
1570 alcSetError(device
, ALC_INVALID_VALUE
);
1575 SuspendContext(NULL
);
1576 data
[i
++] = ALC_FREQUENCY
;
1577 data
[i
++] = device
->Frequency
;
1579 data
[i
++] = ALC_REFRESH
;
1580 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
1582 data
[i
++] = ALC_SYNC
;
1583 data
[i
++] = ALC_FALSE
;
1585 data
[i
++] = ALC_MONO_SOURCES
;
1586 data
[i
++] = device
->NumMonoSources
;
1588 data
[i
++] = ALC_STEREO_SOURCES
;
1589 data
[i
++] = device
->NumStereoSources
;
1591 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1592 data
[i
++] = device
->NumAuxSends
;
1595 ProcessContext(NULL
);
1600 if(!IsDevice(device
))
1601 alcSetError(device
, ALC_INVALID_DEVICE
);
1603 *data
= device
->Frequency
;
1607 if(!IsDevice(device
))
1608 alcSetError(device
, ALC_INVALID_DEVICE
);
1610 *data
= device
->Frequency
/ device
->UpdateSize
;
1614 if(!IsDevice(device
))
1615 alcSetError(device
, ALC_INVALID_DEVICE
);
1620 case ALC_MONO_SOURCES
:
1621 if(!IsDevice(device
))
1622 alcSetError(device
, ALC_INVALID_DEVICE
);
1624 *data
= device
->NumMonoSources
;
1627 case ALC_STEREO_SOURCES
:
1628 if(!IsDevice(device
))
1629 alcSetError(device
, ALC_INVALID_DEVICE
);
1631 *data
= device
->NumStereoSources
;
1635 if(!IsDevice(device
))
1636 alcSetError(device
, ALC_INVALID_DEVICE
);
1638 *data
= device
->Connected
;
1642 alcSetError(device
, ALC_INVALID_ENUM
);
1649 alcIsExtensionPresent
1651 Determines if there is support for a particular extension
1653 ALC_API ALCboolean ALC_APIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1655 ALCboolean bResult
= ALC_FALSE
;
1661 alcSetError(device
, ALC_INVALID_VALUE
);
1665 len
= strlen(extName
);
1666 ptr
= (IsDevice(device
) ? alcExtensionList
: alcNoDeviceExtList
);
1669 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1670 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1675 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1679 } while(isspace(*ptr
));
1690 Retrieves the function address for a particular extension function
1692 ALC_API ALCvoid
* ALC_APIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1698 alcSetError(device
, ALC_INVALID_VALUE
);
1702 while(alcFunctions
[i
].funcName
&& strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1704 return alcFunctions
[i
].address
;
1711 Get the value for a particular ALC Enumerated Value
1713 ALC_API ALCenum ALC_APIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1719 alcSetError(device
, ALC_INVALID_VALUE
);
1723 while(enumeration
[i
].enumName
&& strcmp(enumeration
[i
].enumName
,enumName
) != 0)
1725 return enumeration
[i
].value
;
1732 Create and attach a Context to a particular Device.
1734 ALC_API ALCcontext
* ALC_APIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1736 ALCcontext
*ALContext
;
1739 SuspendContext(NULL
);
1741 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1743 alcSetError(device
, ALC_INVALID_DEVICE
);
1744 ProcessContext(NULL
);
1748 // Reset Context Last Error code
1749 device
->LastError
= ALC_NO_ERROR
;
1751 if(UpdateDeviceParams(device
, attrList
) == ALC_FALSE
)
1753 alcSetError(device
, ALC_INVALID_DEVICE
);
1754 aluHandleDisconnect(device
);
1755 ProcessContext(NULL
);
1756 ALCdevice_StopPlayback(device
);
1761 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1764 device
->Contexts
= temp
;
1766 ALContext
= calloc(1, sizeof(ALCcontext
));
1769 ALContext
->MaxActiveSources
= 256;
1770 ALContext
->ActiveSources
= malloc(sizeof(ALContext
->ActiveSources
[0]) *
1771 ALContext
->MaxActiveSources
);
1774 if(!ALContext
|| !ALContext
->ActiveSources
)
1777 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1778 ProcessContext(NULL
);
1779 if(device
->NumContexts
== 0)
1780 ALCdevice_StopPlayback(device
);
1784 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1785 ALContext
->Device
= device
;
1787 InitContext(ALContext
);
1789 ALContext
->next
= g_pContextList
;
1790 g_pContextList
= ALContext
;
1793 ProcessContext(NULL
);
1804 ALC_API ALCvoid ALC_APIENTRY
alcDestroyContext(ALCcontext
*context
)
1810 if(!IsContext(context
))
1812 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1816 Device
= context
->Device
;
1818 if(Device
->NumContexts
== 1)
1819 ALCdevice_StopPlayback(Device
);
1821 SuspendContext(NULL
);
1823 if(context
== GlobalContext
)
1824 GlobalContext
= NULL
;
1826 for(i
= 0;i
< Device
->NumContexts
;i
++)
1828 if(Device
->Contexts
[i
] == context
)
1830 Device
->Contexts
[i
] = Device
->Contexts
[Device
->NumContexts
-1];
1831 Device
->NumContexts
--;
1837 SuspendContext(context
);
1839 if(context
->SourceMap
.size
> 0)
1842 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceMap
.size
);
1844 ReleaseALSources(context
);
1846 ResetUIntMap(&context
->SourceMap
);
1848 if(context
->EffectSlotMap
.size
> 0)
1851 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->EffectSlotMap
.size
);
1853 ReleaseALAuxiliaryEffectSlots(context
);
1855 ResetUIntMap(&context
->EffectSlotMap
);
1857 free(context
->ActiveSources
);
1858 context
->ActiveSources
= NULL
;
1859 context
->MaxActiveSources
= 0;
1860 context
->ActiveSourceCount
= 0;
1862 list
= &g_pContextList
;
1863 while(*list
!= context
)
1864 list
= &(*list
)->next
;
1866 *list
= (*list
)->next
;
1870 ProcessContext(context
);
1871 ProcessContext(NULL
);
1873 ExitContext(context
);
1875 // Free memory (MUST do this after ProcessContext)
1876 memset(context
, 0, sizeof(ALCcontext
));
1882 alcGetCurrentContext
1884 Returns the currently active Context
1886 ALC_API ALCcontext
* ALC_APIENTRY
alcGetCurrentContext(ALCvoid
)
1888 ALCcontext
*pContext
;
1890 if((pContext
=GetContextSuspended()) != NULL
)
1891 ProcessContext(pContext
);
1899 Returns the currently active thread-local Context
1901 ALC_API ALCcontext
* ALC_APIENTRY
alcGetThreadContext(void)
1903 ALCcontext
*pContext
= NULL
;
1905 SuspendContext(NULL
);
1907 pContext
= tls_get(LocalContext
);
1908 if(pContext
&& !IsContext(pContext
))
1910 tls_set(LocalContext
, NULL
);
1914 ProcessContext(NULL
);
1921 alcGetContextsDevice
1923 Returns the Device that a particular Context is attached to
1925 ALC_API ALCdevice
* ALC_APIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1927 ALCdevice
*pDevice
= NULL
;
1929 SuspendContext(NULL
);
1930 if(IsContext(pContext
))
1931 pDevice
= pContext
->Device
;
1933 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1934 ProcessContext(NULL
);
1941 alcMakeContextCurrent
1943 Makes the given Context the active Context
1945 ALC_API ALCboolean ALC_APIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1947 ALboolean bReturn
= AL_TRUE
;
1949 SuspendContext(NULL
);
1951 // context must be a valid Context or NULL
1952 if(context
== NULL
|| IsContext(context
))
1954 GlobalContext
= context
;
1955 tls_set(LocalContext
, NULL
);
1959 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1963 ProcessContext(NULL
);
1971 Makes the given Context the active Context for the current thread
1973 ALC_API ALCboolean ALC_APIENTRY
alcSetThreadContext(ALCcontext
*context
)
1975 ALboolean bReturn
= AL_TRUE
;
1977 SuspendContext(NULL
);
1979 // context must be a valid Context or NULL
1980 if(context
== NULL
|| IsContext(context
))
1981 tls_set(LocalContext
, context
);
1984 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1988 ProcessContext(NULL
);
1994 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1995 void SetDefaultChannelOrder(ALCdevice
*device
)
1997 switch(device
->FmtChans
)
1999 case DevFmtMono
: device
->DevChannels
[FRONT_CENTER
] = 0; break;
2001 case DevFmtStereo
: device
->DevChannels
[FRONT_LEFT
] = 0;
2002 device
->DevChannels
[FRONT_RIGHT
] = 1; break;
2004 case DevFmtQuad
: device
->DevChannels
[FRONT_LEFT
] = 0;
2005 device
->DevChannels
[FRONT_RIGHT
] = 1;
2006 device
->DevChannels
[BACK_LEFT
] = 2;
2007 device
->DevChannels
[BACK_RIGHT
] = 3; break;
2009 case DevFmtX51
: device
->DevChannels
[FRONT_LEFT
] = 0;
2010 device
->DevChannels
[FRONT_RIGHT
] = 1;
2011 device
->DevChannels
[BACK_LEFT
] = 2;
2012 device
->DevChannels
[BACK_RIGHT
] = 3;
2013 device
->DevChannels
[FRONT_CENTER
] = 4;
2014 device
->DevChannels
[LFE
] = 5; break;
2016 case DevFmtX61
: device
->DevChannels
[FRONT_LEFT
] = 0;
2017 device
->DevChannels
[FRONT_RIGHT
] = 1;
2018 device
->DevChannels
[FRONT_CENTER
] = 2;
2019 device
->DevChannels
[LFE
] = 3;
2020 device
->DevChannels
[BACK_CENTER
] = 4;
2021 device
->DevChannels
[SIDE_LEFT
] = 5;
2022 device
->DevChannels
[SIDE_RIGHT
] = 6; break;
2024 case DevFmtX71
: device
->DevChannels
[FRONT_LEFT
] = 0;
2025 device
->DevChannels
[FRONT_RIGHT
] = 1;
2026 device
->DevChannels
[BACK_LEFT
] = 2;
2027 device
->DevChannels
[BACK_RIGHT
] = 3;
2028 device
->DevChannels
[FRONT_CENTER
] = 4;
2029 device
->DevChannels
[LFE
] = 5;
2030 device
->DevChannels
[SIDE_LEFT
] = 6;
2031 device
->DevChannels
[SIDE_RIGHT
] = 7; break;
2034 // Sets the default order used by WaveFormatEx
2035 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
2037 switch(device
->FmtChans
)
2039 case DevFmtMono
: device
->DevChannels
[FRONT_CENTER
] = 0; break;
2041 case DevFmtStereo
: device
->DevChannels
[FRONT_LEFT
] = 0;
2042 device
->DevChannels
[FRONT_RIGHT
] = 1; break;
2044 case DevFmtQuad
: device
->DevChannels
[FRONT_LEFT
] = 0;
2045 device
->DevChannels
[FRONT_RIGHT
] = 1;
2046 device
->DevChannels
[BACK_LEFT
] = 2;
2047 device
->DevChannels
[BACK_RIGHT
] = 3; break;
2049 case DevFmtX51
: device
->DevChannels
[FRONT_LEFT
] = 0;
2050 device
->DevChannels
[FRONT_RIGHT
] = 1;
2051 device
->DevChannels
[FRONT_CENTER
] = 2;
2052 device
->DevChannels
[LFE
] = 3;
2053 device
->DevChannels
[BACK_LEFT
] = 4;
2054 device
->DevChannels
[BACK_RIGHT
] = 5; break;
2056 case DevFmtX61
: device
->DevChannels
[FRONT_LEFT
] = 0;
2057 device
->DevChannels
[FRONT_RIGHT
] = 1;
2058 device
->DevChannels
[FRONT_CENTER
] = 2;
2059 device
->DevChannels
[LFE
] = 3;
2060 device
->DevChannels
[BACK_CENTER
] = 4;
2061 device
->DevChannels
[SIDE_LEFT
] = 5;
2062 device
->DevChannels
[SIDE_RIGHT
] = 6; break;
2064 case DevFmtX71
: device
->DevChannels
[FRONT_LEFT
] = 0;
2065 device
->DevChannels
[FRONT_RIGHT
] = 1;
2066 device
->DevChannels
[FRONT_CENTER
] = 2;
2067 device
->DevChannels
[LFE
] = 3;
2068 device
->DevChannels
[BACK_LEFT
] = 4;
2069 device
->DevChannels
[BACK_RIGHT
] = 5;
2070 device
->DevChannels
[SIDE_LEFT
] = 6;
2071 device
->DevChannels
[SIDE_RIGHT
] = 7; break;
2075 static ALenum
GetFormatFromString(const char *str
)
2077 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
2078 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
2079 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
2080 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
2081 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
2082 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
2084 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
2085 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
2086 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
2087 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
2088 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
2089 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
2091 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
2092 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
2093 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
2094 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
2095 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
2096 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
2098 AL_PRINT("Unknown format: \"%s\"\n", str
);
2099 return AL_FORMAT_STEREO16
;
2105 Open the Device specified.
2107 ALC_API ALCdevice
* ALC_APIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
2109 ALboolean bDeviceFound
= AL_FALSE
;
2114 if(deviceName
&& !deviceName
[0])
2117 device
= calloc(1, sizeof(ALCdevice
));
2120 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
2125 device
->Connected
= ALC_TRUE
;
2126 device
->IsCaptureDevice
= AL_FALSE
;
2127 device
->LastError
= ALC_NO_ERROR
;
2129 device
->Bs2b
= NULL
;
2130 device
->szDeviceName
= NULL
;
2132 device
->Contexts
= NULL
;
2133 device
->NumContexts
= 0;
2135 InitUIntMap(&device
->BufferMap
);
2136 InitUIntMap(&device
->EffectMap
);
2137 InitUIntMap(&device
->FilterMap
);
2138 InitUIntMap(&device
->DatabufferMap
);
2141 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
2142 if(device
->Frequency
< 8000)
2143 device
->Frequency
= 8000;
2145 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
2146 if(DecomposeDevFormat(GetFormatFromString(fmt
),
2147 &device
->FmtChans
, &device
->FmtType
) == AL_FALSE
)
2149 /* Should never happen... */
2150 device
->FmtChans
= DevFmtStereo
;
2151 device
->FmtType
= DevFmtShort
;
2154 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
2155 if(device
->NumUpdates
< 2)
2156 device
->NumUpdates
= 4;
2158 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", 1024);
2159 if(device
->UpdateSize
<= 0)
2160 device
->UpdateSize
= 1024;
2162 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
2163 if((ALint
)device
->MaxNoOfSources
<= 0)
2164 device
->MaxNoOfSources
= 256;
2166 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
2167 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
2168 device
->AuxiliaryEffectSlotMax
= 4;
2170 device
->NumStereoSources
= 1;
2171 device
->NumMonoSources
= device
->MaxNoOfSources
- device
->NumStereoSources
;
2173 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", 1);
2174 if(device
->NumAuxSends
> MAX_SENDS
)
2175 device
->NumAuxSends
= MAX_SENDS
;
2177 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
2179 device
->DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 1);
2181 device
->HeadDampen
= 0.0f
;
2183 // Find a playback device to open
2184 SuspendContext(NULL
);
2185 for(i
= 0;BackendList
[i
].Init
;i
++)
2187 device
->Funcs
= &BackendList
[i
].Funcs
;
2188 if(ALCdevice_OpenPlayback(device
, deviceName
))
2190 device
->next
= g_pDeviceList
;
2191 g_pDeviceList
= device
;
2194 bDeviceFound
= AL_TRUE
;
2198 ProcessContext(NULL
);
2202 // No suitable output device found
2203 alcSetError(NULL
, ALC_INVALID_VALUE
);
2215 Close the specified Device
2217 ALC_API ALCboolean ALC_APIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
2221 if(!IsDevice(pDevice
) || pDevice
->IsCaptureDevice
)
2223 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
2227 SuspendContext(NULL
);
2229 list
= &g_pDeviceList
;
2230 while(*list
!= pDevice
)
2231 list
= &(*list
)->next
;
2233 *list
= (*list
)->next
;
2236 ProcessContext(NULL
);
2238 if(pDevice
->NumContexts
> 0)
2241 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
2243 while(pDevice
->NumContexts
> 0)
2244 alcDestroyContext(pDevice
->Contexts
[0]);
2246 ALCdevice_ClosePlayback(pDevice
);
2248 if(pDevice
->BufferMap
.size
> 0)
2251 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferMap
.size
);
2253 ReleaseALBuffers(pDevice
);
2255 ResetUIntMap(&pDevice
->BufferMap
);
2257 if(pDevice
->EffectMap
.size
> 0)
2260 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectMap
.size
);
2262 ReleaseALEffects(pDevice
);
2264 ResetUIntMap(&pDevice
->EffectMap
);
2266 if(pDevice
->FilterMap
.size
> 0)
2269 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterMap
.size
);
2271 ReleaseALFilters(pDevice
);
2273 ResetUIntMap(&pDevice
->FilterMap
);
2275 if(pDevice
->DatabufferMap
.size
> 0)
2278 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferMap
.size
);
2280 ReleaseALDatabuffers(pDevice
);
2282 ResetUIntMap(&pDevice
->DatabufferMap
);
2284 free(pDevice
->Bs2b
);
2285 pDevice
->Bs2b
= NULL
;
2287 free(pDevice
->szDeviceName
);
2288 pDevice
->szDeviceName
= NULL
;
2290 free(pDevice
->Contexts
);
2291 pDevice
->Contexts
= NULL
;
2293 //Release device structure
2294 memset(pDevice
, 0, sizeof(ALCdevice
));
2301 static void ReleaseALC(void)
2303 free(alcDeviceList
); alcDeviceList
= NULL
;
2304 alcDeviceListSize
= 0;
2305 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
2306 alcAllDeviceListSize
= 0;
2307 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
2308 alcCaptureDeviceListSize
= 0;
2310 free(alcDefaultDeviceSpecifier
);
2311 alcDefaultDeviceSpecifier
= NULL
;
2312 free(alcDefaultAllDeviceSpecifier
);
2313 alcDefaultAllDeviceSpecifier
= NULL
;
2314 free(alcCaptureDefaultDeviceSpecifier
);
2315 alcCaptureDefaultDeviceSpecifier
= NULL
;
2318 if(g_ulDeviceCount
> 0)
2319 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
2322 while(g_pDeviceList
)
2324 if(g_pDeviceList
->IsCaptureDevice
)
2325 alcCaptureCloseDevice(g_pDeviceList
);
2327 alcCloseDevice(g_pDeviceList
);
2331 ///////////////////////////////////////////////////////