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 { "alcMakeCurrent", (ALvoid
*) alcMakeCurrent
},
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 ALCuint alcDeviceListSize
;
173 static ALCchar
*alcAllDeviceList
;
174 static ALCuint alcAllDeviceListSize
;
175 static ALCchar
*alcCaptureDeviceList
;
176 static ALCuint alcCaptureDeviceListSize
;
177 // Default is always the first in the list
178 static ALCchar
*alcDefaultDeviceSpecifier
;
179 static ALCchar
*alcDefaultAllDeviceSpecifier
;
180 static ALCchar
*alcCaptureDefaultDeviceSpecifier
;
183 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_disconnect ALC_EXT_EFX ALC_EXTX_thread_local_context";
184 static ALCint alcMajorVersion
= 1;
185 static ALCint alcMinorVersion
= 1;
187 static ALCint alcEFXMajorVersion
= 1;
188 static ALCint alcEFXMinorVersion
= 0;
190 ///////////////////////////////////////////////////////
193 ///////////////////////////////////////////////////////
196 static ALCdevice
*g_pDeviceList
= NULL
;
197 static ALCuint g_ulDeviceCount
= 0;
199 static CRITICAL_SECTION g_csMutex
;
202 static ALCcontext
*g_pContextList
= NULL
;
203 static ALCuint g_ulContextCount
= 0;
205 // Thread-local current context
206 static tls_type LocalContext
;
209 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
211 // Mixing Priority Level
214 ///////////////////////////////////////////////////////
217 ///////////////////////////////////////////////////////
218 // ALC Related helper functions
220 static void alc_init(void);
221 static void alc_deinit(void);
223 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
227 // Perform actions based on the reason for calling.
228 switch(ul_reason_for_call
)
230 case DLL_PROCESS_ATTACH
:
231 DisableThreadLibraryCalls(hModule
);
235 case DLL_PROCESS_DETACH
:
242 #ifdef HAVE_GCC_DESTRUCTOR
243 static void alc_init(void) __attribute__((constructor
));
244 static void alc_deinit(void) __attribute__((destructor
));
248 static void alc_init(void)
251 const char *devs
, *str
;
253 InitializeCriticalSection(&g_csMutex
);
257 tls_create(&LocalContext
);
259 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
261 devs
= GetConfigValue(NULL
, "drivers", "");
266 const char *next
= devs
;
272 next
= strchr(devs
, ',');
274 if(!devs
[0] || devs
[0] == ',')
281 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
282 for(n
= i
;BackendList
[n
].Init
;n
++)
284 if(len
== strlen(BackendList
[n
].name
) &&
285 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
287 BackendInfo Bkp
= BackendList
[n
];
290 BackendList
[n
] = BackendList
[n
-1];
293 BackendList
[n
] = Bkp
;
303 BackendList
[i
].name
= NULL
;
304 BackendList
[i
].Init
= NULL
;
305 BackendList
[i
].Deinit
= NULL
;
306 BackendList
[i
].Probe
= NULL
;
310 for(i
= 0;BackendList
[i
].Init
;i
++)
312 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
314 BackendList
[i
].Probe(DEVICE_PROBE
);
315 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
316 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
319 DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 0);
321 str
= GetConfigValue(NULL
, "excludefx", "");
328 { "eaxreverb", EAXREVERB
},
329 { "reverb", REVERB
},
335 const char *next
= str
;
339 next
= strchr(str
, ',');
341 if(!str
[0] || next
== str
)
344 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
345 for(n
= 0;EffectList
[n
].name
;n
++)
347 if(len
== strlen(EffectList
[n
].name
) &&
348 strncmp(EffectList
[n
].name
, str
, len
) == 0)
349 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
355 static void alc_deinit(void)
361 for(i
= 0;BackendList
[i
].Deinit
;i
++)
362 BackendList
[i
].Deinit();
364 tls_delete(LocalContext
);
368 DeleteCriticalSection(&g_csMutex
);
372 static void ProbeDeviceList()
376 free(alcDeviceList
); alcDeviceList
= NULL
;
377 alcDeviceListSize
= 0;
379 for(i
= 0;BackendList
[i
].Probe
;i
++)
380 BackendList
[i
].Probe(DEVICE_PROBE
);
383 static void ProbeAllDeviceList()
387 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
388 alcAllDeviceListSize
= 0;
390 for(i
= 0;BackendList
[i
].Probe
;i
++)
391 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
394 static void ProbeCaptureDeviceList()
398 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
399 alcCaptureDeviceListSize
= 0;
401 for(i
= 0;BackendList
[i
].Probe
;i
++)
402 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
406 #define DECL_APPEND_LIST_FUNC(type) \
407 void Append##type##List(const ALCchar *name) \
409 ALCuint len = strlen(name); \
415 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
418 AL_PRINT("Realloc failed to add %s!\n", name); \
421 alc##type##List = temp; \
422 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
423 alc##type##ListSize += len+1; \
424 alc##type##List[alc##type##ListSize] = 0; \
427 DECL_APPEND_LIST_FUNC(Device
)
428 DECL_APPEND_LIST_FUNC(AllDevice
)
429 DECL_APPEND_LIST_FUNC(CaptureDevice
)
432 void EnableRTPrio(ALint level
)
438 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
440 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
441 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
442 struct sched_param param
;
446 /* Use the minimum real-time priority possible for now (on Linux this
447 * should be 1 for SCHED_RR) */
448 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
449 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
453 param
.sched_priority
= 0;
454 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
457 /* Real-time priority not available */
461 AL_PRINT("Failed to set priority level for thread\n");
468 Check pDevice is a valid Device pointer
470 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
472 ALCdevice
*pTempDevice
;
474 SuspendContext(NULL
);
476 pTempDevice
= g_pDeviceList
;
477 while(pTempDevice
&& pTempDevice
!= pDevice
)
478 pTempDevice
= pTempDevice
->next
;
480 ProcessContext(NULL
);
482 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
488 Check pContext is a valid Context pointer
490 static ALCboolean
IsContext(ALCcontext
*pContext
)
492 ALCcontext
*pTempContext
;
494 SuspendContext(NULL
);
496 pTempContext
= g_pContextList
;
497 while (pTempContext
&& pTempContext
!= pContext
)
498 pTempContext
= pTempContext
->next
;
500 ProcessContext(NULL
);
502 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
509 Store latest ALC Error
511 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
514 device
->LastError
= errorCode
;
516 g_eLastContextError
= errorCode
;
525 ALCvoid
SuspendContext(ALCcontext
*pContext
)
528 EnterCriticalSection(&g_csMutex
);
537 ALCvoid
ProcessContext(ALCcontext
*pContext
)
540 LeaveCriticalSection(&g_csMutex
);
547 Returns the currently active Context, in a locked state
549 ALCcontext
*GetContextSuspended(void)
551 ALCcontext
*pContext
= NULL
;
553 SuspendContext(NULL
);
555 pContext
= tls_get(LocalContext
);
556 if(pContext
&& !IsContext(pContext
))
558 tls_set(LocalContext
, NULL
);
563 pContext
= g_pContextList
;
564 while(pContext
&& !pContext
->InUse
)
565 pContext
= pContext
->next
;
568 SuspendContext(pContext
);
570 ProcessContext(NULL
);
579 Initialize Context variables
581 static ALvoid
InitContext(ALCcontext
*pContext
)
583 //Initialise listener
584 pContext
->Listener
.Gain
= 1.0f
;
585 pContext
->Listener
.MetersPerUnit
= 1.0f
;
586 pContext
->Listener
.Position
[0] = 0.0f
;
587 pContext
->Listener
.Position
[1] = 0.0f
;
588 pContext
->Listener
.Position
[2] = 0.0f
;
589 pContext
->Listener
.Velocity
[0] = 0.0f
;
590 pContext
->Listener
.Velocity
[1] = 0.0f
;
591 pContext
->Listener
.Velocity
[2] = 0.0f
;
592 pContext
->Listener
.Forward
[0] = 0.0f
;
593 pContext
->Listener
.Forward
[1] = 0.0f
;
594 pContext
->Listener
.Forward
[2] = -1.0f
;
595 pContext
->Listener
.Up
[0] = 0.0f
;
596 pContext
->Listener
.Up
[1] = 1.0f
;
597 pContext
->Listener
.Up
[2] = 0.0f
;
600 pContext
->LastError
= AL_NO_ERROR
;
601 pContext
->InUse
= AL_FALSE
;
602 pContext
->Suspended
= AL_FALSE
;
605 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
606 pContext
->SourceDistanceModel
= AL_FALSE
;
607 pContext
->DopplerFactor
= 1.0f
;
608 pContext
->DopplerVelocity
= 1.0f
;
609 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
611 pContext
->ExtensionList
= "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_EXTX_sample_buffer_object AL_EXTX_source_distance_model AL_LOKI_quadriphonic";
618 Clean up Context, destroy any remaining Sources
620 static ALCvoid
ExitContext(ALCcontext
*pContext
)
623 pContext
->LastError
= AL_NO_ERROR
;
624 pContext
->InUse
= AL_FALSE
;
627 ///////////////////////////////////////////////////////
630 ///////////////////////////////////////////////////////
631 // ALC Functions calls
634 // This should probably move to another c file but for now ...
635 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
637 ALCboolean DeviceFound
= ALC_FALSE
;
638 ALCdevice
*pDevice
= NULL
;
643 alcSetError(NULL
, ALC_INVALID_VALUE
);
647 if(deviceName
&& !deviceName
[0])
650 pDevice
= malloc(sizeof(ALCdevice
));
653 //Initialise device structure
654 memset(pDevice
, 0, sizeof(ALCdevice
));
657 pDevice
->Connected
= ALC_TRUE
;
658 pDevice
->IsCaptureDevice
= AL_TRUE
;
660 pDevice
->szDeviceName
= NULL
;
662 pDevice
->Frequency
= frequency
;
663 pDevice
->Format
= format
;
664 pDevice
->UpdateSize
= SampleSize
;
665 pDevice
->NumUpdates
= 1;
667 SuspendContext(NULL
);
668 for(i
= 0;BackendList
[i
].Init
;i
++)
670 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
671 if(ALCdevice_OpenCapture(pDevice
, deviceName
))
673 pDevice
->next
= g_pDeviceList
;
674 g_pDeviceList
= pDevice
;
677 DeviceFound
= ALC_TRUE
;
681 ProcessContext(NULL
);
685 alcSetError(NULL
, ALC_INVALID_VALUE
);
691 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
696 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
698 ALCboolean bReturn
= ALC_FALSE
;
701 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
703 SuspendContext(NULL
);
705 list
= &g_pDeviceList
;
706 while(*list
!= pDevice
)
707 list
= &(*list
)->next
;
709 *list
= (*list
)->next
;
712 ProcessContext(NULL
);
714 ALCdevice_CloseCapture(pDevice
);
716 free(pDevice
->szDeviceName
);
717 pDevice
->szDeviceName
= NULL
;
724 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
729 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
731 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
732 ALCdevice_StartCapture(pDevice
);
734 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
737 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
739 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
740 ALCdevice_StopCapture(pDevice
);
742 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
745 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
747 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
748 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
750 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
756 Return last ALC generated error code
758 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
760 ALCenum errorCode
= ALC_NO_ERROR
;
764 errorCode
= device
->LastError
;
765 device
->LastError
= ALC_NO_ERROR
;
769 errorCode
= g_eLastContextError
;
770 g_eLastContextError
= ALC_NO_ERROR
;
781 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
783 SuspendContext(NULL
);
784 if(IsContext(pContext
))
785 pContext
->Suspended
= AL_TRUE
;
786 ProcessContext(NULL
);
795 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
797 SuspendContext(NULL
);
798 if(IsContext(pContext
))
799 pContext
->Suspended
= AL_FALSE
;
800 ProcessContext(NULL
);
807 Returns information about the Device, and error strings
809 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
811 const ALCchar
*value
= NULL
;
819 case ALC_INVALID_ENUM
:
820 value
= alcErrInvalidEnum
;
823 case ALC_INVALID_VALUE
:
824 value
= alcErrInvalidValue
;
827 case ALC_INVALID_DEVICE
:
828 value
= alcErrInvalidDevice
;
831 case ALC_INVALID_CONTEXT
:
832 value
= alcErrInvalidContext
;
835 case ALC_OUT_OF_MEMORY
:
836 value
= alcErrOutOfMemory
;
839 case ALC_DEVICE_SPECIFIER
:
840 if(IsDevice(pDevice
))
841 value
= pDevice
->szDeviceName
;
845 value
= alcDeviceList
;
849 case ALC_ALL_DEVICES_SPECIFIER
:
850 ProbeAllDeviceList();
851 value
= alcAllDeviceList
;
854 case ALC_CAPTURE_DEVICE_SPECIFIER
:
855 if(IsDevice(pDevice
))
856 value
= pDevice
->szDeviceName
;
859 ProbeCaptureDeviceList();
860 value
= alcCaptureDeviceList
;
864 /* Default devices are always first in the list */
865 case ALC_DEFAULT_DEVICE_SPECIFIER
:
866 free(alcDefaultDeviceSpecifier
);
867 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
868 if(!alcDefaultDeviceSpecifier
)
869 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
870 value
= alcDefaultDeviceSpecifier
;
873 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
874 free(alcDefaultAllDeviceSpecifier
);
875 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
876 alcAllDeviceList
: "");
877 if(!alcDefaultAllDeviceSpecifier
)
878 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
879 value
= alcDefaultAllDeviceSpecifier
;
882 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
883 free(alcCaptureDefaultDeviceSpecifier
);
884 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
885 alcCaptureDeviceList
: "");
886 if(!alcCaptureDefaultDeviceSpecifier
)
887 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
888 value
= alcCaptureDefaultDeviceSpecifier
;
892 value
= alcExtensionList
;
896 alcSetError(pDevice
, ALC_INVALID_ENUM
);
907 Returns information about the Device and the version of Open AL
909 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
911 if(size
== 0 || data
== NULL
)
913 alcSetError(device
, ALC_INVALID_VALUE
);
917 if(IsDevice(device
) && device
->IsCaptureDevice
)
919 SuspendContext(NULL
);
924 case ALC_CAPTURE_SAMPLES
:
925 *data
= ALCdevice_AvailableSamples(device
);
929 *data
= device
->Connected
;
933 alcSetError(device
, ALC_INVALID_ENUM
);
937 ProcessContext(NULL
);
944 case ALC_MAJOR_VERSION
:
945 *data
= alcMajorVersion
;
948 case ALC_MINOR_VERSION
:
949 *data
= alcMinorVersion
;
952 case ALC_EFX_MAJOR_VERSION
:
953 *data
= alcEFXMajorVersion
;
956 case ALC_EFX_MINOR_VERSION
:
957 *data
= alcEFXMinorVersion
;
960 case ALC_MAX_AUXILIARY_SENDS
:
961 if(!IsDevice(device
))
962 alcSetError(device
, ALC_INVALID_DEVICE
);
964 *data
= device
->NumAuxSends
;
967 case ALC_ATTRIBUTES_SIZE
:
968 if(!IsDevice(device
))
969 alcSetError(device
, ALC_INVALID_DEVICE
);
974 case ALC_ALL_ATTRIBUTES
:
975 if(!IsDevice(device
))
976 alcSetError(device
, ALC_INVALID_DEVICE
);
978 alcSetError(device
, ALC_INVALID_VALUE
);
983 SuspendContext(NULL
);
984 data
[i
++] = ALC_FREQUENCY
;
985 data
[i
++] = device
->Frequency
;
987 data
[i
++] = ALC_REFRESH
;
988 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
990 data
[i
++] = ALC_SYNC
;
991 data
[i
++] = ALC_FALSE
;
993 data
[i
++] = ALC_MONO_SOURCES
;
994 data
[i
++] = device
->lNumMonoSources
;
996 data
[i
++] = ALC_STEREO_SOURCES
;
997 data
[i
++] = device
->lNumStereoSources
;
999 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1000 data
[i
++] = device
->NumAuxSends
;
1003 ProcessContext(NULL
);
1008 if(!IsDevice(device
))
1009 alcSetError(device
, ALC_INVALID_DEVICE
);
1011 *data
= device
->Frequency
;
1015 if(!IsDevice(device
))
1016 alcSetError(device
, ALC_INVALID_DEVICE
);
1018 *data
= device
->Frequency
/ device
->UpdateSize
;
1022 if(!IsDevice(device
))
1023 alcSetError(device
, ALC_INVALID_DEVICE
);
1028 case ALC_MONO_SOURCES
:
1029 if(!IsDevice(device
))
1030 alcSetError(device
, ALC_INVALID_DEVICE
);
1032 *data
= device
->lNumMonoSources
;
1035 case ALC_STEREO_SOURCES
:
1036 if(!IsDevice(device
))
1037 alcSetError(device
, ALC_INVALID_DEVICE
);
1039 *data
= device
->lNumStereoSources
;
1043 if(!IsDevice(device
))
1044 alcSetError(device
, ALC_INVALID_DEVICE
);
1046 *data
= device
->Connected
;
1050 alcSetError(device
, ALC_INVALID_ENUM
);
1057 alcIsExtensionPresent
1059 Determines if there is support for a particular extension
1061 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1063 ALCboolean bResult
= ALC_FALSE
;
1070 len
= strlen(extName
);
1071 ptr
= alcExtensionList
;
1074 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1075 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1080 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1084 } while(isspace(*ptr
));
1089 alcSetError(device
, ALC_INVALID_VALUE
);
1098 Retrieves the function address for a particular extension function
1100 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1102 ALCvoid
*pFunction
= NULL
;
1107 while(alcFunctions
[i
].funcName
&&
1108 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1110 pFunction
= alcFunctions
[i
].address
;
1113 alcSetError(device
, ALC_INVALID_VALUE
);
1122 Get the value for a particular ALC Enumerated Value
1124 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1129 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1131 val
= enumeration
[i
].value
;
1133 if(!enumeration
[i
].enumName
)
1134 alcSetError(device
, ALC_INVALID_VALUE
);
1143 Create and attach a Context to a particular Device.
1145 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1147 ALuint attrIdx
, reqStereoSources
;
1148 ALCcontext
*ALContext
;
1152 SuspendContext(NULL
);
1154 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1156 alcSetError(device
, ALC_INVALID_DEVICE
);
1157 ProcessContext(NULL
);
1161 // Reset Context Last Error code
1162 device
->LastError
= ALC_NO_ERROR
;
1164 // If a context is already running on the device, stop playback so the
1165 // device attributes can be updated
1166 if(device
->NumContexts
> 0)
1168 ProcessContext(NULL
);
1169 ALCdevice_StopPlayback(device
);
1170 SuspendContext(NULL
);
1173 // Check for attributes
1176 ALCint level
= device
->Bs2bLevel
;
1177 ALCuint freq
= device
->Frequency
;
1178 ALCint numMono
= device
->lNumMonoSources
;
1179 ALCint numStereo
= device
->lNumStereoSources
;
1180 ALCuint numSends
= device
->NumAuxSends
;
1183 while(attrList
[attrIdx
])
1185 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
1186 !ConfigValueExists(NULL
, "frequency"))
1188 freq
= attrList
[attrIdx
+ 1];
1193 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1195 reqStereoSources
= attrList
[attrIdx
+ 1];
1196 if(reqStereoSources
> device
->MaxNoOfSources
)
1197 reqStereoSources
= device
->MaxNoOfSources
;
1199 numStereo
= reqStereoSources
;
1200 numMono
= device
->MaxNoOfSources
- numStereo
;
1203 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
1204 !ConfigValueExists(NULL
, "sends"))
1206 numSends
= attrList
[attrIdx
+ 1];
1207 if(numSends
> MAX_SENDS
)
1208 numSends
= MAX_SENDS
;
1214 device
->Bs2bLevel
= level
;
1215 device
->Frequency
= freq
;
1216 device
->lNumMonoSources
= numMono
;
1217 device
->lNumStereoSources
= numStereo
;
1218 device
->NumAuxSends
= numSends
;
1221 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1223 alcSetError(device
, ALC_INVALID_DEVICE
);
1224 aluHandleDisconnect(device
);
1225 ProcessContext(NULL
);
1229 for(i
= 0;i
< device
->NumContexts
;i
++)
1231 ALCcontext
*context
= device
->Contexts
[i
];
1235 SuspendContext(context
);
1236 for(slot
= context
->AuxiliaryEffectSlot
;slot
!= NULL
;slot
= slot
->next
)
1238 if(!slot
->EffectState
)
1241 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1243 alcSetError(device
, ALC_INVALID_DEVICE
);
1244 aluHandleDisconnect(device
);
1245 ProcessContext(context
);
1246 ProcessContext(NULL
);
1247 ALCdevice_StopPlayback(device
);
1250 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1253 for(source
= context
->Source
;source
!= NULL
;source
= source
->next
)
1255 ALuint s
= device
->NumAuxSends
;
1256 while(s
< MAX_SENDS
)
1258 if(source
->Send
[s
].Slot
)
1259 source
->Send
[s
].Slot
->refcount
--;
1260 source
->Send
[s
].Slot
= NULL
;
1261 source
->Send
[s
].WetFilter
.type
= 0;
1262 source
->Send
[s
].WetFilter
.filter
= 0;
1265 source
->NeedsUpdate
= AL_TRUE
;
1267 aluInitPanning(context
);
1268 ProcessContext(context
);
1271 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1275 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1276 bs2b_clear(device
->Bs2b
);
1278 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1279 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1284 device
->Bs2b
= NULL
;
1287 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1290 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1291 ProcessContext(NULL
);
1294 device
->Contexts
= temp
;
1296 ALContext
= calloc(1, sizeof(ALCcontext
));
1299 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1300 ProcessContext(NULL
);
1304 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1305 ALContext
->Device
= device
;
1307 InitContext(ALContext
);
1308 aluInitPanning(ALContext
);
1310 ALContext
->next
= g_pContextList
;
1311 g_pContextList
= ALContext
;
1314 ProcessContext(NULL
);
1325 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1330 if (IsContext(context
))
1332 ALCdevice
*Device
= context
->Device
;
1334 if(Device
->NumContexts
== 1)
1335 ALCdevice_StopPlayback(Device
);
1337 SuspendContext(NULL
);
1339 for(i
= 0;i
< Device
->NumContexts
-1;i
++)
1341 if(Device
->Contexts
[i
] == context
)
1343 memmove(&Device
->Contexts
[i
], &Device
->Contexts
[i
+1],
1344 (Device
->NumContexts
-i
-1) * sizeof(*Device
->Contexts
));
1348 Device
->NumContexts
--;
1351 SuspendContext(context
);
1353 if(context
->SourceCount
> 0)
1356 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceCount
);
1358 ReleaseALSources(context
);
1360 if(context
->AuxiliaryEffectSlotCount
> 0)
1363 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->AuxiliaryEffectSlotCount
);
1365 ReleaseALAuxiliaryEffectSlots(context
);
1368 list
= &g_pContextList
;
1369 while(*list
!= context
)
1370 list
= &(*list
)->next
;
1372 *list
= (*list
)->next
;
1376 ProcessContext(context
);
1377 ProcessContext(NULL
);
1379 ExitContext(context
);
1381 // Free memory (MUST do this after ProcessContext)
1382 memset(context
, 0, sizeof(ALCcontext
));
1386 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1391 alcGetCurrentContext
1393 Returns the currently active Context
1395 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1397 ALCcontext
*pContext
;
1399 if((pContext
=GetContextSuspended()) != NULL
)
1400 ProcessContext(pContext
);
1408 Returns the currently active thread-local Context
1410 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void)
1412 ALCcontext
*pContext
= NULL
;
1414 SuspendContext(NULL
);
1416 pContext
= tls_get(LocalContext
);
1417 if(pContext
&& !IsContext(pContext
))
1419 tls_set(LocalContext
, NULL
);
1423 ProcessContext(NULL
);
1430 alcGetContextsDevice
1432 Returns the Device that a particular Context is attached to
1434 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1436 ALCdevice
*pDevice
= NULL
;
1438 SuspendContext(NULL
);
1439 if (IsContext(pContext
))
1440 pDevice
= pContext
->Device
;
1442 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1443 ProcessContext(NULL
);
1450 alcMakeContextCurrent
1452 Makes the given Context the active Context
1454 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1456 ALCcontext
*ALContext
;
1457 ALboolean bReturn
= AL_TRUE
;
1459 SuspendContext(NULL
);
1461 // context must be a valid Context or NULL
1462 if(context
== NULL
|| IsContext(context
))
1464 if((ALContext
=GetContextSuspended()) != NULL
)
1466 ALContext
->InUse
=AL_FALSE
;
1467 ProcessContext(ALContext
);
1470 if((ALContext
=context
) != NULL
&& ALContext
->Device
)
1472 SuspendContext(ALContext
);
1473 ALContext
->InUse
=AL_TRUE
;
1474 ProcessContext(ALContext
);
1477 tls_set(LocalContext
, NULL
);
1481 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1485 ProcessContext(NULL
);
1493 Makes the given Context the active Context for the current thread
1495 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
)
1497 ALboolean bReturn
= AL_TRUE
;
1499 SuspendContext(NULL
);
1501 // context must be a valid Context or NULL
1502 if(context
== NULL
|| IsContext(context
))
1503 tls_set(LocalContext
, context
);
1506 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1510 ProcessContext(NULL
);
1516 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1517 void SetDefaultChannelOrder(ALCdevice
*device
)
1519 switch(aluChannelsFromFormat(device
->Format
))
1521 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1523 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1524 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1526 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1527 device
->DevChannels
[1] = FRONT_RIGHT
;
1528 device
->DevChannels
[2] = BACK_LEFT
;
1529 device
->DevChannels
[3] = BACK_RIGHT
; break;
1531 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1532 device
->DevChannels
[1] = FRONT_RIGHT
;
1533 device
->DevChannels
[2] = BACK_LEFT
;
1534 device
->DevChannels
[3] = BACK_RIGHT
;
1535 device
->DevChannels
[4] = FRONT_CENTER
;
1536 device
->DevChannels
[5] = LFE
; break;
1538 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1539 device
->DevChannels
[1] = FRONT_RIGHT
;
1540 device
->DevChannels
[2] = FRONT_CENTER
;
1541 device
->DevChannels
[3] = LFE
;
1542 device
->DevChannels
[4] = BACK_CENTER
;
1543 device
->DevChannels
[5] = SIDE_LEFT
;
1544 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1546 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1547 device
->DevChannels
[1] = FRONT_RIGHT
;
1548 device
->DevChannels
[2] = BACK_LEFT
;
1549 device
->DevChannels
[3] = BACK_RIGHT
;
1550 device
->DevChannels
[4] = FRONT_CENTER
;
1551 device
->DevChannels
[5] = LFE
;
1552 device
->DevChannels
[6] = SIDE_LEFT
;
1553 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1556 // Sets the default order used by WaveFormatEx
1557 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1559 switch(aluChannelsFromFormat(device
->Format
))
1561 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1563 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1564 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1566 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1567 device
->DevChannels
[1] = FRONT_RIGHT
;
1568 device
->DevChannels
[2] = BACK_LEFT
;
1569 device
->DevChannels
[3] = BACK_RIGHT
; break;
1571 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1572 device
->DevChannels
[1] = FRONT_RIGHT
;
1573 device
->DevChannels
[2] = FRONT_CENTER
;
1574 device
->DevChannels
[3] = LFE
;
1575 device
->DevChannels
[4] = BACK_LEFT
;
1576 device
->DevChannels
[5] = BACK_RIGHT
; break;
1578 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1579 device
->DevChannels
[1] = FRONT_RIGHT
;
1580 device
->DevChannels
[2] = FRONT_CENTER
;
1581 device
->DevChannels
[3] = LFE
;
1582 device
->DevChannels
[4] = BACK_CENTER
;
1583 device
->DevChannels
[5] = SIDE_LEFT
;
1584 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1586 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1587 device
->DevChannels
[1] = FRONT_RIGHT
;
1588 device
->DevChannels
[2] = FRONT_CENTER
;
1589 device
->DevChannels
[3] = LFE
;
1590 device
->DevChannels
[4] = BACK_LEFT
;
1591 device
->DevChannels
[5] = BACK_RIGHT
;
1592 device
->DevChannels
[6] = SIDE_LEFT
;
1593 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1597 static ALenum
GetFormatFromString(const char *str
)
1599 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1600 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1601 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1602 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1603 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1604 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1606 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1607 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1608 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1609 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1610 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1611 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1613 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1614 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1615 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1616 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1617 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1618 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1620 AL_PRINT("Unknown format: \"%s\"\n", str
);
1621 return AL_FORMAT_STEREO16
;
1627 Open the Device specified.
1629 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1631 ALboolean bDeviceFound
= AL_FALSE
;
1635 if(deviceName
&& !deviceName
[0])
1638 device
= malloc(sizeof(ALCdevice
));
1643 //Initialise device structure
1644 memset(device
, 0, sizeof(ALCdevice
));
1647 device
->Connected
= ALC_TRUE
;
1648 device
->IsCaptureDevice
= AL_FALSE
;
1649 device
->LastError
= ALC_NO_ERROR
;
1651 device
->Bs2b
= NULL
;
1652 device
->szDeviceName
= NULL
;
1654 device
->Contexts
= NULL
;
1655 device
->NumContexts
= 0;
1658 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1659 if(device
->Frequency
< 8000)
1660 device
->Frequency
= 8000;
1662 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1663 device
->Format
= GetFormatFromString(fmt
);
1665 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1666 if(device
->NumUpdates
< 2)
1667 device
->NumUpdates
= 4;
1669 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1670 if(i
<= 0) i
= 4096;
1672 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1673 if(device
->UpdateSize
<= 0)
1674 device
->UpdateSize
= i
/device
->NumUpdates
;
1676 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1677 if((ALint
)device
->MaxNoOfSources
<= 0)
1678 device
->MaxNoOfSources
= 256;
1680 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1681 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1682 device
->AuxiliaryEffectSlotMax
= 4;
1684 device
->lNumStereoSources
= 1;
1685 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1687 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1688 if(device
->NumAuxSends
> MAX_SENDS
)
1689 device
->NumAuxSends
= MAX_SENDS
;
1691 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1693 if(aluChannelsFromFormat(device
->Format
) <= 2)
1695 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1696 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1697 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1700 device
->HeadDampen
= 0.0f
;
1702 // Find a playback device to open
1703 SuspendContext(NULL
);
1704 for(i
= 0;BackendList
[i
].Init
;i
++)
1706 device
->Funcs
= &BackendList
[i
].Funcs
;
1707 if(ALCdevice_OpenPlayback(device
, deviceName
))
1709 device
->next
= g_pDeviceList
;
1710 g_pDeviceList
= device
;
1713 bDeviceFound
= AL_TRUE
;
1717 ProcessContext(NULL
);
1721 // No suitable output device found
1722 alcSetError(NULL
, ALC_INVALID_VALUE
);
1728 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1737 Close the specified Device
1739 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1741 ALCboolean bReturn
= ALC_FALSE
;
1744 if(IsDevice(pDevice
) && !pDevice
->IsCaptureDevice
)
1746 SuspendContext(NULL
);
1748 list
= &g_pDeviceList
;
1749 while(*list
!= pDevice
)
1750 list
= &(*list
)->next
;
1752 *list
= (*list
)->next
;
1755 ProcessContext(NULL
);
1757 if(pDevice
->NumContexts
> 0)
1760 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1762 while(pDevice
->NumContexts
> 0)
1763 alcDestroyContext(pDevice
->Contexts
[0]);
1765 ALCdevice_ClosePlayback(pDevice
);
1767 if(pDevice
->BufferCount
> 0)
1770 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1772 ReleaseALBuffers(pDevice
);
1774 if(pDevice
->EffectCount
> 0)
1777 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1779 ReleaseALEffects(pDevice
);
1781 if(pDevice
->FilterCount
> 0)
1784 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1786 ReleaseALFilters(pDevice
);
1788 if(pDevice
->DatabufferCount
> 0)
1791 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1793 ReleaseALDatabuffers(pDevice
);
1796 free(pDevice
->Bs2b
);
1797 pDevice
->Bs2b
= NULL
;
1799 free(pDevice
->szDeviceName
);
1800 pDevice
->szDeviceName
= NULL
;
1802 free(pDevice
->Contexts
);
1803 pDevice
->Contexts
= NULL
;
1805 //Release device structure
1806 memset(pDevice
, 0, sizeof(ALCdevice
));
1812 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
1818 ALCvoid
ReleaseALC(ALCvoid
)
1820 free(alcDeviceList
); alcDeviceList
= NULL
;
1821 alcDeviceListSize
= 0;
1822 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
1823 alcAllDeviceListSize
= 0;
1824 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
1825 alcCaptureDeviceListSize
= 0;
1827 free(alcDefaultDeviceSpecifier
);
1828 alcDefaultDeviceSpecifier
= NULL
;
1829 free(alcDefaultAllDeviceSpecifier
);
1830 alcDefaultAllDeviceSpecifier
= NULL
;
1831 free(alcCaptureDefaultDeviceSpecifier
);
1832 alcCaptureDefaultDeviceSpecifier
= NULL
;
1835 if(g_ulDeviceCount
> 0)
1836 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1839 while(g_pDeviceList
)
1841 if(g_pDeviceList
->IsCaptureDevice
)
1842 alcCaptureCloseDevice(g_pDeviceList
);
1844 alcCloseDevice(g_pDeviceList
);
1848 ///////////////////////////////////////////////////////