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 const ALCchar alcExtensionList
[] =
184 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
185 "ALC_EXT_disconnect ALC_EXT_EFX ALC_EXTX_thread_local_context";
186 static const ALCint alcMajorVersion
= 1;
187 static const ALCint alcMinorVersion
= 1;
189 static const ALCint alcEFXMajorVersion
= 1;
190 static const ALCint alcEFXMinorVersion
= 0;
192 ///////////////////////////////////////////////////////
195 ///////////////////////////////////////////////////////
198 static ALCdevice
*g_pDeviceList
= NULL
;
199 static ALCuint g_ulDeviceCount
= 0;
201 static CRITICAL_SECTION g_csMutex
;
204 static ALCcontext
*g_pContextList
= NULL
;
205 static ALCuint g_ulContextCount
= 0;
207 // Thread-local current context
208 static tls_type LocalContext
;
211 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
213 // Default context extensions
214 static const ALchar alExtList
[] =
215 "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 "
216 "AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET "
217 "AL_EXTX_sample_buffer_object AL_EXT_source_distance_model "
218 "AL_LOKI_quadriphonic";
220 // Mixing Priority Level
224 resampler_t DefaultResampler
;
226 ///////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////
230 // ALC Related helper functions
232 static void alc_init(void);
233 static void alc_deinit(void);
235 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
239 // Perform actions based on the reason for calling.
240 switch(ul_reason_for_call
)
242 case DLL_PROCESS_ATTACH
:
243 DisableThreadLibraryCalls(hModule
);
247 case DLL_PROCESS_DETACH
:
254 #ifdef HAVE_GCC_DESTRUCTOR
255 static void alc_init(void) __attribute__((constructor
));
256 static void alc_deinit(void) __attribute__((destructor
));
260 static void alc_init(void)
263 const char *devs
, *str
;
265 InitializeCriticalSection(&g_csMutex
);
269 tls_create(&LocalContext
);
271 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
273 DefaultResampler
= GetConfigValueInt(NULL
, "resampler", RESAMPLER_DEFAULT
);
274 if(DefaultResampler
>= RESAMPLER_MAX
|| DefaultResampler
<= RESAMPLER_MIN
)
275 DefaultResampler
= RESAMPLER_DEFAULT
;
277 devs
= GetConfigValue(NULL
, "drivers", "");
282 const char *next
= devs
;
288 next
= strchr(devs
, ',');
290 if(!devs
[0] || devs
[0] == ',')
297 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
298 for(n
= i
;BackendList
[n
].Init
;n
++)
300 if(len
== strlen(BackendList
[n
].name
) &&
301 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
303 BackendInfo Bkp
= BackendList
[n
];
306 BackendList
[n
] = BackendList
[n
-1];
309 BackendList
[n
] = Bkp
;
319 BackendList
[i
].name
= NULL
;
320 BackendList
[i
].Init
= NULL
;
321 BackendList
[i
].Deinit
= NULL
;
322 BackendList
[i
].Probe
= NULL
;
326 for(i
= 0;BackendList
[i
].Init
;i
++)
327 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
329 DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 0);
331 str
= GetConfigValue(NULL
, "excludefx", "");
338 { "eaxreverb", EAXREVERB
},
339 { "reverb", REVERB
},
345 const char *next
= str
;
349 next
= strchr(str
, ',');
351 if(!str
[0] || next
== str
)
354 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
355 for(n
= 0;EffectList
[n
].name
;n
++)
357 if(len
== strlen(EffectList
[n
].name
) &&
358 strncmp(EffectList
[n
].name
, str
, len
) == 0)
359 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
365 static void alc_deinit(void)
371 for(i
= 0;BackendList
[i
].Deinit
;i
++)
372 BackendList
[i
].Deinit();
374 tls_delete(LocalContext
);
378 DeleteCriticalSection(&g_csMutex
);
382 static void ProbeDeviceList()
386 free(alcDeviceList
); alcDeviceList
= NULL
;
387 alcDeviceListSize
= 0;
389 for(i
= 0;BackendList
[i
].Probe
;i
++)
390 BackendList
[i
].Probe(DEVICE_PROBE
);
393 static void ProbeAllDeviceList()
397 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
398 alcAllDeviceListSize
= 0;
400 for(i
= 0;BackendList
[i
].Probe
;i
++)
401 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
404 static void ProbeCaptureDeviceList()
408 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
409 alcCaptureDeviceListSize
= 0;
411 for(i
= 0;BackendList
[i
].Probe
;i
++)
412 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
416 #define DECL_APPEND_LIST_FUNC(type) \
417 void Append##type##List(const ALCchar *name) \
419 ALCuint len = strlen(name); \
425 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
428 AL_PRINT("Realloc failed to add %s!\n", name); \
431 alc##type##List = temp; \
432 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
433 alc##type##ListSize += len+1; \
434 alc##type##List[alc##type##ListSize] = 0; \
437 DECL_APPEND_LIST_FUNC(Device
)
438 DECL_APPEND_LIST_FUNC(AllDevice
)
439 DECL_APPEND_LIST_FUNC(CaptureDevice
)
442 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
448 fn
= strrchr(fname
, '/');
449 if(!fn
) fn
= strrchr(fname
, '\\');;
453 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
454 if(i
< (int)sizeof(str
) && i
> 0)
458 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
461 str
[sizeof(str
)-1] = 0;
463 fprintf(stderr
, "%s", str
);
466 void EnableRTPrio(ALint level
)
472 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
474 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
475 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
476 struct sched_param param
;
480 /* Use the minimum real-time priority possible for now (on Linux this
481 * should be 1 for SCHED_RR) */
482 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
483 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
487 param
.sched_priority
= 0;
488 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
491 /* Real-time priority not available */
495 AL_PRINT("Failed to set priority level for thread\n");
502 Check pDevice is a valid Device pointer
504 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
506 ALCdevice
*pTempDevice
;
508 SuspendContext(NULL
);
510 pTempDevice
= g_pDeviceList
;
511 while(pTempDevice
&& pTempDevice
!= pDevice
)
512 pTempDevice
= pTempDevice
->next
;
514 ProcessContext(NULL
);
516 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
522 Check pContext is a valid Context pointer
524 static ALCboolean
IsContext(ALCcontext
*pContext
)
526 ALCcontext
*pTempContext
;
528 SuspendContext(NULL
);
530 pTempContext
= g_pContextList
;
531 while (pTempContext
&& pTempContext
!= pContext
)
532 pTempContext
= pTempContext
->next
;
534 ProcessContext(NULL
);
536 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
543 Store latest ALC Error
545 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
548 device
->LastError
= errorCode
;
550 g_eLastContextError
= errorCode
;
559 ALCvoid
SuspendContext(ALCcontext
*pContext
)
562 EnterCriticalSection(&g_csMutex
);
571 ALCvoid
ProcessContext(ALCcontext
*pContext
)
574 LeaveCriticalSection(&g_csMutex
);
581 Returns the currently active Context, in a locked state
583 ALCcontext
*GetContextSuspended(void)
585 ALCcontext
*pContext
= NULL
;
587 SuspendContext(NULL
);
589 pContext
= tls_get(LocalContext
);
590 if(pContext
&& !IsContext(pContext
))
592 tls_set(LocalContext
, NULL
);
597 pContext
= g_pContextList
;
598 while(pContext
&& !pContext
->InUse
)
599 pContext
= pContext
->next
;
602 SuspendContext(pContext
);
604 ProcessContext(NULL
);
613 Initialize Context variables
615 static ALvoid
InitContext(ALCcontext
*pContext
)
617 //Initialise listener
618 pContext
->Listener
.Gain
= 1.0f
;
619 pContext
->Listener
.MetersPerUnit
= 1.0f
;
620 pContext
->Listener
.Position
[0] = 0.0f
;
621 pContext
->Listener
.Position
[1] = 0.0f
;
622 pContext
->Listener
.Position
[2] = 0.0f
;
623 pContext
->Listener
.Velocity
[0] = 0.0f
;
624 pContext
->Listener
.Velocity
[1] = 0.0f
;
625 pContext
->Listener
.Velocity
[2] = 0.0f
;
626 pContext
->Listener
.Forward
[0] = 0.0f
;
627 pContext
->Listener
.Forward
[1] = 0.0f
;
628 pContext
->Listener
.Forward
[2] = -1.0f
;
629 pContext
->Listener
.Up
[0] = 0.0f
;
630 pContext
->Listener
.Up
[1] = 1.0f
;
631 pContext
->Listener
.Up
[2] = 0.0f
;
634 pContext
->LastError
= AL_NO_ERROR
;
635 pContext
->InUse
= AL_FALSE
;
636 pContext
->Suspended
= AL_FALSE
;
639 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
640 pContext
->SourceDistanceModel
= AL_FALSE
;
641 pContext
->DopplerFactor
= 1.0f
;
642 pContext
->DopplerVelocity
= 1.0f
;
643 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
645 pContext
->ExtensionList
= alExtList
;
652 Clean up Context, destroy any remaining Sources
654 static ALCvoid
ExitContext(ALCcontext
*pContext
)
657 pContext
->LastError
= AL_NO_ERROR
;
658 pContext
->InUse
= AL_FALSE
;
661 ///////////////////////////////////////////////////////
664 ///////////////////////////////////////////////////////
665 // ALC Functions calls
668 // This should probably move to another c file but for now ...
669 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
671 ALCboolean DeviceFound
= ALC_FALSE
;
672 ALCdevice
*pDevice
= NULL
;
677 alcSetError(NULL
, ALC_INVALID_VALUE
);
681 if(deviceName
&& !deviceName
[0])
684 if(!alcCaptureDeviceList
)
685 ProbeCaptureDeviceList();
687 pDevice
= malloc(sizeof(ALCdevice
));
690 //Initialise device structure
691 memset(pDevice
, 0, sizeof(ALCdevice
));
694 pDevice
->Connected
= ALC_TRUE
;
695 pDevice
->IsCaptureDevice
= AL_TRUE
;
697 pDevice
->szDeviceName
= NULL
;
699 pDevice
->Frequency
= frequency
;
700 pDevice
->Format
= format
;
701 pDevice
->UpdateSize
= SampleSize
;
702 pDevice
->NumUpdates
= 1;
704 SuspendContext(NULL
);
705 for(i
= 0;BackendList
[i
].Init
;i
++)
707 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
708 if(ALCdevice_OpenCapture(pDevice
, deviceName
))
710 pDevice
->next
= g_pDeviceList
;
711 g_pDeviceList
= pDevice
;
714 DeviceFound
= ALC_TRUE
;
718 ProcessContext(NULL
);
722 alcSetError(NULL
, ALC_INVALID_VALUE
);
728 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
733 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
735 ALCboolean bReturn
= ALC_FALSE
;
738 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
740 SuspendContext(NULL
);
742 list
= &g_pDeviceList
;
743 while(*list
!= pDevice
)
744 list
= &(*list
)->next
;
746 *list
= (*list
)->next
;
749 ProcessContext(NULL
);
751 ALCdevice_CloseCapture(pDevice
);
753 free(pDevice
->szDeviceName
);
754 pDevice
->szDeviceName
= NULL
;
761 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
766 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
768 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
769 ALCdevice_StartCapture(pDevice
);
771 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
774 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
776 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
777 ALCdevice_StopCapture(pDevice
);
779 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
782 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
784 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
785 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
787 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
793 Return last ALC generated error code
795 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
797 ALCenum errorCode
= ALC_NO_ERROR
;
801 errorCode
= device
->LastError
;
802 device
->LastError
= ALC_NO_ERROR
;
806 errorCode
= g_eLastContextError
;
807 g_eLastContextError
= ALC_NO_ERROR
;
818 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
820 SuspendContext(NULL
);
821 if(IsContext(pContext
))
822 pContext
->Suspended
= AL_TRUE
;
823 ProcessContext(NULL
);
832 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
834 SuspendContext(NULL
);
835 if(IsContext(pContext
))
836 pContext
->Suspended
= AL_FALSE
;
837 ProcessContext(NULL
);
844 Returns information about the Device, and error strings
846 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
848 const ALCchar
*value
= NULL
;
856 case ALC_INVALID_ENUM
:
857 value
= alcErrInvalidEnum
;
860 case ALC_INVALID_VALUE
:
861 value
= alcErrInvalidValue
;
864 case ALC_INVALID_DEVICE
:
865 value
= alcErrInvalidDevice
;
868 case ALC_INVALID_CONTEXT
:
869 value
= alcErrInvalidContext
;
872 case ALC_OUT_OF_MEMORY
:
873 value
= alcErrOutOfMemory
;
876 case ALC_DEVICE_SPECIFIER
:
877 if(IsDevice(pDevice
))
878 value
= pDevice
->szDeviceName
;
882 value
= alcDeviceList
;
886 case ALC_ALL_DEVICES_SPECIFIER
:
887 ProbeAllDeviceList();
888 value
= alcAllDeviceList
;
891 case ALC_CAPTURE_DEVICE_SPECIFIER
:
892 if(IsDevice(pDevice
))
893 value
= pDevice
->szDeviceName
;
896 ProbeCaptureDeviceList();
897 value
= alcCaptureDeviceList
;
901 /* Default devices are always first in the list */
902 case ALC_DEFAULT_DEVICE_SPECIFIER
:
906 free(alcDefaultDeviceSpecifier
);
907 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
908 if(!alcDefaultDeviceSpecifier
)
909 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
910 value
= alcDefaultDeviceSpecifier
;
913 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
914 if(!alcAllDeviceList
)
915 ProbeAllDeviceList();
917 free(alcDefaultAllDeviceSpecifier
);
918 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
919 alcAllDeviceList
: "");
920 if(!alcDefaultAllDeviceSpecifier
)
921 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
922 value
= alcDefaultAllDeviceSpecifier
;
925 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
926 if(!alcCaptureDeviceList
)
927 ProbeCaptureDeviceList();
929 free(alcCaptureDefaultDeviceSpecifier
);
930 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
931 alcCaptureDeviceList
: "");
932 if(!alcCaptureDefaultDeviceSpecifier
)
933 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
934 value
= alcCaptureDefaultDeviceSpecifier
;
938 value
= alcExtensionList
;
942 alcSetError(pDevice
, ALC_INVALID_ENUM
);
953 Returns information about the Device and the version of Open AL
955 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
957 if(size
== 0 || data
== NULL
)
959 alcSetError(device
, ALC_INVALID_VALUE
);
963 if(IsDevice(device
) && device
->IsCaptureDevice
)
965 SuspendContext(NULL
);
970 case ALC_CAPTURE_SAMPLES
:
971 *data
= ALCdevice_AvailableSamples(device
);
975 *data
= device
->Connected
;
979 alcSetError(device
, ALC_INVALID_ENUM
);
983 ProcessContext(NULL
);
990 case ALC_MAJOR_VERSION
:
991 *data
= alcMajorVersion
;
994 case ALC_MINOR_VERSION
:
995 *data
= alcMinorVersion
;
998 case ALC_EFX_MAJOR_VERSION
:
999 *data
= alcEFXMajorVersion
;
1002 case ALC_EFX_MINOR_VERSION
:
1003 *data
= alcEFXMinorVersion
;
1006 case ALC_MAX_AUXILIARY_SENDS
:
1007 if(!IsDevice(device
))
1008 alcSetError(device
, ALC_INVALID_DEVICE
);
1010 *data
= device
->NumAuxSends
;
1013 case ALC_ATTRIBUTES_SIZE
:
1014 if(!IsDevice(device
))
1015 alcSetError(device
, ALC_INVALID_DEVICE
);
1020 case ALC_ALL_ATTRIBUTES
:
1021 if(!IsDevice(device
))
1022 alcSetError(device
, ALC_INVALID_DEVICE
);
1024 alcSetError(device
, ALC_INVALID_VALUE
);
1029 SuspendContext(NULL
);
1030 data
[i
++] = ALC_FREQUENCY
;
1031 data
[i
++] = device
->Frequency
;
1033 data
[i
++] = ALC_REFRESH
;
1034 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
1036 data
[i
++] = ALC_SYNC
;
1037 data
[i
++] = ALC_FALSE
;
1039 data
[i
++] = ALC_MONO_SOURCES
;
1040 data
[i
++] = device
->lNumMonoSources
;
1042 data
[i
++] = ALC_STEREO_SOURCES
;
1043 data
[i
++] = device
->lNumStereoSources
;
1045 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1046 data
[i
++] = device
->NumAuxSends
;
1049 ProcessContext(NULL
);
1054 if(!IsDevice(device
))
1055 alcSetError(device
, ALC_INVALID_DEVICE
);
1057 *data
= device
->Frequency
;
1061 if(!IsDevice(device
))
1062 alcSetError(device
, ALC_INVALID_DEVICE
);
1064 *data
= device
->Frequency
/ device
->UpdateSize
;
1068 if(!IsDevice(device
))
1069 alcSetError(device
, ALC_INVALID_DEVICE
);
1074 case ALC_MONO_SOURCES
:
1075 if(!IsDevice(device
))
1076 alcSetError(device
, ALC_INVALID_DEVICE
);
1078 *data
= device
->lNumMonoSources
;
1081 case ALC_STEREO_SOURCES
:
1082 if(!IsDevice(device
))
1083 alcSetError(device
, ALC_INVALID_DEVICE
);
1085 *data
= device
->lNumStereoSources
;
1089 if(!IsDevice(device
))
1090 alcSetError(device
, ALC_INVALID_DEVICE
);
1092 *data
= device
->Connected
;
1096 alcSetError(device
, ALC_INVALID_ENUM
);
1103 alcIsExtensionPresent
1105 Determines if there is support for a particular extension
1107 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1109 ALCboolean bResult
= ALC_FALSE
;
1116 len
= strlen(extName
);
1117 ptr
= alcExtensionList
;
1120 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1121 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1126 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1130 } while(isspace(*ptr
));
1135 alcSetError(device
, ALC_INVALID_VALUE
);
1144 Retrieves the function address for a particular extension function
1146 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1148 ALCvoid
*pFunction
= NULL
;
1153 while(alcFunctions
[i
].funcName
&&
1154 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1156 pFunction
= alcFunctions
[i
].address
;
1159 alcSetError(device
, ALC_INVALID_VALUE
);
1168 Get the value for a particular ALC Enumerated Value
1170 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1175 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1177 val
= enumeration
[i
].value
;
1179 if(!enumeration
[i
].enumName
)
1180 alcSetError(device
, ALC_INVALID_VALUE
);
1189 Create and attach a Context to a particular Device.
1191 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1193 ALuint attrIdx
, reqStereoSources
;
1194 ALCcontext
*ALContext
;
1198 SuspendContext(NULL
);
1200 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1202 alcSetError(device
, ALC_INVALID_DEVICE
);
1203 ProcessContext(NULL
);
1207 // Reset Context Last Error code
1208 device
->LastError
= ALC_NO_ERROR
;
1210 // If a context is already running on the device, stop playback so the
1211 // device attributes can be updated
1212 if(device
->NumContexts
> 0)
1214 ProcessContext(NULL
);
1215 ALCdevice_StopPlayback(device
);
1216 SuspendContext(NULL
);
1219 // Check for attributes
1222 ALCint level
= device
->Bs2bLevel
;
1223 ALCuint freq
= device
->Frequency
;
1224 ALCint numMono
= device
->lNumMonoSources
;
1225 ALCint numStereo
= device
->lNumStereoSources
;
1226 ALCuint numSends
= device
->NumAuxSends
;
1229 while(attrList
[attrIdx
])
1231 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
1232 !ConfigValueExists(NULL
, "frequency"))
1234 freq
= attrList
[attrIdx
+ 1];
1239 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1241 reqStereoSources
= attrList
[attrIdx
+ 1];
1242 if(reqStereoSources
> device
->MaxNoOfSources
)
1243 reqStereoSources
= device
->MaxNoOfSources
;
1245 numStereo
= reqStereoSources
;
1246 numMono
= device
->MaxNoOfSources
- numStereo
;
1249 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
1250 !ConfigValueExists(NULL
, "sends"))
1252 numSends
= attrList
[attrIdx
+ 1];
1253 if(numSends
> MAX_SENDS
)
1254 numSends
= MAX_SENDS
;
1260 device
->UpdateSize
= (ALuint64
)device
->UpdateSize
* freq
/
1263 device
->Bs2bLevel
= level
;
1264 device
->Frequency
= freq
;
1265 device
->lNumMonoSources
= numMono
;
1266 device
->lNumStereoSources
= numStereo
;
1267 device
->NumAuxSends
= numSends
;
1270 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1272 alcSetError(device
, ALC_INVALID_DEVICE
);
1273 aluHandleDisconnect(device
);
1274 ProcessContext(NULL
);
1278 for(i
= 0;i
< device
->NumContexts
;i
++)
1280 ALCcontext
*context
= device
->Contexts
[i
];
1284 SuspendContext(context
);
1285 for(slot
= context
->AuxiliaryEffectSlot
;slot
!= NULL
;slot
= slot
->next
)
1287 if(!slot
->EffectState
)
1290 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1292 alcSetError(device
, ALC_INVALID_DEVICE
);
1293 aluHandleDisconnect(device
);
1294 ProcessContext(context
);
1295 ProcessContext(NULL
);
1296 ALCdevice_StopPlayback(device
);
1299 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1302 for(source
= context
->Source
;source
!= NULL
;source
= source
->next
)
1304 ALuint s
= device
->NumAuxSends
;
1305 while(s
< MAX_SENDS
)
1307 if(source
->Send
[s
].Slot
)
1308 source
->Send
[s
].Slot
->refcount
--;
1309 source
->Send
[s
].Slot
= NULL
;
1310 source
->Send
[s
].WetFilter
.type
= 0;
1311 source
->Send
[s
].WetFilter
.filter
= 0;
1314 source
->NeedsUpdate
= AL_TRUE
;
1316 aluInitPanning(context
);
1317 ProcessContext(context
);
1320 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1324 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1325 bs2b_clear(device
->Bs2b
);
1327 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1328 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1333 device
->Bs2b
= NULL
;
1336 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1339 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1340 ProcessContext(NULL
);
1343 device
->Contexts
= temp
;
1345 ALContext
= calloc(1, sizeof(ALCcontext
));
1348 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1349 ProcessContext(NULL
);
1353 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1354 ALContext
->Device
= device
;
1356 InitContext(ALContext
);
1357 aluInitPanning(ALContext
);
1359 ALContext
->next
= g_pContextList
;
1360 g_pContextList
= ALContext
;
1363 ProcessContext(NULL
);
1374 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1379 if (IsContext(context
))
1381 ALCdevice
*Device
= context
->Device
;
1383 if(Device
->NumContexts
== 1)
1384 ALCdevice_StopPlayback(Device
);
1386 SuspendContext(NULL
);
1388 for(i
= 0;i
< Device
->NumContexts
-1;i
++)
1390 if(Device
->Contexts
[i
] == context
)
1392 memmove(&Device
->Contexts
[i
], &Device
->Contexts
[i
+1],
1393 (Device
->NumContexts
-i
-1) * sizeof(*Device
->Contexts
));
1397 Device
->NumContexts
--;
1400 SuspendContext(context
);
1402 if(context
->SourceCount
> 0)
1405 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceCount
);
1407 ReleaseALSources(context
);
1409 if(context
->AuxiliaryEffectSlotCount
> 0)
1412 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->AuxiliaryEffectSlotCount
);
1414 ReleaseALAuxiliaryEffectSlots(context
);
1417 list
= &g_pContextList
;
1418 while(*list
!= context
)
1419 list
= &(*list
)->next
;
1421 *list
= (*list
)->next
;
1425 ProcessContext(context
);
1426 ProcessContext(NULL
);
1428 ExitContext(context
);
1430 // Free memory (MUST do this after ProcessContext)
1431 memset(context
, 0, sizeof(ALCcontext
));
1435 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1440 alcGetCurrentContext
1442 Returns the currently active Context
1444 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1446 ALCcontext
*pContext
;
1448 if((pContext
=GetContextSuspended()) != NULL
)
1449 ProcessContext(pContext
);
1457 Returns the currently active thread-local Context
1459 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void)
1461 ALCcontext
*pContext
= NULL
;
1463 SuspendContext(NULL
);
1465 pContext
= tls_get(LocalContext
);
1466 if(pContext
&& !IsContext(pContext
))
1468 tls_set(LocalContext
, NULL
);
1472 ProcessContext(NULL
);
1479 alcGetContextsDevice
1481 Returns the Device that a particular Context is attached to
1483 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1485 ALCdevice
*pDevice
= NULL
;
1487 SuspendContext(NULL
);
1488 if (IsContext(pContext
))
1489 pDevice
= pContext
->Device
;
1491 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1492 ProcessContext(NULL
);
1499 alcMakeContextCurrent
1501 Makes the given Context the active Context
1503 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1505 ALCcontext
*ALContext
;
1506 ALboolean bReturn
= AL_TRUE
;
1508 SuspendContext(NULL
);
1510 // context must be a valid Context or NULL
1511 if(context
== NULL
|| IsContext(context
))
1513 ALContext
= g_pContextList
;
1514 while(ALContext
&& !ALContext
->InUse
)
1515 ALContext
= ALContext
->next
;
1517 if(ALContext
!= NULL
)
1519 SuspendContext(ALContext
);
1520 ALContext
->InUse
=AL_FALSE
;
1521 ProcessContext(ALContext
);
1524 if((ALContext
=context
) != NULL
&& ALContext
->Device
)
1526 SuspendContext(ALContext
);
1527 ALContext
->InUse
=AL_TRUE
;
1528 ProcessContext(ALContext
);
1531 tls_set(LocalContext
, NULL
);
1535 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1539 ProcessContext(NULL
);
1547 Makes the given Context the active Context for the current thread
1549 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
)
1551 ALboolean bReturn
= AL_TRUE
;
1553 SuspendContext(NULL
);
1555 // context must be a valid Context or NULL
1556 if(context
== NULL
|| IsContext(context
))
1557 tls_set(LocalContext
, context
);
1560 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1564 ProcessContext(NULL
);
1570 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1571 void SetDefaultChannelOrder(ALCdevice
*device
)
1573 switch(aluChannelsFromFormat(device
->Format
))
1575 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1577 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1578 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1580 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1581 device
->DevChannels
[1] = FRONT_RIGHT
;
1582 device
->DevChannels
[2] = BACK_LEFT
;
1583 device
->DevChannels
[3] = BACK_RIGHT
; break;
1585 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1586 device
->DevChannels
[1] = FRONT_RIGHT
;
1587 device
->DevChannels
[2] = BACK_LEFT
;
1588 device
->DevChannels
[3] = BACK_RIGHT
;
1589 device
->DevChannels
[4] = FRONT_CENTER
;
1590 device
->DevChannels
[5] = LFE
; break;
1592 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1593 device
->DevChannels
[1] = FRONT_RIGHT
;
1594 device
->DevChannels
[2] = FRONT_CENTER
;
1595 device
->DevChannels
[3] = LFE
;
1596 device
->DevChannels
[4] = BACK_CENTER
;
1597 device
->DevChannels
[5] = SIDE_LEFT
;
1598 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1600 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1601 device
->DevChannels
[1] = FRONT_RIGHT
;
1602 device
->DevChannels
[2] = BACK_LEFT
;
1603 device
->DevChannels
[3] = BACK_RIGHT
;
1604 device
->DevChannels
[4] = FRONT_CENTER
;
1605 device
->DevChannels
[5] = LFE
;
1606 device
->DevChannels
[6] = SIDE_LEFT
;
1607 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1610 // Sets the default order used by WaveFormatEx
1611 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1613 switch(aluChannelsFromFormat(device
->Format
))
1615 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1617 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1618 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1620 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1621 device
->DevChannels
[1] = FRONT_RIGHT
;
1622 device
->DevChannels
[2] = BACK_LEFT
;
1623 device
->DevChannels
[3] = BACK_RIGHT
; break;
1625 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1626 device
->DevChannels
[1] = FRONT_RIGHT
;
1627 device
->DevChannels
[2] = FRONT_CENTER
;
1628 device
->DevChannels
[3] = LFE
;
1629 device
->DevChannels
[4] = BACK_LEFT
;
1630 device
->DevChannels
[5] = BACK_RIGHT
; break;
1632 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1633 device
->DevChannels
[1] = FRONT_RIGHT
;
1634 device
->DevChannels
[2] = FRONT_CENTER
;
1635 device
->DevChannels
[3] = LFE
;
1636 device
->DevChannels
[4] = BACK_CENTER
;
1637 device
->DevChannels
[5] = SIDE_LEFT
;
1638 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1640 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1641 device
->DevChannels
[1] = FRONT_RIGHT
;
1642 device
->DevChannels
[2] = FRONT_CENTER
;
1643 device
->DevChannels
[3] = LFE
;
1644 device
->DevChannels
[4] = BACK_LEFT
;
1645 device
->DevChannels
[5] = BACK_RIGHT
;
1646 device
->DevChannels
[6] = SIDE_LEFT
;
1647 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1651 static ALenum
GetFormatFromString(const char *str
)
1653 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1654 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1655 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1656 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1657 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1658 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1660 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1661 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1662 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1663 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1664 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1665 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1667 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1668 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1669 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1670 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1671 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1672 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1674 AL_PRINT("Unknown format: \"%s\"\n", str
);
1675 return AL_FORMAT_STEREO16
;
1681 Open the Device specified.
1683 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1685 ALboolean bDeviceFound
= AL_FALSE
;
1689 if(deviceName
&& !deviceName
[0])
1694 if(!alcAllDeviceList
)
1695 ProbeAllDeviceList();
1697 device
= malloc(sizeof(ALCdevice
));
1702 //Initialise device structure
1703 memset(device
, 0, sizeof(ALCdevice
));
1706 device
->Connected
= ALC_TRUE
;
1707 device
->IsCaptureDevice
= AL_FALSE
;
1708 device
->LastError
= ALC_NO_ERROR
;
1710 device
->Bs2b
= NULL
;
1711 device
->szDeviceName
= NULL
;
1713 device
->Contexts
= NULL
;
1714 device
->NumContexts
= 0;
1717 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1718 if(device
->Frequency
< 8000)
1719 device
->Frequency
= 8000;
1721 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1722 device
->Format
= GetFormatFromString(fmt
);
1724 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1725 if(device
->NumUpdates
< 2)
1726 device
->NumUpdates
= 4;
1728 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1729 if(i
<= 0) i
= 4096;
1731 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1732 if(device
->UpdateSize
<= 0)
1733 device
->UpdateSize
= i
/device
->NumUpdates
;
1735 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1736 if((ALint
)device
->MaxNoOfSources
<= 0)
1737 device
->MaxNoOfSources
= 256;
1739 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1740 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1741 device
->AuxiliaryEffectSlotMax
= 4;
1743 device
->lNumStereoSources
= 1;
1744 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1746 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1747 if(device
->NumAuxSends
> MAX_SENDS
)
1748 device
->NumAuxSends
= MAX_SENDS
;
1750 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1752 if(aluChannelsFromFormat(device
->Format
) <= 2)
1754 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1755 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1756 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1759 device
->HeadDampen
= 0.0f
;
1761 // Find a playback device to open
1762 SuspendContext(NULL
);
1763 for(i
= 0;BackendList
[i
].Init
;i
++)
1765 device
->Funcs
= &BackendList
[i
].Funcs
;
1766 if(ALCdevice_OpenPlayback(device
, deviceName
))
1768 device
->next
= g_pDeviceList
;
1769 g_pDeviceList
= device
;
1772 bDeviceFound
= AL_TRUE
;
1776 ProcessContext(NULL
);
1780 // No suitable output device found
1781 alcSetError(NULL
, ALC_INVALID_VALUE
);
1787 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1796 Close the specified Device
1798 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1800 ALCboolean bReturn
= ALC_FALSE
;
1803 if(IsDevice(pDevice
) && !pDevice
->IsCaptureDevice
)
1805 SuspendContext(NULL
);
1807 list
= &g_pDeviceList
;
1808 while(*list
!= pDevice
)
1809 list
= &(*list
)->next
;
1811 *list
= (*list
)->next
;
1814 ProcessContext(NULL
);
1816 if(pDevice
->NumContexts
> 0)
1819 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1821 while(pDevice
->NumContexts
> 0)
1822 alcDestroyContext(pDevice
->Contexts
[0]);
1824 ALCdevice_ClosePlayback(pDevice
);
1826 if(pDevice
->BufferCount
> 0)
1829 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1831 ReleaseALBuffers(pDevice
);
1833 if(pDevice
->EffectCount
> 0)
1836 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1838 ReleaseALEffects(pDevice
);
1840 if(pDevice
->FilterCount
> 0)
1843 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1845 ReleaseALFilters(pDevice
);
1847 if(pDevice
->DatabufferCount
> 0)
1850 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1852 ReleaseALDatabuffers(pDevice
);
1855 free(pDevice
->Bs2b
);
1856 pDevice
->Bs2b
= NULL
;
1858 free(pDevice
->szDeviceName
);
1859 pDevice
->szDeviceName
= NULL
;
1861 free(pDevice
->Contexts
);
1862 pDevice
->Contexts
= NULL
;
1864 //Release device structure
1865 memset(pDevice
, 0, sizeof(ALCdevice
));
1871 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
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 ///////////////////////////////////////////////////////