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
;
214 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
216 // Default context extensions
217 static const ALchar alExtList
[] =
218 "AL_EXTX_buffer_sub_data AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE "
219 "AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS "
220 "AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET "
221 "AL_EXTX_sample_buffer_object AL_EXT_source_distance_model "
222 "AL_LOKI_quadriphonic";
224 // Mixing Priority Level
228 resampler_t DefaultResampler
;
230 ///////////////////////////////////////////////////////
233 ///////////////////////////////////////////////////////
234 // ALC Related helper functions
236 static void alc_init(void);
237 static void alc_deinit(void);
239 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
243 // Perform actions based on the reason for calling.
244 switch(ul_reason_for_call
)
246 case DLL_PROCESS_ATTACH
:
247 DisableThreadLibraryCalls(hModule
);
251 case DLL_PROCESS_DETACH
:
258 #ifdef HAVE_GCC_DESTRUCTOR
259 static void alc_init(void) __attribute__((constructor
));
260 static void alc_deinit(void) __attribute__((destructor
));
264 static void alc_init(void)
267 const char *devs
, *str
;
269 InitializeCriticalSection(&g_csMutex
);
273 tls_create(&LocalContext
);
275 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
277 DefaultResampler
= GetConfigValueInt(NULL
, "resampler", RESAMPLER_DEFAULT
);
278 if(DefaultResampler
>= RESAMPLER_MAX
|| DefaultResampler
<= RESAMPLER_MIN
)
279 DefaultResampler
= RESAMPLER_DEFAULT
;
281 devs
= GetConfigValue(NULL
, "drivers", "");
286 const char *next
= devs
;
292 next
= strchr(devs
, ',');
294 if(!devs
[0] || devs
[0] == ',')
301 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
302 for(n
= i
;BackendList
[n
].Init
;n
++)
304 if(len
== strlen(BackendList
[n
].name
) &&
305 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
307 BackendInfo Bkp
= BackendList
[n
];
310 BackendList
[n
] = BackendList
[n
-1];
313 BackendList
[n
] = Bkp
;
323 BackendList
[i
].name
= NULL
;
324 BackendList
[i
].Init
= NULL
;
325 BackendList
[i
].Deinit
= NULL
;
326 BackendList
[i
].Probe
= NULL
;
330 for(i
= 0;BackendList
[i
].Init
;i
++)
331 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
333 DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 0);
335 str
= GetConfigValue(NULL
, "excludefx", "");
342 { "eaxreverb", EAXREVERB
},
343 { "reverb", REVERB
},
349 const char *next
= str
;
353 next
= strchr(str
, ',');
355 if(!str
[0] || next
== str
)
358 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
359 for(n
= 0;EffectList
[n
].name
;n
++)
361 if(len
== strlen(EffectList
[n
].name
) &&
362 strncmp(EffectList
[n
].name
, str
, len
) == 0)
363 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
369 static void alc_deinit(void)
375 for(i
= 0;BackendList
[i
].Deinit
;i
++)
376 BackendList
[i
].Deinit();
378 tls_delete(LocalContext
);
382 DeleteCriticalSection(&g_csMutex
);
386 static void ProbeDeviceList()
390 free(alcDeviceList
); alcDeviceList
= NULL
;
391 alcDeviceListSize
= 0;
393 for(i
= 0;BackendList
[i
].Probe
;i
++)
394 BackendList
[i
].Probe(DEVICE_PROBE
);
397 static void ProbeAllDeviceList()
401 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
402 alcAllDeviceListSize
= 0;
404 for(i
= 0;BackendList
[i
].Probe
;i
++)
405 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
408 static void ProbeCaptureDeviceList()
412 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
413 alcCaptureDeviceListSize
= 0;
415 for(i
= 0;BackendList
[i
].Probe
;i
++)
416 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
420 #define DECL_APPEND_LIST_FUNC(type) \
421 void Append##type##List(const ALCchar *name) \
423 size_t len = strlen(name); \
429 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
432 AL_PRINT("Realloc failed to add %s!\n", name); \
435 alc##type##List = temp; \
436 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
437 alc##type##ListSize += len+1; \
438 alc##type##List[alc##type##ListSize] = 0; \
441 DECL_APPEND_LIST_FUNC(Device
)
442 DECL_APPEND_LIST_FUNC(AllDevice
)
443 DECL_APPEND_LIST_FUNC(CaptureDevice
)
446 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
452 fn
= strrchr(fname
, '/');
453 if(!fn
) fn
= strrchr(fname
, '\\');;
457 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
458 if(i
< (int)sizeof(str
) && i
> 0)
462 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
465 str
[sizeof(str
)-1] = 0;
467 fprintf(stderr
, "%s", str
);
470 void EnableRTPrio(ALint level
)
476 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
478 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
479 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
480 struct sched_param param
;
484 /* Use the minimum real-time priority possible for now (on Linux this
485 * should be 1 for SCHED_RR) */
486 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
487 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
491 param
.sched_priority
= 0;
492 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
495 /* Real-time priority not available */
499 AL_PRINT("Failed to set priority level for thread\n");
506 Check pDevice is a valid Device pointer
508 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
510 ALCdevice
*pTempDevice
;
512 SuspendContext(NULL
);
514 pTempDevice
= g_pDeviceList
;
515 while(pTempDevice
&& pTempDevice
!= pDevice
)
516 pTempDevice
= pTempDevice
->next
;
518 ProcessContext(NULL
);
520 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
526 Check pContext is a valid Context pointer
528 static ALCboolean
IsContext(ALCcontext
*pContext
)
530 ALCcontext
*pTempContext
;
532 SuspendContext(NULL
);
534 pTempContext
= g_pContextList
;
535 while (pTempContext
&& pTempContext
!= pContext
)
536 pTempContext
= pTempContext
->next
;
538 ProcessContext(NULL
);
540 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
547 Store latest ALC Error
549 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
552 device
->LastError
= errorCode
;
554 g_eLastContextError
= errorCode
;
563 ALCvoid
SuspendContext(ALCcontext
*pContext
)
566 EnterCriticalSection(&g_csMutex
);
575 ALCvoid
ProcessContext(ALCcontext
*pContext
)
578 LeaveCriticalSection(&g_csMutex
);
585 Returns the currently active Context, in a locked state
587 ALCcontext
*GetContextSuspended(void)
589 ALCcontext
*pContext
= NULL
;
591 SuspendContext(NULL
);
593 pContext
= tls_get(LocalContext
);
594 if(pContext
&& !IsContext(pContext
))
596 tls_set(LocalContext
, NULL
);
601 pContext
= g_pContextList
;
602 while(pContext
&& !pContext
->InUse
)
603 pContext
= pContext
->next
;
606 SuspendContext(pContext
);
608 ProcessContext(NULL
);
617 Initialize Context variables
619 static ALvoid
InitContext(ALCcontext
*pContext
)
621 //Initialise listener
622 pContext
->Listener
.Gain
= 1.0f
;
623 pContext
->Listener
.MetersPerUnit
= 1.0f
;
624 pContext
->Listener
.Position
[0] = 0.0f
;
625 pContext
->Listener
.Position
[1] = 0.0f
;
626 pContext
->Listener
.Position
[2] = 0.0f
;
627 pContext
->Listener
.Velocity
[0] = 0.0f
;
628 pContext
->Listener
.Velocity
[1] = 0.0f
;
629 pContext
->Listener
.Velocity
[2] = 0.0f
;
630 pContext
->Listener
.Forward
[0] = 0.0f
;
631 pContext
->Listener
.Forward
[1] = 0.0f
;
632 pContext
->Listener
.Forward
[2] = -1.0f
;
633 pContext
->Listener
.Up
[0] = 0.0f
;
634 pContext
->Listener
.Up
[1] = 1.0f
;
635 pContext
->Listener
.Up
[2] = 0.0f
;
638 pContext
->LastError
= AL_NO_ERROR
;
639 pContext
->InUse
= AL_FALSE
;
640 pContext
->Suspended
= AL_FALSE
;
643 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
644 pContext
->SourceDistanceModel
= AL_FALSE
;
645 pContext
->DopplerFactor
= 1.0f
;
646 pContext
->DopplerVelocity
= 1.0f
;
647 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
649 pContext
->ExtensionList
= alExtList
;
656 Clean up Context, destroy any remaining Sources
658 static ALCvoid
ExitContext(ALCcontext
*pContext
)
661 pContext
->LastError
= AL_NO_ERROR
;
662 pContext
->InUse
= AL_FALSE
;
665 ///////////////////////////////////////////////////////
668 ///////////////////////////////////////////////////////
669 // ALC Functions calls
672 // This should probably move to another c file but for now ...
673 ALC_API ALCdevice
* ALC_APIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
675 ALCboolean DeviceFound
= ALC_FALSE
;
676 ALCdevice
*device
= NULL
;
681 alcSetError(NULL
, ALC_INVALID_VALUE
);
685 if(deviceName
&& !deviceName
[0])
688 device
= calloc(1, sizeof(ALCdevice
));
691 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
696 device
->Connected
= ALC_TRUE
;
697 device
->IsCaptureDevice
= AL_TRUE
;
699 device
->szDeviceName
= NULL
;
701 device
->Frequency
= frequency
;
702 device
->Format
= format
;
703 device
->UpdateSize
= SampleSize
;
704 device
->NumUpdates
= 1;
706 SuspendContext(NULL
);
707 for(i
= 0;BackendList
[i
].Init
;i
++)
709 device
->Funcs
= &BackendList
[i
].Funcs
;
710 if(ALCdevice_OpenCapture(device
, deviceName
))
712 device
->next
= g_pDeviceList
;
713 g_pDeviceList
= device
;
716 DeviceFound
= ALC_TRUE
;
720 ProcessContext(NULL
);
724 alcSetError(NULL
, ALC_INVALID_VALUE
);
732 ALC_API ALCboolean ALC_APIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
736 if(!IsDevice(pDevice
) || !pDevice
->IsCaptureDevice
)
738 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
742 SuspendContext(NULL
);
744 list
= &g_pDeviceList
;
745 while(*list
!= pDevice
)
746 list
= &(*list
)->next
;
748 *list
= (*list
)->next
;
751 ProcessContext(NULL
);
753 ALCdevice_CloseCapture(pDevice
);
755 free(pDevice
->szDeviceName
);
756 pDevice
->szDeviceName
= NULL
;
763 ALC_API
void ALC_APIENTRY
alcCaptureStart(ALCdevice
*device
)
765 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
767 alcSetError(device
, ALC_INVALID_DEVICE
);
770 SuspendContext(NULL
);
771 ALCdevice_StartCapture(device
);
772 ProcessContext(NULL
);
775 ALC_API
void ALC_APIENTRY
alcCaptureStop(ALCdevice
*device
)
777 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
779 alcSetError(device
, ALC_INVALID_DEVICE
);
782 SuspendContext(NULL
);
783 ALCdevice_StopCapture(device
);
784 ProcessContext(NULL
);
787 ALC_API
void ALC_APIENTRY
alcCaptureSamples(ALCdevice
*device
, ALCvoid
*buffer
, ALCsizei samples
)
789 if(!IsDevice(device
) || !device
->IsCaptureDevice
)
791 alcSetError(device
, ALC_INVALID_DEVICE
);
794 SuspendContext(NULL
);
795 ALCdevice_CaptureSamples(device
, buffer
, samples
);
796 ProcessContext(NULL
);
802 Return last ALC generated error code
804 ALC_API ALCenum ALC_APIENTRY
alcGetError(ALCdevice
*device
)
806 ALCenum errorCode
= ALC_NO_ERROR
;
810 errorCode
= device
->LastError
;
811 device
->LastError
= ALC_NO_ERROR
;
815 errorCode
= g_eLastContextError
;
816 g_eLastContextError
= ALC_NO_ERROR
;
827 ALC_API ALCvoid ALC_APIENTRY
alcSuspendContext(ALCcontext
*pContext
)
829 SuspendContext(NULL
);
830 if(IsContext(pContext
))
831 pContext
->Suspended
= AL_TRUE
;
832 ProcessContext(NULL
);
841 ALC_API ALCvoid ALC_APIENTRY
alcProcessContext(ALCcontext
*pContext
)
843 SuspendContext(NULL
);
844 if(IsContext(pContext
))
845 pContext
->Suspended
= AL_FALSE
;
846 ProcessContext(NULL
);
853 Returns information about the Device, and error strings
855 ALC_API
const ALCchar
* ALC_APIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
857 const ALCchar
*value
= NULL
;
865 case ALC_INVALID_ENUM
:
866 value
= alcErrInvalidEnum
;
869 case ALC_INVALID_VALUE
:
870 value
= alcErrInvalidValue
;
873 case ALC_INVALID_DEVICE
:
874 value
= alcErrInvalidDevice
;
877 case ALC_INVALID_CONTEXT
:
878 value
= alcErrInvalidContext
;
881 case ALC_OUT_OF_MEMORY
:
882 value
= alcErrOutOfMemory
;
885 case ALC_DEVICE_SPECIFIER
:
886 if(IsDevice(pDevice
))
887 value
= pDevice
->szDeviceName
;
891 value
= alcDeviceList
;
895 case ALC_ALL_DEVICES_SPECIFIER
:
896 ProbeAllDeviceList();
897 value
= alcAllDeviceList
;
900 case ALC_CAPTURE_DEVICE_SPECIFIER
:
901 if(IsDevice(pDevice
))
902 value
= pDevice
->szDeviceName
;
905 ProbeCaptureDeviceList();
906 value
= alcCaptureDeviceList
;
910 /* Default devices are always first in the list */
911 case ALC_DEFAULT_DEVICE_SPECIFIER
:
915 free(alcDefaultDeviceSpecifier
);
916 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
917 if(!alcDefaultDeviceSpecifier
)
918 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
919 value
= alcDefaultDeviceSpecifier
;
922 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
923 if(!alcAllDeviceList
)
924 ProbeAllDeviceList();
926 free(alcDefaultAllDeviceSpecifier
);
927 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
928 alcAllDeviceList
: "");
929 if(!alcDefaultAllDeviceSpecifier
)
930 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
931 value
= alcDefaultAllDeviceSpecifier
;
934 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
935 if(!alcCaptureDeviceList
)
936 ProbeCaptureDeviceList();
938 free(alcCaptureDefaultDeviceSpecifier
);
939 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
940 alcCaptureDeviceList
: "");
941 if(!alcCaptureDefaultDeviceSpecifier
)
942 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
943 value
= alcCaptureDefaultDeviceSpecifier
;
947 if(IsDevice(pDevice
))
948 value
= alcExtensionList
;
950 value
= alcNoDeviceExtList
;
954 alcSetError(pDevice
, ALC_INVALID_ENUM
);
965 Returns information about the Device and the version of Open AL
967 ALC_API ALCvoid ALC_APIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
969 if(size
== 0 || data
== NULL
)
971 alcSetError(device
, ALC_INVALID_VALUE
);
975 if(IsDevice(device
) && device
->IsCaptureDevice
)
977 SuspendContext(NULL
);
982 case ALC_CAPTURE_SAMPLES
:
983 *data
= ALCdevice_AvailableSamples(device
);
987 *data
= device
->Connected
;
991 alcSetError(device
, ALC_INVALID_ENUM
);
995 ProcessContext(NULL
);
1002 case ALC_MAJOR_VERSION
:
1003 *data
= alcMajorVersion
;
1006 case ALC_MINOR_VERSION
:
1007 *data
= alcMinorVersion
;
1010 case ALC_EFX_MAJOR_VERSION
:
1011 *data
= alcEFXMajorVersion
;
1014 case ALC_EFX_MINOR_VERSION
:
1015 *data
= alcEFXMinorVersion
;
1018 case ALC_MAX_AUXILIARY_SENDS
:
1019 if(!IsDevice(device
))
1020 alcSetError(device
, ALC_INVALID_DEVICE
);
1022 *data
= device
->NumAuxSends
;
1025 case ALC_ATTRIBUTES_SIZE
:
1026 if(!IsDevice(device
))
1027 alcSetError(device
, ALC_INVALID_DEVICE
);
1032 case ALC_ALL_ATTRIBUTES
:
1033 if(!IsDevice(device
))
1034 alcSetError(device
, ALC_INVALID_DEVICE
);
1036 alcSetError(device
, ALC_INVALID_VALUE
);
1041 SuspendContext(NULL
);
1042 data
[i
++] = ALC_FREQUENCY
;
1043 data
[i
++] = device
->Frequency
;
1045 data
[i
++] = ALC_REFRESH
;
1046 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
1048 data
[i
++] = ALC_SYNC
;
1049 data
[i
++] = ALC_FALSE
;
1051 data
[i
++] = ALC_MONO_SOURCES
;
1052 data
[i
++] = device
->lNumMonoSources
;
1054 data
[i
++] = ALC_STEREO_SOURCES
;
1055 data
[i
++] = device
->lNumStereoSources
;
1057 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1058 data
[i
++] = device
->NumAuxSends
;
1061 ProcessContext(NULL
);
1066 if(!IsDevice(device
))
1067 alcSetError(device
, ALC_INVALID_DEVICE
);
1069 *data
= device
->Frequency
;
1073 if(!IsDevice(device
))
1074 alcSetError(device
, ALC_INVALID_DEVICE
);
1076 *data
= device
->Frequency
/ device
->UpdateSize
;
1080 if(!IsDevice(device
))
1081 alcSetError(device
, ALC_INVALID_DEVICE
);
1086 case ALC_MONO_SOURCES
:
1087 if(!IsDevice(device
))
1088 alcSetError(device
, ALC_INVALID_DEVICE
);
1090 *data
= device
->lNumMonoSources
;
1093 case ALC_STEREO_SOURCES
:
1094 if(!IsDevice(device
))
1095 alcSetError(device
, ALC_INVALID_DEVICE
);
1097 *data
= device
->lNumStereoSources
;
1101 if(!IsDevice(device
))
1102 alcSetError(device
, ALC_INVALID_DEVICE
);
1104 *data
= device
->Connected
;
1108 alcSetError(device
, ALC_INVALID_ENUM
);
1115 alcIsExtensionPresent
1117 Determines if there is support for a particular extension
1119 ALC_API ALCboolean ALC_APIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1121 ALCboolean bResult
= ALC_FALSE
;
1127 alcSetError(device
, ALC_INVALID_VALUE
);
1131 len
= strlen(extName
);
1132 ptr
= (IsDevice(device
) ? alcExtensionList
: alcNoDeviceExtList
);
1135 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1136 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1141 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1145 } while(isspace(*ptr
));
1156 Retrieves the function address for a particular extension function
1158 ALC_API ALCvoid
* ALC_APIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1164 alcSetError(device
, ALC_INVALID_VALUE
);
1168 while(alcFunctions
[i
].funcName
&& strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1170 return alcFunctions
[i
].address
;
1177 Get the value for a particular ALC Enumerated Value
1179 ALC_API ALCenum ALC_APIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1184 while(enumeration
[i
].enumName
&& strcmp(enumeration
[i
].enumName
,enumName
) == 0)
1186 val
= enumeration
[i
].value
;
1188 if(!enumeration
[i
].enumName
)
1189 alcSetError(device
, ALC_INVALID_VALUE
);
1198 Create and attach a Context to a particular Device.
1200 ALC_API ALCcontext
* ALC_APIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1202 ALuint attrIdx
, reqStereoSources
;
1203 ALCcontext
*ALContext
;
1207 SuspendContext(NULL
);
1209 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1211 alcSetError(device
, ALC_INVALID_DEVICE
);
1212 ProcessContext(NULL
);
1216 // Reset Context Last Error code
1217 device
->LastError
= ALC_NO_ERROR
;
1219 // If a context is already running on the device, stop playback so the
1220 // device attributes can be updated
1221 if(device
->NumContexts
> 0)
1223 ProcessContext(NULL
);
1224 ALCdevice_StopPlayback(device
);
1225 SuspendContext(NULL
);
1228 // Check for attributes
1231 ALCint level
= device
->Bs2bLevel
;
1232 ALCuint freq
= device
->Frequency
;
1233 ALCint numMono
= device
->lNumMonoSources
;
1234 ALCint numStereo
= device
->lNumStereoSources
;
1235 ALCuint numSends
= device
->NumAuxSends
;
1238 while(attrList
[attrIdx
])
1240 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
1241 !ConfigValueExists(NULL
, "frequency"))
1243 freq
= attrList
[attrIdx
+ 1];
1248 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1250 reqStereoSources
= attrList
[attrIdx
+ 1];
1251 if(reqStereoSources
> device
->MaxNoOfSources
)
1252 reqStereoSources
= device
->MaxNoOfSources
;
1254 numStereo
= reqStereoSources
;
1255 numMono
= device
->MaxNoOfSources
- numStereo
;
1258 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
1259 !ConfigValueExists(NULL
, "sends"))
1261 numSends
= attrList
[attrIdx
+ 1];
1262 if(numSends
> MAX_SENDS
)
1263 numSends
= MAX_SENDS
;
1269 device
->UpdateSize
= (ALuint64
)device
->UpdateSize
* freq
/
1272 device
->Bs2bLevel
= level
;
1273 device
->Frequency
= freq
;
1274 device
->lNumMonoSources
= numMono
;
1275 device
->lNumStereoSources
= numStereo
;
1276 device
->NumAuxSends
= numSends
;
1279 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1281 alcSetError(device
, ALC_INVALID_DEVICE
);
1282 aluHandleDisconnect(device
);
1283 ProcessContext(NULL
);
1287 for(i
= 0;i
< device
->NumContexts
;i
++)
1289 ALCcontext
*context
= device
->Contexts
[i
];
1293 SuspendContext(context
);
1294 for(slot
= context
->EffectSlotList
;slot
!= NULL
;slot
= slot
->next
)
1296 if(!slot
->EffectState
)
1299 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1301 alcSetError(device
, ALC_INVALID_DEVICE
);
1302 aluHandleDisconnect(device
);
1303 ProcessContext(context
);
1304 ProcessContext(NULL
);
1305 ALCdevice_StopPlayback(device
);
1308 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1311 for(source
= context
->SourceList
;source
!= NULL
;source
= source
->next
)
1313 ALuint s
= device
->NumAuxSends
;
1314 while(s
< MAX_SENDS
)
1316 if(source
->Send
[s
].Slot
)
1317 source
->Send
[s
].Slot
->refcount
--;
1318 source
->Send
[s
].Slot
= NULL
;
1319 source
->Send
[s
].WetFilter
.type
= 0;
1320 source
->Send
[s
].WetFilter
.filter
= 0;
1323 source
->NeedsUpdate
= AL_TRUE
;
1325 aluInitPanning(context
);
1326 ProcessContext(context
);
1329 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1333 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1334 bs2b_clear(device
->Bs2b
);
1336 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1337 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1342 device
->Bs2b
= NULL
;
1345 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1348 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1349 ProcessContext(NULL
);
1352 device
->Contexts
= temp
;
1354 ALContext
= calloc(1, sizeof(ALCcontext
));
1357 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1358 ProcessContext(NULL
);
1362 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1363 ALContext
->Device
= device
;
1365 InitContext(ALContext
);
1366 aluInitPanning(ALContext
);
1368 ALContext
->next
= g_pContextList
;
1369 g_pContextList
= ALContext
;
1372 ProcessContext(NULL
);
1383 ALC_API ALCvoid ALC_APIENTRY
alcDestroyContext(ALCcontext
*context
)
1389 if(!IsContext(context
))
1391 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1395 Device
= context
->Device
;
1397 if(Device
->NumContexts
== 1)
1398 ALCdevice_StopPlayback(Device
);
1400 SuspendContext(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 ALCcontext
*ALContext
;
1516 ALboolean bReturn
= AL_TRUE
;
1518 SuspendContext(NULL
);
1520 // context must be a valid Context or NULL
1521 if(context
== NULL
|| IsContext(context
))
1523 ALContext
= g_pContextList
;
1524 while(ALContext
&& !ALContext
->InUse
)
1525 ALContext
= ALContext
->next
;
1527 if(ALContext
!= NULL
)
1529 SuspendContext(ALContext
);
1530 ALContext
->InUse
=AL_FALSE
;
1531 ProcessContext(ALContext
);
1534 if((ALContext
=context
) != NULL
&& ALContext
->Device
)
1536 SuspendContext(ALContext
);
1537 ALContext
->InUse
=AL_TRUE
;
1538 ProcessContext(ALContext
);
1541 tls_set(LocalContext
, NULL
);
1545 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1549 ProcessContext(NULL
);
1557 Makes the given Context the active Context for the current thread
1559 ALC_API ALCboolean ALC_APIENTRY
alcSetThreadContext(ALCcontext
*context
)
1561 ALboolean bReturn
= AL_TRUE
;
1563 SuspendContext(NULL
);
1565 // context must be a valid Context or NULL
1566 if(context
== NULL
|| IsContext(context
))
1567 tls_set(LocalContext
, context
);
1570 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1574 ProcessContext(NULL
);
1580 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1581 void SetDefaultChannelOrder(ALCdevice
*device
)
1583 switch(aluChannelsFromFormat(device
->Format
))
1585 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1587 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1588 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1590 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1591 device
->DevChannels
[1] = FRONT_RIGHT
;
1592 device
->DevChannels
[2] = BACK_LEFT
;
1593 device
->DevChannels
[3] = BACK_RIGHT
; break;
1595 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1596 device
->DevChannels
[1] = FRONT_RIGHT
;
1597 device
->DevChannels
[2] = BACK_LEFT
;
1598 device
->DevChannels
[3] = BACK_RIGHT
;
1599 device
->DevChannels
[4] = FRONT_CENTER
;
1600 device
->DevChannels
[5] = LFE
; break;
1602 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1603 device
->DevChannels
[1] = FRONT_RIGHT
;
1604 device
->DevChannels
[2] = FRONT_CENTER
;
1605 device
->DevChannels
[3] = LFE
;
1606 device
->DevChannels
[4] = BACK_CENTER
;
1607 device
->DevChannels
[5] = SIDE_LEFT
;
1608 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1610 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1611 device
->DevChannels
[1] = FRONT_RIGHT
;
1612 device
->DevChannels
[2] = BACK_LEFT
;
1613 device
->DevChannels
[3] = BACK_RIGHT
;
1614 device
->DevChannels
[4] = FRONT_CENTER
;
1615 device
->DevChannels
[5] = LFE
;
1616 device
->DevChannels
[6] = SIDE_LEFT
;
1617 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1620 // Sets the default order used by WaveFormatEx
1621 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1623 switch(aluChannelsFromFormat(device
->Format
))
1625 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1627 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1628 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1630 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1631 device
->DevChannels
[1] = FRONT_RIGHT
;
1632 device
->DevChannels
[2] = BACK_LEFT
;
1633 device
->DevChannels
[3] = BACK_RIGHT
; break;
1635 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1636 device
->DevChannels
[1] = FRONT_RIGHT
;
1637 device
->DevChannels
[2] = FRONT_CENTER
;
1638 device
->DevChannels
[3] = LFE
;
1639 device
->DevChannels
[4] = BACK_LEFT
;
1640 device
->DevChannels
[5] = BACK_RIGHT
; break;
1642 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1643 device
->DevChannels
[1] = FRONT_RIGHT
;
1644 device
->DevChannels
[2] = FRONT_CENTER
;
1645 device
->DevChannels
[3] = LFE
;
1646 device
->DevChannels
[4] = BACK_CENTER
;
1647 device
->DevChannels
[5] = SIDE_LEFT
;
1648 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1650 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1651 device
->DevChannels
[1] = FRONT_RIGHT
;
1652 device
->DevChannels
[2] = FRONT_CENTER
;
1653 device
->DevChannels
[3] = LFE
;
1654 device
->DevChannels
[4] = BACK_LEFT
;
1655 device
->DevChannels
[5] = BACK_RIGHT
;
1656 device
->DevChannels
[6] = SIDE_LEFT
;
1657 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1661 static ALenum
GetFormatFromString(const char *str
)
1663 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1664 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1665 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1666 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1667 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1668 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1670 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1671 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1672 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1673 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1674 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1675 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1677 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1678 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1679 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1680 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1681 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1682 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1684 AL_PRINT("Unknown format: \"%s\"\n", str
);
1685 return AL_FORMAT_STEREO16
;
1691 Open the Device specified.
1693 ALC_API ALCdevice
* ALC_APIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1695 ALboolean bDeviceFound
= AL_FALSE
;
1700 if(deviceName
&& !deviceName
[0])
1703 device
= calloc(1, sizeof(ALCdevice
));
1706 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1711 device
->Connected
= ALC_TRUE
;
1712 device
->IsCaptureDevice
= AL_FALSE
;
1713 device
->LastError
= ALC_NO_ERROR
;
1715 device
->Bs2b
= NULL
;
1716 device
->szDeviceName
= NULL
;
1718 device
->Contexts
= NULL
;
1719 device
->NumContexts
= 0;
1722 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1723 if(device
->Frequency
< 8000)
1724 device
->Frequency
= 8000;
1726 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1727 device
->Format
= GetFormatFromString(fmt
);
1729 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1730 if(device
->NumUpdates
< 2)
1731 device
->NumUpdates
= 4;
1733 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1734 if(i
<= 0) i
= 4096;
1736 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1737 if(device
->UpdateSize
<= 0)
1738 device
->UpdateSize
= i
/device
->NumUpdates
;
1740 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1741 if((ALint
)device
->MaxNoOfSources
<= 0)
1742 device
->MaxNoOfSources
= 256;
1744 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1745 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1746 device
->AuxiliaryEffectSlotMax
= 4;
1748 device
->lNumStereoSources
= 1;
1749 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1751 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1752 if(device
->NumAuxSends
> MAX_SENDS
)
1753 device
->NumAuxSends
= MAX_SENDS
;
1755 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1757 if(aluChannelsFromFormat(device
->Format
) <= 2)
1759 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1760 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1761 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1764 device
->HeadDampen
= 0.0f
;
1766 // Find a playback device to open
1767 SuspendContext(NULL
);
1768 for(i
= 0;BackendList
[i
].Init
;i
++)
1770 device
->Funcs
= &BackendList
[i
].Funcs
;
1771 if(ALCdevice_OpenPlayback(device
, deviceName
))
1773 device
->next
= g_pDeviceList
;
1774 g_pDeviceList
= device
;
1777 bDeviceFound
= AL_TRUE
;
1781 ProcessContext(NULL
);
1785 // No suitable output device found
1786 alcSetError(NULL
, ALC_INVALID_VALUE
);
1798 Close the specified Device
1800 ALC_API ALCboolean ALC_APIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1804 if(!IsDevice(pDevice
) || pDevice
->IsCaptureDevice
)
1806 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
1810 SuspendContext(NULL
);
1812 list
= &g_pDeviceList
;
1813 while(*list
!= pDevice
)
1814 list
= &(*list
)->next
;
1816 *list
= (*list
)->next
;
1819 ProcessContext(NULL
);
1821 if(pDevice
->NumContexts
> 0)
1824 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1826 while(pDevice
->NumContexts
> 0)
1827 alcDestroyContext(pDevice
->Contexts
[0]);
1829 ALCdevice_ClosePlayback(pDevice
);
1831 if(pDevice
->BufferCount
> 0)
1834 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1836 ReleaseALBuffers(pDevice
);
1838 if(pDevice
->EffectCount
> 0)
1841 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1843 ReleaseALEffects(pDevice
);
1845 if(pDevice
->FilterCount
> 0)
1848 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1850 ReleaseALFilters(pDevice
);
1852 if(pDevice
->DatabufferCount
> 0)
1855 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1857 ReleaseALDatabuffers(pDevice
);
1860 free(pDevice
->Bs2b
);
1861 pDevice
->Bs2b
= NULL
;
1863 free(pDevice
->szDeviceName
);
1864 pDevice
->szDeviceName
= NULL
;
1866 free(pDevice
->Contexts
);
1867 pDevice
->Contexts
= NULL
;
1869 //Release device structure
1870 memset(pDevice
, 0, sizeof(ALCdevice
));
1877 ALCvoid
ReleaseALC(ALCvoid
)
1879 free(alcDeviceList
); alcDeviceList
= NULL
;
1880 alcDeviceListSize
= 0;
1881 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
1882 alcAllDeviceListSize
= 0;
1883 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
1884 alcCaptureDeviceListSize
= 0;
1886 free(alcDefaultDeviceSpecifier
);
1887 alcDefaultDeviceSpecifier
= NULL
;
1888 free(alcDefaultAllDeviceSpecifier
);
1889 alcDefaultAllDeviceSpecifier
= NULL
;
1890 free(alcCaptureDefaultDeviceSpecifier
);
1891 alcCaptureDefaultDeviceSpecifier
= NULL
;
1894 if(g_ulDeviceCount
> 0)
1895 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1898 while(g_pDeviceList
)
1900 if(g_pDeviceList
->IsCaptureDevice
)
1901 alcCaptureCloseDevice(g_pDeviceList
);
1903 alcCloseDevice(g_pDeviceList
);
1907 ///////////////////////////////////////////////////////