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
[] = {
52 { "alsa", alc_alsa_init
, alc_alsa_deinit
, alc_alsa_probe
, EmptyFuncs
},
55 { "oss", alc_oss_init
, alc_oss_deinit
, alc_oss_probe
, EmptyFuncs
},
58 { "solaris", alc_solaris_init
, alc_solaris_deinit
, alc_solaris_probe
, EmptyFuncs
},
61 { "dsound", alcDSoundInit
, alcDSoundDeinit
, alcDSoundProbe
, EmptyFuncs
},
64 { "winmm", alcWinMMInit
, alcWinMMDeinit
, alcWinMMProbe
, EmptyFuncs
},
67 { "port", alc_pa_init
, alc_pa_deinit
, alc_pa_probe
, EmptyFuncs
},
69 #ifdef HAVE_PULSEAUDIO
70 { "pulse", alc_pulse_init
, alc_pulse_deinit
, alc_pulse_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(ALenum errorCode
)
513 g_eLastContextError
= errorCode
;
522 ALCvoid
SuspendContext(ALCcontext
*pContext
)
525 EnterCriticalSection(&g_csMutex
);
534 ALCvoid
ProcessContext(ALCcontext
*pContext
)
537 LeaveCriticalSection(&g_csMutex
);
544 Returns the currently active Context, in a locked state
546 ALCcontext
*GetContextSuspended(void)
548 ALCcontext
*pContext
= NULL
;
550 SuspendContext(NULL
);
552 pContext
= tls_get(LocalContext
);
553 if(pContext
&& !IsContext(pContext
))
555 tls_set(LocalContext
, NULL
);
560 pContext
= g_pContextList
;
561 while(pContext
&& !pContext
->InUse
)
562 pContext
= pContext
->next
;
565 SuspendContext(pContext
);
567 ProcessContext(NULL
);
576 Initialize Context variables
578 static ALvoid
InitContext(ALCcontext
*pContext
)
580 //Initialise listener
581 pContext
->Listener
.Gain
= 1.0f
;
582 pContext
->Listener
.MetersPerUnit
= 1.0f
;
583 pContext
->Listener
.Position
[0] = 0.0f
;
584 pContext
->Listener
.Position
[1] = 0.0f
;
585 pContext
->Listener
.Position
[2] = 0.0f
;
586 pContext
->Listener
.Velocity
[0] = 0.0f
;
587 pContext
->Listener
.Velocity
[1] = 0.0f
;
588 pContext
->Listener
.Velocity
[2] = 0.0f
;
589 pContext
->Listener
.Forward
[0] = 0.0f
;
590 pContext
->Listener
.Forward
[1] = 0.0f
;
591 pContext
->Listener
.Forward
[2] = -1.0f
;
592 pContext
->Listener
.Up
[0] = 0.0f
;
593 pContext
->Listener
.Up
[1] = 1.0f
;
594 pContext
->Listener
.Up
[2] = 0.0f
;
597 pContext
->LastError
= AL_NO_ERROR
;
598 pContext
->InUse
= AL_FALSE
;
599 pContext
->Suspended
= AL_FALSE
;
602 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
603 pContext
->SourceDistanceModel
= AL_FALSE
;
604 pContext
->DopplerFactor
= 1.0f
;
605 pContext
->DopplerVelocity
= 1.0f
;
606 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
608 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";
610 aluInitPanning(pContext
);
617 Clean up Context, destroy any remaining Sources
619 static ALCvoid
ExitContext(ALCcontext
*pContext
)
622 pContext
->LastError
= AL_NO_ERROR
;
623 pContext
->InUse
= AL_FALSE
;
626 ///////////////////////////////////////////////////////
629 ///////////////////////////////////////////////////////
630 // ALC Functions calls
633 // This should probably move to another c file but for now ...
634 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
636 ALCboolean DeviceFound
= ALC_FALSE
;
637 ALCdevice
*pDevice
= NULL
;
642 alcSetError(ALC_INVALID_VALUE
);
646 if(deviceName
&& !deviceName
[0])
649 pDevice
= malloc(sizeof(ALCdevice
));
652 //Initialise device structure
653 memset(pDevice
, 0, sizeof(ALCdevice
));
656 pDevice
->Connected
= ALC_TRUE
;
657 pDevice
->IsCaptureDevice
= AL_TRUE
;
659 pDevice
->szDeviceName
= NULL
;
661 pDevice
->Frequency
= frequency
;
662 pDevice
->Format
= format
;
663 pDevice
->UpdateSize
= SampleSize
;
664 pDevice
->NumUpdates
= 1;
666 SuspendContext(NULL
);
667 for(i
= 0;BackendList
[i
].Init
;i
++)
669 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
670 if(ALCdevice_OpenCapture(pDevice
, deviceName
))
672 pDevice
->next
= g_pDeviceList
;
673 g_pDeviceList
= pDevice
;
676 DeviceFound
= ALC_TRUE
;
680 ProcessContext(NULL
);
684 alcSetError(ALC_INVALID_VALUE
);
690 alcSetError(ALC_OUT_OF_MEMORY
);
695 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
697 ALCboolean bReturn
= ALC_FALSE
;
700 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
702 SuspendContext(NULL
);
704 list
= &g_pDeviceList
;
705 while(*list
!= pDevice
)
706 list
= &(*list
)->next
;
708 *list
= (*list
)->next
;
711 ProcessContext(NULL
);
713 ALCdevice_CloseCapture(pDevice
);
715 free(pDevice
->szDeviceName
);
716 pDevice
->szDeviceName
= NULL
;
723 alcSetError(ALC_INVALID_DEVICE
);
728 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
730 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
731 ALCdevice_StartCapture(pDevice
);
733 alcSetError(ALC_INVALID_DEVICE
);
736 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
738 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
739 ALCdevice_StopCapture(pDevice
);
741 alcSetError(ALC_INVALID_DEVICE
);
744 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
746 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
747 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
749 alcSetError(ALC_INVALID_DEVICE
);
755 Return last ALC generated error code
757 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
763 errorCode
= g_eLastContextError
;
764 g_eLastContextError
= ALC_NO_ERROR
;
774 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
776 SuspendContext(NULL
);
777 if(IsContext(pContext
))
778 pContext
->Suspended
= AL_TRUE
;
779 ProcessContext(NULL
);
788 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
790 SuspendContext(NULL
);
791 if(IsContext(pContext
))
792 pContext
->Suspended
= AL_FALSE
;
793 ProcessContext(NULL
);
800 Returns information about the Device, and error strings
802 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
804 const ALCchar
*value
= NULL
;
812 case ALC_INVALID_ENUM
:
813 value
= alcErrInvalidEnum
;
816 case ALC_INVALID_VALUE
:
817 value
= alcErrInvalidValue
;
820 case ALC_INVALID_DEVICE
:
821 value
= alcErrInvalidDevice
;
824 case ALC_INVALID_CONTEXT
:
825 value
= alcErrInvalidContext
;
828 case ALC_OUT_OF_MEMORY
:
829 value
= alcErrOutOfMemory
;
832 case ALC_DEVICE_SPECIFIER
:
833 if(IsDevice(pDevice
))
834 value
= pDevice
->szDeviceName
;
838 value
= alcDeviceList
;
842 case ALC_ALL_DEVICES_SPECIFIER
:
843 ProbeAllDeviceList();
844 value
= alcAllDeviceList
;
847 case ALC_CAPTURE_DEVICE_SPECIFIER
:
848 if(IsDevice(pDevice
))
849 value
= pDevice
->szDeviceName
;
852 ProbeCaptureDeviceList();
853 value
= alcCaptureDeviceList
;
857 /* Default devices are always first in the list */
858 case ALC_DEFAULT_DEVICE_SPECIFIER
:
859 free(alcDefaultDeviceSpecifier
);
860 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
861 if(!alcDefaultDeviceSpecifier
)
862 alcSetError(ALC_OUT_OF_MEMORY
);
863 value
= alcDefaultDeviceSpecifier
;
866 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
867 free(alcDefaultAllDeviceSpecifier
);
868 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
869 alcAllDeviceList
: "");
870 if(!alcDefaultAllDeviceSpecifier
)
871 alcSetError(ALC_OUT_OF_MEMORY
);
872 value
= alcDefaultAllDeviceSpecifier
;
875 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
876 free(alcCaptureDefaultDeviceSpecifier
);
877 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
878 alcCaptureDeviceList
: "");
879 if(!alcCaptureDefaultDeviceSpecifier
)
880 alcSetError(ALC_OUT_OF_MEMORY
);
881 value
= alcCaptureDefaultDeviceSpecifier
;
885 value
= alcExtensionList
;
889 alcSetError(ALC_INVALID_ENUM
);
900 Returns information about the Device and the version of Open AL
902 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
904 if(IsDevice(device
) && device
->IsCaptureDevice
)
906 SuspendContext(NULL
);
911 case ALC_CAPTURE_SAMPLES
:
912 if ((size
) && (data
))
913 *data
= ALCdevice_AvailableSamples(device
);
915 alcSetError(ALC_INVALID_VALUE
);
920 alcSetError(ALC_INVALID_VALUE
);
922 *data
= device
->Connected
;
926 alcSetError(ALC_INVALID_ENUM
);
930 ProcessContext(NULL
);
939 case ALC_MAJOR_VERSION
:
941 alcSetError(ALC_INVALID_VALUE
);
943 *data
= alcMajorVersion
;
946 case ALC_MINOR_VERSION
:
948 alcSetError(ALC_INVALID_VALUE
);
950 *data
= alcMinorVersion
;
953 case ALC_EFX_MAJOR_VERSION
:
955 alcSetError(ALC_INVALID_VALUE
);
957 *data
= alcEFXMajorVersion
;
960 case ALC_EFX_MINOR_VERSION
:
962 alcSetError(ALC_INVALID_VALUE
);
964 *data
= alcEFXMinorVersion
;
967 case ALC_MAX_AUXILIARY_SENDS
:
969 alcSetError(ALC_INVALID_VALUE
);
971 *data
= (device
?device
->NumAuxSends
:MAX_SENDS
);
974 case ALC_ATTRIBUTES_SIZE
:
975 if(!IsDevice(device
))
976 alcSetError(ALC_INVALID_DEVICE
);
978 alcSetError(ALC_INVALID_VALUE
);
983 case ALC_ALL_ATTRIBUTES
:
984 if(!IsDevice(device
))
985 alcSetError(ALC_INVALID_DEVICE
);
987 alcSetError(ALC_INVALID_VALUE
);
992 SuspendContext(NULL
);
993 data
[i
++] = ALC_FREQUENCY
;
994 data
[i
++] = device
->Frequency
;
996 data
[i
++] = ALC_REFRESH
;
997 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
999 data
[i
++] = ALC_SYNC
;
1000 data
[i
++] = ALC_FALSE
;
1002 data
[i
++] = ALC_MONO_SOURCES
;
1003 data
[i
++] = device
->lNumMonoSources
;
1005 data
[i
++] = ALC_STEREO_SOURCES
;
1006 data
[i
++] = device
->lNumStereoSources
;
1008 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1009 data
[i
++] = device
->NumAuxSends
;
1012 ProcessContext(NULL
);
1017 if(!IsDevice(device
))
1018 alcSetError(ALC_INVALID_DEVICE
);
1020 alcSetError(ALC_INVALID_VALUE
);
1022 *data
= device
->Frequency
;
1026 if(!IsDevice(device
))
1027 alcSetError(ALC_INVALID_DEVICE
);
1029 alcSetError(ALC_INVALID_VALUE
);
1031 *data
= device
->Frequency
/ device
->UpdateSize
;
1035 if(!IsDevice(device
))
1036 alcSetError(ALC_INVALID_DEVICE
);
1038 alcSetError(ALC_INVALID_VALUE
);
1043 case ALC_MONO_SOURCES
:
1044 if(!IsDevice(device
))
1045 alcSetError(ALC_INVALID_DEVICE
);
1047 alcSetError(ALC_INVALID_VALUE
);
1049 *data
= device
->lNumMonoSources
;
1052 case ALC_STEREO_SOURCES
:
1053 if(!IsDevice(device
))
1054 alcSetError(ALC_INVALID_DEVICE
);
1056 alcSetError(ALC_INVALID_VALUE
);
1058 *data
= device
->lNumStereoSources
;
1062 if(!IsDevice(device
))
1063 alcSetError(ALC_INVALID_DEVICE
);
1065 alcSetError(ALC_INVALID_VALUE
);
1067 *data
= device
->Connected
;
1071 alcSetError(ALC_INVALID_ENUM
);
1076 alcSetError(ALC_INVALID_VALUE
);
1084 alcIsExtensionPresent
1086 Determines if there is support for a particular extension
1088 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1090 ALCboolean bResult
= ALC_FALSE
;
1099 len
= strlen(extName
);
1100 ptr
= alcExtensionList
;
1103 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1104 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1109 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1113 } while(isspace(*ptr
));
1118 alcSetError(ALC_INVALID_VALUE
);
1127 Retrieves the function address for a particular extension function
1129 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1131 ALCvoid
*pFunction
= NULL
;
1138 while(alcFunctions
[i
].funcName
&&
1139 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1141 pFunction
= alcFunctions
[i
].address
;
1144 alcSetError(ALC_INVALID_VALUE
);
1153 Get the value for a particular ALC Enumerated Value
1155 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1162 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1164 val
= enumeration
[i
].value
;
1166 if(!enumeration
[i
].enumName
)
1167 alcSetError(ALC_INVALID_VALUE
);
1176 Create and attach a Context to a particular Device.
1178 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1180 ALuint attrIdx
, reqStereoSources
;
1181 ALCcontext
*ALContext
;
1185 SuspendContext(NULL
);
1187 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1189 alcSetError(ALC_INVALID_DEVICE
);
1190 ProcessContext(NULL
);
1194 // Reset Context Last Error code
1195 g_eLastContextError
= ALC_NO_ERROR
;
1197 // If a context is already running on the device, stop playback so the
1198 // device attributes can be updated
1199 if(device
->NumContexts
> 0)
1201 ProcessContext(NULL
);
1202 ALCdevice_StopPlayback(device
);
1203 SuspendContext(NULL
);
1206 // Check for attributes
1209 ALCint level
= device
->Bs2bLevel
;
1210 ALCuint freq
= device
->Frequency
;
1211 ALCint numMono
= device
->lNumMonoSources
;
1212 ALCint numStereo
= device
->lNumStereoSources
;
1213 ALCuint numSends
= device
->NumAuxSends
;
1216 while(attrList
[attrIdx
])
1218 if(attrList
[attrIdx
] == ALC_FREQUENCY
)
1220 freq
= attrList
[attrIdx
+ 1];
1222 freq
= device
->Frequency
;
1225 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1227 reqStereoSources
= attrList
[attrIdx
+ 1];
1228 if(reqStereoSources
> device
->MaxNoOfSources
)
1229 reqStereoSources
= device
->MaxNoOfSources
;
1231 numStereo
= reqStereoSources
;
1232 numMono
= device
->MaxNoOfSources
- numStereo
;
1235 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
)
1237 numSends
= attrList
[attrIdx
+ 1];
1238 if(numSends
> MAX_SENDS
)
1239 numSends
= MAX_SENDS
;
1245 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", level
);
1246 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", freq
);
1247 device
->lNumMonoSources
= numMono
;
1248 device
->lNumStereoSources
= numStereo
;
1249 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", numSends
);
1252 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1254 alcSetError(ALC_INVALID_DEVICE
);
1255 aluHandleDisconnect(device
);
1256 ProcessContext(NULL
);
1260 for(i
= 0;i
< device
->NumContexts
;i
++)
1262 ALCcontext
*context
= device
->Contexts
[i
];
1266 SuspendContext(context
);
1267 for(slot
= context
->AuxiliaryEffectSlot
;slot
!= NULL
;slot
= slot
->next
)
1269 if(!slot
->EffectState
)
1272 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1274 alcSetError(ALC_INVALID_DEVICE
);
1275 aluHandleDisconnect(device
);
1276 ProcessContext(context
);
1277 ProcessContext(NULL
);
1278 ALCdevice_StopPlayback(device
);
1281 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1284 for(source
= context
->Source
;source
!= NULL
;source
= source
->next
)
1286 ALuint s
= device
->NumAuxSends
;
1287 while(s
< MAX_SENDS
)
1289 if(source
->Send
[s
].Slot
)
1290 source
->Send
[s
].Slot
->refcount
--;
1291 source
->Send
[s
].Slot
= NULL
;
1292 source
->Send
[s
].WetFilter
.type
= 0;
1293 source
->Send
[s
].WetFilter
.filter
= 0;
1296 source
->NeedsUpdate
= AL_TRUE
;
1298 ProcessContext(context
);
1301 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1305 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1306 bs2b_clear(device
->Bs2b
);
1308 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1309 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1314 device
->Bs2b
= NULL
;
1317 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1320 alcSetError(ALC_OUT_OF_MEMORY
);
1321 ProcessContext(NULL
);
1324 device
->Contexts
= temp
;
1326 ALContext
= calloc(1, sizeof(ALCcontext
));
1329 alcSetError(ALC_OUT_OF_MEMORY
);
1330 ProcessContext(NULL
);
1334 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1335 ALContext
->Device
= device
;
1337 InitContext(ALContext
);
1339 ALContext
->next
= g_pContextList
;
1340 g_pContextList
= ALContext
;
1343 ProcessContext(NULL
);
1354 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1359 if (IsContext(context
))
1361 ALCdevice
*Device
= context
->Device
;
1363 if(Device
->NumContexts
== 1)
1364 ALCdevice_StopPlayback(Device
);
1366 SuspendContext(NULL
);
1368 for(i
= 0;i
< Device
->NumContexts
-1;i
++)
1370 if(Device
->Contexts
[i
] == context
)
1372 memmove(&Device
->Contexts
[i
], &Device
->Contexts
[i
+1],
1373 (Device
->NumContexts
-i
-1) * sizeof(*Device
->Contexts
));
1377 Device
->NumContexts
--;
1380 SuspendContext(context
);
1382 if(context
->SourceCount
> 0)
1385 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceCount
);
1387 ReleaseALSources(context
);
1389 if(context
->AuxiliaryEffectSlotCount
> 0)
1392 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->AuxiliaryEffectSlotCount
);
1394 ReleaseALAuxiliaryEffectSlots(context
);
1397 list
= &g_pContextList
;
1398 while(*list
!= context
)
1399 list
= &(*list
)->next
;
1401 *list
= (*list
)->next
;
1405 ProcessContext(context
);
1406 ProcessContext(NULL
);
1408 ExitContext(context
);
1410 // Free memory (MUST do this after ProcessContext)
1411 memset(context
, 0, sizeof(ALCcontext
));
1415 alcSetError(ALC_INVALID_CONTEXT
);
1420 alcGetCurrentContext
1422 Returns the currently active Context
1424 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1426 ALCcontext
*pContext
;
1428 if((pContext
=GetContextSuspended()) != NULL
)
1429 ProcessContext(pContext
);
1437 Returns the currently active thread-local Context
1439 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void)
1441 ALCcontext
*pContext
= NULL
;
1443 SuspendContext(NULL
);
1445 pContext
= tls_get(LocalContext
);
1446 if(pContext
&& !IsContext(pContext
))
1448 tls_set(LocalContext
, NULL
);
1452 ProcessContext(NULL
);
1459 alcGetContextsDevice
1461 Returns the Device that a particular Context is attached to
1463 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1465 ALCdevice
*pDevice
= NULL
;
1467 SuspendContext(NULL
);
1468 if (IsContext(pContext
))
1469 pDevice
= pContext
->Device
;
1471 alcSetError(ALC_INVALID_CONTEXT
);
1472 ProcessContext(NULL
);
1479 alcMakeContextCurrent
1481 Makes the given Context the active Context
1483 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1485 ALCcontext
*ALContext
;
1486 ALboolean bReturn
= AL_TRUE
;
1488 SuspendContext(NULL
);
1490 // context must be a valid Context or NULL
1491 if(context
== NULL
|| IsContext(context
))
1493 if((ALContext
=GetContextSuspended()) != NULL
)
1495 ALContext
->InUse
=AL_FALSE
;
1496 ProcessContext(ALContext
);
1499 if((ALContext
=context
) != NULL
&& ALContext
->Device
)
1501 SuspendContext(ALContext
);
1502 ALContext
->InUse
=AL_TRUE
;
1503 ProcessContext(ALContext
);
1506 tls_set(LocalContext
, NULL
);
1510 alcSetError(ALC_INVALID_CONTEXT
);
1514 ProcessContext(NULL
);
1522 Makes the given Context the active Context for the current thread
1524 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
)
1526 ALboolean bReturn
= AL_TRUE
;
1528 SuspendContext(NULL
);
1530 // context must be a valid Context or NULL
1531 if(context
== NULL
|| IsContext(context
))
1532 tls_set(LocalContext
, context
);
1535 alcSetError(ALC_INVALID_CONTEXT
);
1539 ProcessContext(NULL
);
1545 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1546 void SetDefaultChannelOrder(ALCdevice
*device
)
1548 switch(aluChannelsFromFormat(device
->Format
))
1550 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1552 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1553 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1555 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1556 device
->DevChannels
[1] = FRONT_RIGHT
;
1557 device
->DevChannels
[2] = BACK_LEFT
;
1558 device
->DevChannels
[3] = BACK_RIGHT
; break;
1560 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1561 device
->DevChannels
[1] = FRONT_RIGHT
;
1562 device
->DevChannels
[2] = BACK_LEFT
;
1563 device
->DevChannels
[3] = BACK_RIGHT
;
1564 device
->DevChannels
[4] = FRONT_CENTER
;
1565 device
->DevChannels
[5] = LFE
; break;
1567 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1568 device
->DevChannels
[1] = FRONT_RIGHT
;
1569 device
->DevChannels
[2] = FRONT_CENTER
;
1570 device
->DevChannels
[3] = LFE
;
1571 device
->DevChannels
[4] = BACK_CENTER
;
1572 device
->DevChannels
[5] = SIDE_LEFT
;
1573 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1575 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1576 device
->DevChannels
[1] = FRONT_RIGHT
;
1577 device
->DevChannels
[2] = BACK_LEFT
;
1578 device
->DevChannels
[3] = BACK_RIGHT
;
1579 device
->DevChannels
[4] = FRONT_CENTER
;
1580 device
->DevChannels
[5] = LFE
;
1581 device
->DevChannels
[6] = SIDE_LEFT
;
1582 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1585 // Sets the default order used by WaveFormatEx
1586 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1588 switch(aluChannelsFromFormat(device
->Format
))
1590 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1592 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1593 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1595 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1596 device
->DevChannels
[1] = FRONT_RIGHT
;
1597 device
->DevChannels
[2] = BACK_LEFT
;
1598 device
->DevChannels
[3] = BACK_RIGHT
; break;
1600 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1601 device
->DevChannels
[1] = FRONT_RIGHT
;
1602 device
->DevChannels
[2] = FRONT_CENTER
;
1603 device
->DevChannels
[3] = LFE
;
1604 device
->DevChannels
[4] = BACK_LEFT
;
1605 device
->DevChannels
[5] = BACK_RIGHT
; break;
1607 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1608 device
->DevChannels
[1] = FRONT_RIGHT
;
1609 device
->DevChannels
[2] = FRONT_CENTER
;
1610 device
->DevChannels
[3] = LFE
;
1611 device
->DevChannels
[4] = BACK_CENTER
;
1612 device
->DevChannels
[5] = SIDE_LEFT
;
1613 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1615 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1616 device
->DevChannels
[1] = FRONT_RIGHT
;
1617 device
->DevChannels
[2] = FRONT_CENTER
;
1618 device
->DevChannels
[3] = LFE
;
1619 device
->DevChannels
[4] = BACK_LEFT
;
1620 device
->DevChannels
[5] = BACK_RIGHT
;
1621 device
->DevChannels
[6] = SIDE_LEFT
;
1622 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1626 static ALenum
GetFormatFromString(const char *str
)
1628 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1629 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1630 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1631 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1632 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1633 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1635 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1636 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1637 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1638 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1639 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1640 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1642 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1643 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1644 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1645 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1646 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1647 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1649 AL_PRINT("Unknown format: \"%s\"\n", str
);
1650 return AL_FORMAT_STEREO16
;
1656 Open the Device specified.
1658 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1660 ALboolean bDeviceFound
= AL_FALSE
;
1664 if(deviceName
&& !deviceName
[0])
1667 device
= malloc(sizeof(ALCdevice
));
1672 //Initialise device structure
1673 memset(device
, 0, sizeof(ALCdevice
));
1676 device
->Connected
= ALC_TRUE
;
1677 device
->IsCaptureDevice
= AL_FALSE
;
1679 device
->Bs2b
= NULL
;
1680 device
->szDeviceName
= NULL
;
1682 device
->Contexts
= NULL
;
1683 device
->NumContexts
= 0;
1686 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1687 if(device
->Frequency
== 0)
1688 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1690 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1691 device
->Format
= GetFormatFromString(fmt
);
1693 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1694 if(device
->NumUpdates
< 2)
1695 device
->NumUpdates
= 4;
1697 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1698 if(i
<= 0) i
= 4096;
1700 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1701 if(device
->UpdateSize
<= 0)
1702 device
->UpdateSize
= i
/device
->NumUpdates
;
1704 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1705 if((ALint
)device
->MaxNoOfSources
<= 0)
1706 device
->MaxNoOfSources
= 256;
1708 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1709 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1710 device
->AuxiliaryEffectSlotMax
= 4;
1712 device
->lNumStereoSources
= 1;
1713 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1715 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1716 if(device
->NumAuxSends
> MAX_SENDS
)
1717 device
->NumAuxSends
= MAX_SENDS
;
1719 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1721 if(aluChannelsFromFormat(device
->Format
) <= 2)
1723 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1724 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1725 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1728 device
->HeadDampen
= 0.0f
;
1730 // Find a playback device to open
1731 SuspendContext(NULL
);
1732 for(i
= 0;BackendList
[i
].Init
;i
++)
1734 device
->Funcs
= &BackendList
[i
].Funcs
;
1735 if(ALCdevice_OpenPlayback(device
, deviceName
))
1737 device
->next
= g_pDeviceList
;
1738 g_pDeviceList
= device
;
1741 bDeviceFound
= AL_TRUE
;
1745 ProcessContext(NULL
);
1749 // No suitable output device found
1750 alcSetError(ALC_INVALID_VALUE
);
1756 alcSetError(ALC_OUT_OF_MEMORY
);
1765 Close the specified Device
1767 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1769 ALCboolean bReturn
= ALC_FALSE
;
1772 if(IsDevice(pDevice
) && !pDevice
->IsCaptureDevice
)
1774 SuspendContext(NULL
);
1776 list
= &g_pDeviceList
;
1777 while(*list
!= pDevice
)
1778 list
= &(*list
)->next
;
1780 *list
= (*list
)->next
;
1783 ProcessContext(NULL
);
1785 if(pDevice
->NumContexts
> 0)
1788 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1790 while(pDevice
->NumContexts
> 0)
1791 alcDestroyContext(pDevice
->Contexts
[0]);
1793 ALCdevice_ClosePlayback(pDevice
);
1795 if(pDevice
->BufferCount
> 0)
1798 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1800 ReleaseALBuffers(pDevice
);
1802 if(pDevice
->EffectCount
> 0)
1805 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1807 ReleaseALEffects(pDevice
);
1809 if(pDevice
->FilterCount
> 0)
1812 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1814 ReleaseALFilters(pDevice
);
1816 if(pDevice
->DatabufferCount
> 0)
1819 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1821 ReleaseALDatabuffers(pDevice
);
1824 free(pDevice
->Bs2b
);
1825 pDevice
->Bs2b
= NULL
;
1827 free(pDevice
->szDeviceName
);
1828 pDevice
->szDeviceName
= NULL
;
1830 free(pDevice
->Contexts
);
1831 pDevice
->Contexts
= NULL
;
1833 //Release device structure
1834 memset(pDevice
, 0, sizeof(ALCdevice
));
1840 alcSetError(ALC_INVALID_DEVICE
);
1846 ALCvoid
ReleaseALC(ALCvoid
)
1848 free(alcDeviceList
); alcDeviceList
= NULL
;
1849 alcDeviceListSize
= 0;
1850 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
1851 alcAllDeviceListSize
= 0;
1852 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
1853 alcCaptureDeviceListSize
= 0;
1855 free(alcDefaultDeviceSpecifier
);
1856 alcDefaultDeviceSpecifier
= NULL
;
1857 free(alcDefaultAllDeviceSpecifier
);
1858 alcDefaultAllDeviceSpecifier
= NULL
;
1859 free(alcCaptureDefaultDeviceSpecifier
);
1860 alcCaptureDefaultDeviceSpecifier
= NULL
;
1863 if(g_ulDeviceCount
> 0)
1864 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1867 while(g_pDeviceList
)
1869 if(g_pDeviceList
->IsCaptureDevice
)
1870 alcCaptureCloseDevice(g_pDeviceList
);
1872 alcCloseDevice(g_pDeviceList
);
1876 ///////////////////////////////////////////////////////