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
35 #include "alExtension.h"
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 { "wave", alc_wave_init
, alc_wave_deinit
, alc_wave_probe
, EmptyFuncs
},
75 { NULL
, NULL
, NULL
, NULL
, EmptyFuncs
}
79 ///////////////////////////////////////////////////////
81 #define ALC_EFX_MAJOR_VERSION 0x20001
82 #define ALC_EFX_MINOR_VERSION 0x20002
83 #define ALC_MAX_AUXILIARY_SENDS 0x20003
85 ///////////////////////////////////////////////////////
86 // STRING and EXTENSIONS
88 typedef struct ALCfunction_struct
94 static ALCfunction alcFunctions
[] = {
95 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
96 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
97 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
98 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
99 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
100 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
101 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
102 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
103 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
104 { "alcGetError", (ALvoid
*) alcGetError
},
105 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
106 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
107 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
108 { "alcGetString", (ALvoid
*) alcGetString
},
109 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
110 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
111 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
112 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
113 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
114 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
116 { "alcSetThreadContext", (ALvoid
*) alcSetThreadContext
},
117 { "alcGetThreadContext", (ALvoid
*) alcGetThreadContext
},
119 { NULL
, (ALvoid
*) NULL
}
122 static ALenums enumeration
[]={
124 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
125 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
126 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
129 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
130 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
131 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
132 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
133 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
134 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
135 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
136 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
137 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
138 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
139 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
140 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
141 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
142 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
143 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
144 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
145 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
148 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
149 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
150 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
153 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
154 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
155 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
156 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
157 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
158 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
159 { (ALchar
*)NULL
, (ALenum
)0 }
162 static const ALCchar alcNoError
[] = "No Error";
163 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
164 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
165 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
166 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
167 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
169 /* Device lists. Sizes only include the first ending null character, not the
171 static ALCchar
*alcDeviceList
;
172 static size_t alcDeviceListSize
;
173 static ALCchar
*alcAllDeviceList
;
174 static size_t alcAllDeviceListSize
;
175 static ALCchar
*alcCaptureDeviceList
;
176 static size_t alcCaptureDeviceListSize
;
177 // Default is always the first in the list
178 static ALCchar
*alcDefaultDeviceSpecifier
;
179 static ALCchar
*alcDefaultAllDeviceSpecifier
;
180 static ALCchar
*alcCaptureDefaultDeviceSpecifier
;
183 static const ALCchar alcNoDeviceExtList
[] =
184 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
185 "ALC_EXTX_thread_local_context";
186 static const ALCchar alcExtensionList
[] =
187 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
188 "ALC_EXT_disconnect ALC_EXT_EFX ALC_EXTX_thread_local_context";
189 static const ALCint alcMajorVersion
= 1;
190 static const ALCint alcMinorVersion
= 1;
192 static const ALCint alcEFXMajorVersion
= 1;
193 static const ALCint alcEFXMinorVersion
= 0;
195 ///////////////////////////////////////////////////////
198 ///////////////////////////////////////////////////////
201 static ALCdevice
*g_pDeviceList
= NULL
;
202 static ALCuint g_ulDeviceCount
= 0;
204 static CRITICAL_SECTION g_csMutex
;
207 static ALCcontext
*g_pContextList
= NULL
;
208 static ALCuint g_ulContextCount
= 0;
210 // Thread-local current context
211 static tls_type LocalContext
;
212 // Process-wide current context
213 static ALCcontext
*GlobalContext
;
216 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
218 // Default context extensions
219 static const ALchar alExtList
[] =
220 "AL_EXTX_buffer_sub_data AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE "
221 "AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS "
222 "AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET "
223 "AL_EXTX_sample_buffer_object AL_EXT_source_distance_model "
224 "AL_LOKI_quadriphonic";
226 // Mixing Priority Level
230 resampler_t DefaultResampler
;
232 ///////////////////////////////////////////////////////
235 ///////////////////////////////////////////////////////
236 // ALC Related helper functions
238 static void alc_init(void);
239 static void alc_deinit(void);
241 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
245 // Perform actions based on the reason for calling.
246 switch(ul_reason_for_call
)
248 case DLL_PROCESS_ATTACH
:
249 DisableThreadLibraryCalls(hModule
);
253 case DLL_PROCESS_DETACH
:
260 #ifdef HAVE_GCC_DESTRUCTOR
261 static void alc_init(void) __attribute__((constructor
));
262 static void alc_deinit(void) __attribute__((destructor
));
266 static void alc_init(void)
269 const char *devs
, *str
;
271 InitializeCriticalSection(&g_csMutex
);
275 tls_create(&LocalContext
);
277 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
279 DefaultResampler
= GetConfigValueInt(NULL
, "resampler", RESAMPLER_DEFAULT
);
280 if(DefaultResampler
>= RESAMPLER_MAX
|| DefaultResampler
<= RESAMPLER_MIN
)
281 DefaultResampler
= RESAMPLER_DEFAULT
;
283 devs
= GetConfigValue(NULL
, "drivers", "");
288 const char *next
= devs
;
294 next
= strchr(devs
, ',');
296 if(!devs
[0] || devs
[0] == ',')
303 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
304 for(n
= i
;BackendList
[n
].Init
;n
++)
306 if(len
== strlen(BackendList
[n
].name
) &&
307 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
309 BackendInfo Bkp
= BackendList
[n
];
312 BackendList
[n
] = BackendList
[n
-1];
315 BackendList
[n
] = Bkp
;
325 BackendList
[i
].name
= NULL
;
326 BackendList
[i
].Init
= NULL
;
327 BackendList
[i
].Deinit
= NULL
;
328 BackendList
[i
].Probe
= NULL
;
332 for(i
= 0;BackendList
[i
].Init
;i
++)
333 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
335 DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 0);
337 str
= GetConfigValue(NULL
, "excludefx", "");
344 { "eaxreverb", EAXREVERB
},
345 { "reverb", REVERB
},
351 const char *next
= str
;
355 next
= strchr(str
, ',');
357 if(!str
[0] || next
== str
)
360 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
361 for(n
= 0;EffectList
[n
].name
;n
++)
363 if(len
== strlen(EffectList
[n
].name
) &&
364 strncmp(EffectList
[n
].name
, str
, len
) == 0)
365 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
371 static void alc_deinit(void)
377 for(i
= 0;BackendList
[i
].Deinit
;i
++)
378 BackendList
[i
].Deinit();
380 tls_delete(LocalContext
);
384 DeleteCriticalSection(&g_csMutex
);
388 static void ProbeDeviceList()
392 free(alcDeviceList
); alcDeviceList
= NULL
;
393 alcDeviceListSize
= 0;
395 for(i
= 0;BackendList
[i
].Probe
;i
++)
396 BackendList
[i
].Probe(DEVICE_PROBE
);
399 static void ProbeAllDeviceList()
403 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
404 alcAllDeviceListSize
= 0;
406 for(i
= 0;BackendList
[i
].Probe
;i
++)
407 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
410 static void ProbeCaptureDeviceList()
414 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
415 alcCaptureDeviceListSize
= 0;
417 for(i
= 0;BackendList
[i
].Probe
;i
++)
418 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
422 #define DECL_APPEND_LIST_FUNC(type) \
423 void Append##type##List(const ALCchar *name) \
425 size_t len = strlen(name); \
431 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
434 AL_PRINT("Realloc failed to add %s!\n", name); \
437 alc##type##List = temp; \
438 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
439 alc##type##ListSize += len+1; \
440 alc##type##List[alc##type##ListSize] = 0; \
443 DECL_APPEND_LIST_FUNC(Device
)
444 DECL_APPEND_LIST_FUNC(AllDevice
)
445 DECL_APPEND_LIST_FUNC(CaptureDevice
)
448 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
454 fn
= strrchr(fname
, '/');
455 if(!fn
) fn
= strrchr(fname
, '\\');;
459 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
460 if(i
< (int)sizeof(str
) && i
> 0)
464 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
467 str
[sizeof(str
)-1] = 0;
469 fprintf(stderr
, "%s", str
);
472 void EnableRTPrio(ALint level
)
478 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
480 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
481 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
482 struct sched_param param
;
486 /* Use the minimum real-time priority possible for now (on Linux this
487 * should be 1 for SCHED_RR) */
488 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
489 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
493 param
.sched_priority
= 0;
494 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
497 /* Real-time priority not available */
501 AL_PRINT("Failed to set priority level for thread\n");
508 Check pDevice is a valid Device pointer
510 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
512 ALCdevice
*pTempDevice
;
514 SuspendContext(NULL
);
516 pTempDevice
= g_pDeviceList
;
517 while(pTempDevice
&& pTempDevice
!= pDevice
)
518 pTempDevice
= pTempDevice
->next
;
520 ProcessContext(NULL
);
522 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
528 Check pContext is a valid Context pointer
530 static ALCboolean
IsContext(ALCcontext
*pContext
)
532 ALCcontext
*pTempContext
;
534 SuspendContext(NULL
);
536 pTempContext
= g_pContextList
;
537 while (pTempContext
&& pTempContext
!= pContext
)
538 pTempContext
= pTempContext
->next
;
540 ProcessContext(NULL
);
542 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
549 Store latest ALC Error
551 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
554 device
->LastError
= errorCode
;
556 g_eLastContextError
= errorCode
;
565 ALCvoid
SuspendContext(ALCcontext
*pContext
)
568 EnterCriticalSection(&g_csMutex
);
577 ALCvoid
ProcessContext(ALCcontext
*pContext
)
580 LeaveCriticalSection(&g_csMutex
);
587 Returns the currently active Context, in a locked state
589 ALCcontext
*GetContextSuspended(void)
591 ALCcontext
*pContext
= NULL
;
593 SuspendContext(NULL
);
595 pContext
= tls_get(LocalContext
);
596 if(pContext
&& !IsContext(pContext
))
598 tls_set(LocalContext
, NULL
);
602 pContext
= GlobalContext
;
605 SuspendContext(pContext
);
607 ProcessContext(NULL
);
616 Initialize Context variables
618 static ALvoid
InitContext(ALCcontext
*pContext
)
620 //Initialise listener
621 pContext
->Listener
.Gain
= 1.0f
;
622 pContext
->Listener
.MetersPerUnit
= 1.0f
;
623 pContext
->Listener
.Position
[0] = 0.0f
;
624 pContext
->Listener
.Position
[1] = 0.0f
;
625 pContext
->Listener
.Position
[2] = 0.0f
;
626 pContext
->Listener
.Velocity
[0] = 0.0f
;
627 pContext
->Listener
.Velocity
[1] = 0.0f
;
628 pContext
->Listener
.Velocity
[2] = 0.0f
;
629 pContext
->Listener
.Forward
[0] = 0.0f
;
630 pContext
->Listener
.Forward
[1] = 0.0f
;
631 pContext
->Listener
.Forward
[2] = -1.0f
;
632 pContext
->Listener
.Up
[0] = 0.0f
;
633 pContext
->Listener
.Up
[1] = 1.0f
;
634 pContext
->Listener
.Up
[2] = 0.0f
;
637 pContext
->LastError
= AL_NO_ERROR
;
638 pContext
->Suspended
= AL_FALSE
;
641 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
642 pContext
->SourceDistanceModel
= AL_FALSE
;
643 pContext
->DopplerFactor
= 1.0f
;
644 pContext
->DopplerVelocity
= 1.0f
;
645 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
647 pContext
->ExtensionList
= alExtList
;
654 Clean up Context, destroy any remaining Sources
656 static ALCvoid
ExitContext(ALCcontext
*pContext
)
659 pContext
->LastError
= AL_NO_ERROR
;
662 ///////////////////////////////////////////////////////
665 ///////////////////////////////////////////////////////
666 // ALC Functions calls
669 // This should probably move to another c file but for now ...
670 ALC_API ALCdevice
* ALC_APIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
672 ALCboolean DeviceFound
= ALC_FALSE
;
673 ALCdevice
*device
= NULL
;
678 alcSetError(NULL
, ALC_INVALID_VALUE
);
682 if(deviceName
&& !deviceName
[0])
685 device
= calloc(1, sizeof(ALCdevice
));
688 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
693 device
->Connected
= ALC_TRUE
;
694 device
->IsCaptureDevice
= AL_TRUE
;
696 device
->szDeviceName
= NULL
;
698 device
->Frequency
= frequency
;
699 device
->Format
= format
;
700 device
->UpdateSize
= SampleSize
;
701 device
->NumUpdates
= 1;
703 SuspendContext(NULL
);
704 for(i
= 0;BackendList
[i
].Init
;i
++)
706 device
->Funcs
= &BackendList
[i
].Funcs
;
707 if(ALCdevice_OpenCapture(device
, deviceName
))
709 device
->next
= g_pDeviceList
;
710 g_pDeviceList
= device
;
713 DeviceFound
= ALC_TRUE
;
717 ProcessContext(NULL
);
721 alcSetError(NULL
, ALC_INVALID_VALUE
);
729 ALC_API ALCboolean ALC_APIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
733 if(!IsDevice(pDevice
) || !pDevice
->IsCaptureDevice
)
735 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
739 SuspendContext(NULL
);
741 list
= &g_pDeviceList
;
742 while(*list
!= pDevice
)
743 list
= &(*list
)->next
;
745 *list
= (*list
)->next
;
748 ProcessContext(NULL
);
750 ALCdevice_CloseCapture(pDevice
);
752 free(pDevice
->szDeviceName
);
753 pDevice
->szDeviceName
= NULL
;
760 ALC_API
void ALC_APIENTRY
alcCaptureStart(ALCdevice
*device
)
762 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
764 alcSetError(device
, ALC_INVALID_DEVICE
);
767 SuspendContext(NULL
);
768 ALCdevice_StartCapture(device
);
769 ProcessContext(NULL
);
772 ALC_API
void ALC_APIENTRY
alcCaptureStop(ALCdevice
*device
)
774 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
776 alcSetError(device
, ALC_INVALID_DEVICE
);
779 SuspendContext(NULL
);
780 ALCdevice_StopCapture(device
);
781 ProcessContext(NULL
);
784 ALC_API
void ALC_APIENTRY
alcCaptureSamples(ALCdevice
*device
, ALCvoid
*buffer
, ALCsizei samples
)
786 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
788 alcSetError(device
, ALC_INVALID_DEVICE
);
791 SuspendContext(NULL
);
792 ALCdevice_CaptureSamples(device
, buffer
, samples
);
793 ProcessContext(NULL
);
799 Return last ALC generated error code
801 ALC_API ALCenum ALC_APIENTRY
alcGetError(ALCdevice
*device
)
803 ALCenum errorCode
= ALC_NO_ERROR
;
807 errorCode
= device
->LastError
;
808 device
->LastError
= ALC_NO_ERROR
;
812 errorCode
= g_eLastContextError
;
813 g_eLastContextError
= ALC_NO_ERROR
;
824 ALC_API ALCvoid ALC_APIENTRY
alcSuspendContext(ALCcontext
*pContext
)
826 SuspendContext(NULL
);
827 if(IsContext(pContext
))
828 pContext
->Suspended
= AL_TRUE
;
829 ProcessContext(NULL
);
838 ALC_API ALCvoid ALC_APIENTRY
alcProcessContext(ALCcontext
*pContext
)
840 SuspendContext(NULL
);
841 if(IsContext(pContext
))
842 pContext
->Suspended
= AL_FALSE
;
843 ProcessContext(NULL
);
850 Returns information about the Device, and error strings
852 ALC_API
const ALCchar
* ALC_APIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
854 const ALCchar
*value
= NULL
;
862 case ALC_INVALID_ENUM
:
863 value
= alcErrInvalidEnum
;
866 case ALC_INVALID_VALUE
:
867 value
= alcErrInvalidValue
;
870 case ALC_INVALID_DEVICE
:
871 value
= alcErrInvalidDevice
;
874 case ALC_INVALID_CONTEXT
:
875 value
= alcErrInvalidContext
;
878 case ALC_OUT_OF_MEMORY
:
879 value
= alcErrOutOfMemory
;
882 case ALC_DEVICE_SPECIFIER
:
883 if(IsDevice(pDevice
))
884 value
= pDevice
->szDeviceName
;
888 value
= alcDeviceList
;
892 case ALC_ALL_DEVICES_SPECIFIER
:
893 ProbeAllDeviceList();
894 value
= alcAllDeviceList
;
897 case ALC_CAPTURE_DEVICE_SPECIFIER
:
898 if(IsDevice(pDevice
))
899 value
= pDevice
->szDeviceName
;
902 ProbeCaptureDeviceList();
903 value
= alcCaptureDeviceList
;
907 /* Default devices are always first in the list */
908 case ALC_DEFAULT_DEVICE_SPECIFIER
:
912 free(alcDefaultDeviceSpecifier
);
913 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
914 if(!alcDefaultDeviceSpecifier
)
915 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
916 value
= alcDefaultDeviceSpecifier
;
919 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
920 if(!alcAllDeviceList
)
921 ProbeAllDeviceList();
923 free(alcDefaultAllDeviceSpecifier
);
924 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
925 alcAllDeviceList
: "");
926 if(!alcDefaultAllDeviceSpecifier
)
927 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
928 value
= alcDefaultAllDeviceSpecifier
;
931 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
932 if(!alcCaptureDeviceList
)
933 ProbeCaptureDeviceList();
935 free(alcCaptureDefaultDeviceSpecifier
);
936 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
937 alcCaptureDeviceList
: "");
938 if(!alcCaptureDefaultDeviceSpecifier
)
939 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
940 value
= alcCaptureDefaultDeviceSpecifier
;
944 if(IsDevice(pDevice
))
945 value
= alcExtensionList
;
947 value
= alcNoDeviceExtList
;
951 alcSetError(pDevice
, ALC_INVALID_ENUM
);
962 Returns information about the Device and the version of Open AL
964 ALC_API ALCvoid ALC_APIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
966 if(size
== 0 || data
== NULL
)
968 alcSetError(device
, ALC_INVALID_VALUE
);
972 if(IsDevice(device
) && device
->IsCaptureDevice
)
974 SuspendContext(NULL
);
979 case ALC_CAPTURE_SAMPLES
:
980 *data
= ALCdevice_AvailableSamples(device
);
984 *data
= device
->Connected
;
988 alcSetError(device
, ALC_INVALID_ENUM
);
992 ProcessContext(NULL
);
999 case ALC_MAJOR_VERSION
:
1000 *data
= alcMajorVersion
;
1003 case ALC_MINOR_VERSION
:
1004 *data
= alcMinorVersion
;
1007 case ALC_EFX_MAJOR_VERSION
:
1008 *data
= alcEFXMajorVersion
;
1011 case ALC_EFX_MINOR_VERSION
:
1012 *data
= alcEFXMinorVersion
;
1015 case ALC_MAX_AUXILIARY_SENDS
:
1016 if(!IsDevice(device
))
1017 alcSetError(device
, ALC_INVALID_DEVICE
);
1019 *data
= device
->NumAuxSends
;
1022 case ALC_ATTRIBUTES_SIZE
:
1023 if(!IsDevice(device
))
1024 alcSetError(device
, ALC_INVALID_DEVICE
);
1029 case ALC_ALL_ATTRIBUTES
:
1030 if(!IsDevice(device
))
1031 alcSetError(device
, ALC_INVALID_DEVICE
);
1033 alcSetError(device
, ALC_INVALID_VALUE
);
1038 SuspendContext(NULL
);
1039 data
[i
++] = ALC_FREQUENCY
;
1040 data
[i
++] = device
->Frequency
;
1042 data
[i
++] = ALC_REFRESH
;
1043 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
1045 data
[i
++] = ALC_SYNC
;
1046 data
[i
++] = ALC_FALSE
;
1048 data
[i
++] = ALC_MONO_SOURCES
;
1049 data
[i
++] = device
->lNumMonoSources
;
1051 data
[i
++] = ALC_STEREO_SOURCES
;
1052 data
[i
++] = device
->lNumStereoSources
;
1054 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1055 data
[i
++] = device
->NumAuxSends
;
1058 ProcessContext(NULL
);
1063 if(!IsDevice(device
))
1064 alcSetError(device
, ALC_INVALID_DEVICE
);
1066 *data
= device
->Frequency
;
1070 if(!IsDevice(device
))
1071 alcSetError(device
, ALC_INVALID_DEVICE
);
1073 *data
= device
->Frequency
/ device
->UpdateSize
;
1077 if(!IsDevice(device
))
1078 alcSetError(device
, ALC_INVALID_DEVICE
);
1083 case ALC_MONO_SOURCES
:
1084 if(!IsDevice(device
))
1085 alcSetError(device
, ALC_INVALID_DEVICE
);
1087 *data
= device
->lNumMonoSources
;
1090 case ALC_STEREO_SOURCES
:
1091 if(!IsDevice(device
))
1092 alcSetError(device
, ALC_INVALID_DEVICE
);
1094 *data
= device
->lNumStereoSources
;
1098 if(!IsDevice(device
))
1099 alcSetError(device
, ALC_INVALID_DEVICE
);
1101 *data
= device
->Connected
;
1105 alcSetError(device
, ALC_INVALID_ENUM
);
1112 alcIsExtensionPresent
1114 Determines if there is support for a particular extension
1116 ALC_API ALCboolean ALC_APIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1118 ALCboolean bResult
= ALC_FALSE
;
1124 alcSetError(device
, ALC_INVALID_VALUE
);
1128 len
= strlen(extName
);
1129 ptr
= (IsDevice(device
) ? alcExtensionList
: alcNoDeviceExtList
);
1132 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1133 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1138 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1142 } while(isspace(*ptr
));
1153 Retrieves the function address for a particular extension function
1155 ALC_API ALCvoid
* ALC_APIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1161 alcSetError(device
, ALC_INVALID_VALUE
);
1165 while(alcFunctions
[i
].funcName
&& strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1167 return alcFunctions
[i
].address
;
1174 Get the value for a particular ALC Enumerated Value
1176 ALC_API ALCenum ALC_APIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1181 while(enumeration
[i
].enumName
&& strcmp(enumeration
[i
].enumName
,enumName
) == 0)
1183 val
= enumeration
[i
].value
;
1185 if(!enumeration
[i
].enumName
)
1186 alcSetError(device
, ALC_INVALID_VALUE
);
1195 Create and attach a Context to a particular Device.
1197 ALC_API ALCcontext
* ALC_APIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1199 ALuint attrIdx
, reqStereoSources
;
1200 ALCcontext
*ALContext
;
1204 SuspendContext(NULL
);
1206 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1208 alcSetError(device
, ALC_INVALID_DEVICE
);
1209 ProcessContext(NULL
);
1213 // Reset Context Last Error code
1214 device
->LastError
= ALC_NO_ERROR
;
1216 // If a context is already running on the device, stop playback so the
1217 // device attributes can be updated
1218 if(device
->NumContexts
> 0)
1220 ProcessContext(NULL
);
1221 ALCdevice_StopPlayback(device
);
1222 SuspendContext(NULL
);
1225 // Check for attributes
1228 ALCint level
= device
->Bs2bLevel
;
1229 ALCuint freq
= device
->Frequency
;
1230 ALCint numMono
= device
->lNumMonoSources
;
1231 ALCint numStereo
= device
->lNumStereoSources
;
1232 ALCuint numSends
= device
->NumAuxSends
;
1235 while(attrList
[attrIdx
])
1237 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
1238 !ConfigValueExists(NULL
, "frequency"))
1240 freq
= attrList
[attrIdx
+ 1];
1245 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1247 reqStereoSources
= attrList
[attrIdx
+ 1];
1248 if(reqStereoSources
> device
->MaxNoOfSources
)
1249 reqStereoSources
= device
->MaxNoOfSources
;
1251 numStereo
= reqStereoSources
;
1252 numMono
= device
->MaxNoOfSources
- numStereo
;
1255 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
1256 !ConfigValueExists(NULL
, "sends"))
1258 numSends
= attrList
[attrIdx
+ 1];
1259 if(numSends
> MAX_SENDS
)
1260 numSends
= MAX_SENDS
;
1266 device
->UpdateSize
= (ALuint64
)device
->UpdateSize
* freq
/
1269 device
->Bs2bLevel
= level
;
1270 device
->Frequency
= freq
;
1271 device
->lNumMonoSources
= numMono
;
1272 device
->lNumStereoSources
= numStereo
;
1273 device
->NumAuxSends
= numSends
;
1276 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1278 alcSetError(device
, ALC_INVALID_DEVICE
);
1279 aluHandleDisconnect(device
);
1280 ProcessContext(NULL
);
1284 for(i
= 0;i
< device
->NumContexts
;i
++)
1286 ALCcontext
*context
= device
->Contexts
[i
];
1290 SuspendContext(context
);
1291 for(slot
= context
->EffectSlotList
;slot
!= NULL
;slot
= slot
->next
)
1293 if(!slot
->EffectState
)
1296 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1298 alcSetError(device
, ALC_INVALID_DEVICE
);
1299 aluHandleDisconnect(device
);
1300 ProcessContext(context
);
1301 ProcessContext(NULL
);
1302 ALCdevice_StopPlayback(device
);
1305 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1308 for(source
= context
->SourceList
;source
!= NULL
;source
= source
->next
)
1310 ALuint s
= device
->NumAuxSends
;
1311 while(s
< MAX_SENDS
)
1313 if(source
->Send
[s
].Slot
)
1314 source
->Send
[s
].Slot
->refcount
--;
1315 source
->Send
[s
].Slot
= NULL
;
1316 source
->Send
[s
].WetFilter
.type
= 0;
1317 source
->Send
[s
].WetFilter
.filter
= 0;
1320 source
->NeedsUpdate
= AL_TRUE
;
1322 aluInitPanning(context
);
1323 ProcessContext(context
);
1326 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1330 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1331 bs2b_clear(device
->Bs2b
);
1333 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1334 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1339 device
->Bs2b
= NULL
;
1342 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1345 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1346 ProcessContext(NULL
);
1349 device
->Contexts
= temp
;
1351 ALContext
= calloc(1, sizeof(ALCcontext
));
1354 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1355 ProcessContext(NULL
);
1359 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1360 ALContext
->Device
= device
;
1362 InitContext(ALContext
);
1363 aluInitPanning(ALContext
);
1365 ALContext
->next
= g_pContextList
;
1366 g_pContextList
= ALContext
;
1369 ProcessContext(NULL
);
1380 ALC_API ALCvoid ALC_APIENTRY
alcDestroyContext(ALCcontext
*context
)
1386 if(!IsContext(context
))
1388 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1392 Device
= context
->Device
;
1394 if(Device
->NumContexts
== 1)
1395 ALCdevice_StopPlayback(Device
);
1397 SuspendContext(NULL
);
1399 if(context
== GlobalContext
)
1400 GlobalContext
= NULL
;
1402 for(i
= 0;i
< Device
->NumContexts
-1;i
++)
1404 if(Device
->Contexts
[i
] == context
)
1406 Device
->Contexts
[i
] = Device
->Contexts
[Device
->NumContexts
-1];
1410 Device
->NumContexts
--;
1413 SuspendContext(context
);
1415 if(context
->SourceCount
> 0)
1418 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceCount
);
1420 ReleaseALSources(context
);
1422 if(context
->EffectSlotCount
> 0)
1425 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->EffectSlotCount
);
1427 ReleaseALAuxiliaryEffectSlots(context
);
1430 list
= &g_pContextList
;
1431 while(*list
!= context
)
1432 list
= &(*list
)->next
;
1434 *list
= (*list
)->next
;
1438 ProcessContext(context
);
1439 ProcessContext(NULL
);
1441 ExitContext(context
);
1443 // Free memory (MUST do this after ProcessContext)
1444 memset(context
, 0, sizeof(ALCcontext
));
1450 alcGetCurrentContext
1452 Returns the currently active Context
1454 ALC_API ALCcontext
* ALC_APIENTRY
alcGetCurrentContext(ALCvoid
)
1456 ALCcontext
*pContext
;
1458 if((pContext
=GetContextSuspended()) != NULL
)
1459 ProcessContext(pContext
);
1467 Returns the currently active thread-local Context
1469 ALC_API ALCcontext
* ALC_APIENTRY
alcGetThreadContext(void)
1471 ALCcontext
*pContext
= NULL
;
1473 SuspendContext(NULL
);
1475 pContext
= tls_get(LocalContext
);
1476 if(pContext
&& !IsContext(pContext
))
1478 tls_set(LocalContext
, NULL
);
1482 ProcessContext(NULL
);
1489 alcGetContextsDevice
1491 Returns the Device that a particular Context is attached to
1493 ALC_API ALCdevice
* ALC_APIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1495 ALCdevice
*pDevice
= NULL
;
1497 SuspendContext(NULL
);
1498 if(IsContext(pContext
))
1499 pDevice
= pContext
->Device
;
1501 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1502 ProcessContext(NULL
);
1509 alcMakeContextCurrent
1511 Makes the given Context the active Context
1513 ALC_API ALCboolean ALC_APIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1515 ALboolean bReturn
= AL_TRUE
;
1517 SuspendContext(NULL
);
1519 // context must be a valid Context or NULL
1520 if(context
== NULL
|| IsContext(context
))
1522 GlobalContext
= context
;
1523 tls_set(LocalContext
, NULL
);
1527 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1531 ProcessContext(NULL
);
1539 Makes the given Context the active Context for the current thread
1541 ALC_API ALCboolean ALC_APIENTRY
alcSetThreadContext(ALCcontext
*context
)
1543 ALboolean bReturn
= AL_TRUE
;
1545 SuspendContext(NULL
);
1547 // context must be a valid Context or NULL
1548 if(context
== NULL
|| IsContext(context
))
1549 tls_set(LocalContext
, context
);
1552 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1556 ProcessContext(NULL
);
1562 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1563 void SetDefaultChannelOrder(ALCdevice
*device
)
1565 switch(aluChannelsFromFormat(device
->Format
))
1567 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1569 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1570 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1572 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1573 device
->DevChannels
[1] = FRONT_RIGHT
;
1574 device
->DevChannels
[2] = BACK_LEFT
;
1575 device
->DevChannels
[3] = BACK_RIGHT
; break;
1577 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1578 device
->DevChannels
[1] = FRONT_RIGHT
;
1579 device
->DevChannels
[2] = BACK_LEFT
;
1580 device
->DevChannels
[3] = BACK_RIGHT
;
1581 device
->DevChannels
[4] = FRONT_CENTER
;
1582 device
->DevChannels
[5] = LFE
; break;
1584 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1585 device
->DevChannels
[1] = FRONT_RIGHT
;
1586 device
->DevChannels
[2] = FRONT_CENTER
;
1587 device
->DevChannels
[3] = LFE
;
1588 device
->DevChannels
[4] = BACK_CENTER
;
1589 device
->DevChannels
[5] = SIDE_LEFT
;
1590 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1592 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1593 device
->DevChannels
[1] = FRONT_RIGHT
;
1594 device
->DevChannels
[2] = BACK_LEFT
;
1595 device
->DevChannels
[3] = BACK_RIGHT
;
1596 device
->DevChannels
[4] = FRONT_CENTER
;
1597 device
->DevChannels
[5] = LFE
;
1598 device
->DevChannels
[6] = SIDE_LEFT
;
1599 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1602 // Sets the default order used by WaveFormatEx
1603 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1605 switch(aluChannelsFromFormat(device
->Format
))
1607 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1609 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1610 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1612 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1613 device
->DevChannels
[1] = FRONT_RIGHT
;
1614 device
->DevChannels
[2] = BACK_LEFT
;
1615 device
->DevChannels
[3] = BACK_RIGHT
; break;
1617 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1618 device
->DevChannels
[1] = FRONT_RIGHT
;
1619 device
->DevChannels
[2] = FRONT_CENTER
;
1620 device
->DevChannels
[3] = LFE
;
1621 device
->DevChannels
[4] = BACK_LEFT
;
1622 device
->DevChannels
[5] = BACK_RIGHT
; break;
1624 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1625 device
->DevChannels
[1] = FRONT_RIGHT
;
1626 device
->DevChannels
[2] = FRONT_CENTER
;
1627 device
->DevChannels
[3] = LFE
;
1628 device
->DevChannels
[4] = BACK_CENTER
;
1629 device
->DevChannels
[5] = SIDE_LEFT
;
1630 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1632 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1633 device
->DevChannels
[1] = FRONT_RIGHT
;
1634 device
->DevChannels
[2] = FRONT_CENTER
;
1635 device
->DevChannels
[3] = LFE
;
1636 device
->DevChannels
[4] = BACK_LEFT
;
1637 device
->DevChannels
[5] = BACK_RIGHT
;
1638 device
->DevChannels
[6] = SIDE_LEFT
;
1639 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1643 static ALenum
GetFormatFromString(const char *str
)
1645 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1646 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1647 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1648 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1649 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1650 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1652 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1653 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1654 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1655 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1656 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1657 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1659 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1660 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1661 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1662 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1663 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1664 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1666 AL_PRINT("Unknown format: \"%s\"\n", str
);
1667 return AL_FORMAT_STEREO16
;
1673 Open the Device specified.
1675 ALC_API ALCdevice
* ALC_APIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1677 ALboolean bDeviceFound
= AL_FALSE
;
1682 if(deviceName
&& !deviceName
[0])
1685 device
= calloc(1, sizeof(ALCdevice
));
1688 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1693 device
->Connected
= ALC_TRUE
;
1694 device
->IsCaptureDevice
= AL_FALSE
;
1695 device
->LastError
= ALC_NO_ERROR
;
1697 device
->Bs2b
= NULL
;
1698 device
->szDeviceName
= NULL
;
1700 device
->Contexts
= NULL
;
1701 device
->NumContexts
= 0;
1704 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1705 if(device
->Frequency
< 8000)
1706 device
->Frequency
= 8000;
1708 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1709 device
->Format
= GetFormatFromString(fmt
);
1711 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1712 if(device
->NumUpdates
< 2)
1713 device
->NumUpdates
= 4;
1715 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1716 if(i
<= 0) i
= 4096;
1718 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1719 if(device
->UpdateSize
<= 0)
1720 device
->UpdateSize
= i
/device
->NumUpdates
;
1722 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1723 if((ALint
)device
->MaxNoOfSources
<= 0)
1724 device
->MaxNoOfSources
= 256;
1726 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1727 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1728 device
->AuxiliaryEffectSlotMax
= 4;
1730 device
->lNumStereoSources
= 1;
1731 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1733 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1734 if(device
->NumAuxSends
> MAX_SENDS
)
1735 device
->NumAuxSends
= MAX_SENDS
;
1737 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1739 if(aluChannelsFromFormat(device
->Format
) <= 2)
1741 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1742 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1743 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1746 device
->HeadDampen
= 0.0f
;
1748 // Find a playback device to open
1749 SuspendContext(NULL
);
1750 for(i
= 0;BackendList
[i
].Init
;i
++)
1752 device
->Funcs
= &BackendList
[i
].Funcs
;
1753 if(ALCdevice_OpenPlayback(device
, deviceName
))
1755 device
->next
= g_pDeviceList
;
1756 g_pDeviceList
= device
;
1759 bDeviceFound
= AL_TRUE
;
1763 ProcessContext(NULL
);
1767 // No suitable output device found
1768 alcSetError(NULL
, ALC_INVALID_VALUE
);
1780 Close the specified Device
1782 ALC_API ALCboolean ALC_APIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1786 if(!IsDevice(pDevice
) || pDevice
->IsCaptureDevice
)
1788 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
1792 SuspendContext(NULL
);
1794 list
= &g_pDeviceList
;
1795 while(*list
!= pDevice
)
1796 list
= &(*list
)->next
;
1798 *list
= (*list
)->next
;
1801 ProcessContext(NULL
);
1803 if(pDevice
->NumContexts
> 0)
1806 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1808 while(pDevice
->NumContexts
> 0)
1809 alcDestroyContext(pDevice
->Contexts
[0]);
1811 ALCdevice_ClosePlayback(pDevice
);
1813 if(pDevice
->BufferCount
> 0)
1816 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1818 ReleaseALBuffers(pDevice
);
1820 if(pDevice
->EffectCount
> 0)
1823 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1825 ReleaseALEffects(pDevice
);
1827 if(pDevice
->FilterCount
> 0)
1830 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1832 ReleaseALFilters(pDevice
);
1834 if(pDevice
->DatabufferCount
> 0)
1837 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1839 ReleaseALDatabuffers(pDevice
);
1842 free(pDevice
->Bs2b
);
1843 pDevice
->Bs2b
= NULL
;
1845 free(pDevice
->szDeviceName
);
1846 pDevice
->szDeviceName
= NULL
;
1848 free(pDevice
->Contexts
);
1849 pDevice
->Contexts
= NULL
;
1851 //Release device structure
1852 memset(pDevice
, 0, sizeof(ALCdevice
));
1859 ALCvoid
ReleaseALC(ALCvoid
)
1861 free(alcDeviceList
); alcDeviceList
= NULL
;
1862 alcDeviceListSize
= 0;
1863 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
1864 alcAllDeviceListSize
= 0;
1865 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
1866 alcCaptureDeviceListSize
= 0;
1868 free(alcDefaultDeviceSpecifier
);
1869 alcDefaultDeviceSpecifier
= NULL
;
1870 free(alcDefaultAllDeviceSpecifier
);
1871 alcDefaultAllDeviceSpecifier
= NULL
;
1872 free(alcCaptureDefaultDeviceSpecifier
);
1873 alcCaptureDefaultDeviceSpecifier
= NULL
;
1876 if(g_ulDeviceCount
> 0)
1877 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1880 while(g_pDeviceList
)
1882 if(g_pDeviceList
->IsCaptureDevice
)
1883 alcCaptureCloseDevice(g_pDeviceList
);
1885 alcCloseDevice(g_pDeviceList
);
1889 ///////////////////////////////////////////////////////