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 // Default context extensions
212 static const ALchar alExtList
[] =
213 "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 "
214 "AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET "
215 "AL_EXTX_sample_buffer_object AL_EXT_source_distance_model "
216 "AL_LOKI_quadriphonic";
218 // Mixing Priority Level
222 resampler_t DefaultResampler
;
224 ///////////////////////////////////////////////////////
227 ///////////////////////////////////////////////////////
228 // ALC Related helper functions
230 static void alc_init(void);
231 static void alc_deinit(void);
233 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
237 // Perform actions based on the reason for calling.
238 switch(ul_reason_for_call
)
240 case DLL_PROCESS_ATTACH
:
241 DisableThreadLibraryCalls(hModule
);
245 case DLL_PROCESS_DETACH
:
252 #ifdef HAVE_GCC_DESTRUCTOR
253 static void alc_init(void) __attribute__((constructor
));
254 static void alc_deinit(void) __attribute__((destructor
));
258 static void alc_init(void)
261 const char *devs
, *str
;
263 InitializeCriticalSection(&g_csMutex
);
267 tls_create(&LocalContext
);
269 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
271 DefaultResampler
= GetConfigValueInt(NULL
, "resampler", RESAMPLER_DEFAULT
);
272 if(DefaultResampler
>= RESAMPLER_MAX
|| DefaultResampler
<= RESAMPLER_MIN
)
273 DefaultResampler
= RESAMPLER_DEFAULT
;
275 devs
= GetConfigValue(NULL
, "drivers", "");
280 const char *next
= devs
;
286 next
= strchr(devs
, ',');
288 if(!devs
[0] || devs
[0] == ',')
295 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
296 for(n
= i
;BackendList
[n
].Init
;n
++)
298 if(len
== strlen(BackendList
[n
].name
) &&
299 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
301 BackendInfo Bkp
= BackendList
[n
];
304 BackendList
[n
] = BackendList
[n
-1];
307 BackendList
[n
] = Bkp
;
317 BackendList
[i
].name
= NULL
;
318 BackendList
[i
].Init
= NULL
;
319 BackendList
[i
].Deinit
= NULL
;
320 BackendList
[i
].Probe
= NULL
;
324 for(i
= 0;BackendList
[i
].Init
;i
++)
325 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
327 DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 0);
329 str
= GetConfigValue(NULL
, "excludefx", "");
336 { "eaxreverb", EAXREVERB
},
337 { "reverb", REVERB
},
343 const char *next
= str
;
347 next
= strchr(str
, ',');
349 if(!str
[0] || next
== str
)
352 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
353 for(n
= 0;EffectList
[n
].name
;n
++)
355 if(len
== strlen(EffectList
[n
].name
) &&
356 strncmp(EffectList
[n
].name
, str
, len
) == 0)
357 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
363 static void alc_deinit(void)
369 for(i
= 0;BackendList
[i
].Deinit
;i
++)
370 BackendList
[i
].Deinit();
372 tls_delete(LocalContext
);
376 DeleteCriticalSection(&g_csMutex
);
380 static void ProbeDeviceList()
384 free(alcDeviceList
); alcDeviceList
= NULL
;
385 alcDeviceListSize
= 0;
387 for(i
= 0;BackendList
[i
].Probe
;i
++)
388 BackendList
[i
].Probe(DEVICE_PROBE
);
391 static void ProbeAllDeviceList()
395 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
396 alcAllDeviceListSize
= 0;
398 for(i
= 0;BackendList
[i
].Probe
;i
++)
399 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
402 static void ProbeCaptureDeviceList()
406 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
407 alcCaptureDeviceListSize
= 0;
409 for(i
= 0;BackendList
[i
].Probe
;i
++)
410 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
414 #define DECL_APPEND_LIST_FUNC(type) \
415 void Append##type##List(const ALCchar *name) \
417 ALCuint len = strlen(name); \
423 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
426 AL_PRINT("Realloc failed to add %s!\n", name); \
429 alc##type##List = temp; \
430 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
431 alc##type##ListSize += len+1; \
432 alc##type##List[alc##type##ListSize] = 0; \
435 DECL_APPEND_LIST_FUNC(Device
)
436 DECL_APPEND_LIST_FUNC(AllDevice
)
437 DECL_APPEND_LIST_FUNC(CaptureDevice
)
440 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
446 fn
= strrchr(fname
, '/');
447 if(!fn
) fn
= strrchr(fname
, '\\');;
451 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
452 if(i
< (int)sizeof(str
) && i
> 0)
456 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
459 str
[sizeof(str
)-1] = 0;
461 fprintf(stderr
, "%s", str
);
464 void EnableRTPrio(ALint level
)
470 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
472 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
473 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
474 struct sched_param param
;
478 /* Use the minimum real-time priority possible for now (on Linux this
479 * should be 1 for SCHED_RR) */
480 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
481 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
485 param
.sched_priority
= 0;
486 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
489 /* Real-time priority not available */
493 AL_PRINT("Failed to set priority level for thread\n");
500 Check pDevice is a valid Device pointer
502 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
504 ALCdevice
*pTempDevice
;
506 SuspendContext(NULL
);
508 pTempDevice
= g_pDeviceList
;
509 while(pTempDevice
&& pTempDevice
!= pDevice
)
510 pTempDevice
= pTempDevice
->next
;
512 ProcessContext(NULL
);
514 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
520 Check pContext is a valid Context pointer
522 static ALCboolean
IsContext(ALCcontext
*pContext
)
524 ALCcontext
*pTempContext
;
526 SuspendContext(NULL
);
528 pTempContext
= g_pContextList
;
529 while (pTempContext
&& pTempContext
!= pContext
)
530 pTempContext
= pTempContext
->next
;
532 ProcessContext(NULL
);
534 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
541 Store latest ALC Error
543 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
546 device
->LastError
= errorCode
;
548 g_eLastContextError
= errorCode
;
557 ALCvoid
SuspendContext(ALCcontext
*pContext
)
560 EnterCriticalSection(&g_csMutex
);
569 ALCvoid
ProcessContext(ALCcontext
*pContext
)
572 LeaveCriticalSection(&g_csMutex
);
579 Returns the currently active Context, in a locked state
581 ALCcontext
*GetContextSuspended(void)
583 ALCcontext
*pContext
= NULL
;
585 SuspendContext(NULL
);
587 pContext
= tls_get(LocalContext
);
588 if(pContext
&& !IsContext(pContext
))
590 tls_set(LocalContext
, NULL
);
595 pContext
= g_pContextList
;
596 while(pContext
&& !pContext
->InUse
)
597 pContext
= pContext
->next
;
600 SuspendContext(pContext
);
602 ProcessContext(NULL
);
611 Initialize Context variables
613 static ALvoid
InitContext(ALCcontext
*pContext
)
615 //Initialise listener
616 pContext
->Listener
.Gain
= 1.0f
;
617 pContext
->Listener
.MetersPerUnit
= 1.0f
;
618 pContext
->Listener
.Position
[0] = 0.0f
;
619 pContext
->Listener
.Position
[1] = 0.0f
;
620 pContext
->Listener
.Position
[2] = 0.0f
;
621 pContext
->Listener
.Velocity
[0] = 0.0f
;
622 pContext
->Listener
.Velocity
[1] = 0.0f
;
623 pContext
->Listener
.Velocity
[2] = 0.0f
;
624 pContext
->Listener
.Forward
[0] = 0.0f
;
625 pContext
->Listener
.Forward
[1] = 0.0f
;
626 pContext
->Listener
.Forward
[2] = -1.0f
;
627 pContext
->Listener
.Up
[0] = 0.0f
;
628 pContext
->Listener
.Up
[1] = 1.0f
;
629 pContext
->Listener
.Up
[2] = 0.0f
;
632 pContext
->LastError
= AL_NO_ERROR
;
633 pContext
->InUse
= AL_FALSE
;
634 pContext
->Suspended
= AL_FALSE
;
637 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
638 pContext
->SourceDistanceModel
= AL_FALSE
;
639 pContext
->DopplerFactor
= 1.0f
;
640 pContext
->DopplerVelocity
= 1.0f
;
641 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
643 pContext
->ExtensionList
= alExtList
;
650 Clean up Context, destroy any remaining Sources
652 static ALCvoid
ExitContext(ALCcontext
*pContext
)
655 pContext
->LastError
= AL_NO_ERROR
;
656 pContext
->InUse
= AL_FALSE
;
659 ///////////////////////////////////////////////////////
662 ///////////////////////////////////////////////////////
663 // ALC Functions calls
666 // This should probably move to another c file but for now ...
667 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
669 ALCboolean DeviceFound
= ALC_FALSE
;
670 ALCdevice
*pDevice
= NULL
;
675 alcSetError(NULL
, ALC_INVALID_VALUE
);
679 if(deviceName
&& !deviceName
[0])
682 if(!alcCaptureDeviceList
)
683 ProbeCaptureDeviceList();
685 pDevice
= malloc(sizeof(ALCdevice
));
688 //Initialise device structure
689 memset(pDevice
, 0, sizeof(ALCdevice
));
692 pDevice
->Connected
= ALC_TRUE
;
693 pDevice
->IsCaptureDevice
= AL_TRUE
;
695 pDevice
->szDeviceName
= NULL
;
697 pDevice
->Frequency
= frequency
;
698 pDevice
->Format
= format
;
699 pDevice
->UpdateSize
= SampleSize
;
700 pDevice
->NumUpdates
= 1;
702 SuspendContext(NULL
);
703 for(i
= 0;BackendList
[i
].Init
;i
++)
705 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
706 if(ALCdevice_OpenCapture(pDevice
, deviceName
))
708 pDevice
->next
= g_pDeviceList
;
709 g_pDeviceList
= pDevice
;
712 DeviceFound
= ALC_TRUE
;
716 ProcessContext(NULL
);
720 alcSetError(NULL
, ALC_INVALID_VALUE
);
726 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
731 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
733 ALCboolean bReturn
= ALC_FALSE
;
736 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
738 SuspendContext(NULL
);
740 list
= &g_pDeviceList
;
741 while(*list
!= pDevice
)
742 list
= &(*list
)->next
;
744 *list
= (*list
)->next
;
747 ProcessContext(NULL
);
749 ALCdevice_CloseCapture(pDevice
);
751 free(pDevice
->szDeviceName
);
752 pDevice
->szDeviceName
= NULL
;
759 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
764 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
766 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
767 ALCdevice_StartCapture(pDevice
);
769 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
772 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
774 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
775 ALCdevice_StopCapture(pDevice
);
777 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
780 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
782 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
783 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
785 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
791 Return last ALC generated error code
793 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
795 ALCenum errorCode
= ALC_NO_ERROR
;
799 errorCode
= device
->LastError
;
800 device
->LastError
= ALC_NO_ERROR
;
804 errorCode
= g_eLastContextError
;
805 g_eLastContextError
= ALC_NO_ERROR
;
816 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
818 SuspendContext(NULL
);
819 if(IsContext(pContext
))
820 pContext
->Suspended
= AL_TRUE
;
821 ProcessContext(NULL
);
830 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
832 SuspendContext(NULL
);
833 if(IsContext(pContext
))
834 pContext
->Suspended
= AL_FALSE
;
835 ProcessContext(NULL
);
842 Returns information about the Device, and error strings
844 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
846 const ALCchar
*value
= NULL
;
854 case ALC_INVALID_ENUM
:
855 value
= alcErrInvalidEnum
;
858 case ALC_INVALID_VALUE
:
859 value
= alcErrInvalidValue
;
862 case ALC_INVALID_DEVICE
:
863 value
= alcErrInvalidDevice
;
866 case ALC_INVALID_CONTEXT
:
867 value
= alcErrInvalidContext
;
870 case ALC_OUT_OF_MEMORY
:
871 value
= alcErrOutOfMemory
;
874 case ALC_DEVICE_SPECIFIER
:
875 if(IsDevice(pDevice
))
876 value
= pDevice
->szDeviceName
;
880 value
= alcDeviceList
;
884 case ALC_ALL_DEVICES_SPECIFIER
:
885 ProbeAllDeviceList();
886 value
= alcAllDeviceList
;
889 case ALC_CAPTURE_DEVICE_SPECIFIER
:
890 if(IsDevice(pDevice
))
891 value
= pDevice
->szDeviceName
;
894 ProbeCaptureDeviceList();
895 value
= alcCaptureDeviceList
;
899 /* Default devices are always first in the list */
900 case ALC_DEFAULT_DEVICE_SPECIFIER
:
904 free(alcDefaultDeviceSpecifier
);
905 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
906 if(!alcDefaultDeviceSpecifier
)
907 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
908 value
= alcDefaultDeviceSpecifier
;
911 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
912 if(!alcAllDeviceList
)
913 ProbeAllDeviceList();
915 free(alcDefaultAllDeviceSpecifier
);
916 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
917 alcAllDeviceList
: "");
918 if(!alcDefaultAllDeviceSpecifier
)
919 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
920 value
= alcDefaultAllDeviceSpecifier
;
923 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
924 if(!alcCaptureDeviceList
)
925 ProbeCaptureDeviceList();
927 free(alcCaptureDefaultDeviceSpecifier
);
928 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
929 alcCaptureDeviceList
: "");
930 if(!alcCaptureDefaultDeviceSpecifier
)
931 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
932 value
= alcCaptureDefaultDeviceSpecifier
;
936 value
= alcExtensionList
;
940 alcSetError(pDevice
, ALC_INVALID_ENUM
);
951 Returns information about the Device and the version of Open AL
953 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
955 if(size
== 0 || data
== NULL
)
957 alcSetError(device
, ALC_INVALID_VALUE
);
961 if(IsDevice(device
) && device
->IsCaptureDevice
)
963 SuspendContext(NULL
);
968 case ALC_CAPTURE_SAMPLES
:
969 *data
= ALCdevice_AvailableSamples(device
);
973 *data
= device
->Connected
;
977 alcSetError(device
, ALC_INVALID_ENUM
);
981 ProcessContext(NULL
);
988 case ALC_MAJOR_VERSION
:
989 *data
= alcMajorVersion
;
992 case ALC_MINOR_VERSION
:
993 *data
= alcMinorVersion
;
996 case ALC_EFX_MAJOR_VERSION
:
997 *data
= alcEFXMajorVersion
;
1000 case ALC_EFX_MINOR_VERSION
:
1001 *data
= alcEFXMinorVersion
;
1004 case ALC_MAX_AUXILIARY_SENDS
:
1005 if(!IsDevice(device
))
1006 alcSetError(device
, ALC_INVALID_DEVICE
);
1008 *data
= device
->NumAuxSends
;
1011 case ALC_ATTRIBUTES_SIZE
:
1012 if(!IsDevice(device
))
1013 alcSetError(device
, ALC_INVALID_DEVICE
);
1018 case ALC_ALL_ATTRIBUTES
:
1019 if(!IsDevice(device
))
1020 alcSetError(device
, ALC_INVALID_DEVICE
);
1022 alcSetError(device
, ALC_INVALID_VALUE
);
1027 SuspendContext(NULL
);
1028 data
[i
++] = ALC_FREQUENCY
;
1029 data
[i
++] = device
->Frequency
;
1031 data
[i
++] = ALC_REFRESH
;
1032 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
1034 data
[i
++] = ALC_SYNC
;
1035 data
[i
++] = ALC_FALSE
;
1037 data
[i
++] = ALC_MONO_SOURCES
;
1038 data
[i
++] = device
->lNumMonoSources
;
1040 data
[i
++] = ALC_STEREO_SOURCES
;
1041 data
[i
++] = device
->lNumStereoSources
;
1043 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1044 data
[i
++] = device
->NumAuxSends
;
1047 ProcessContext(NULL
);
1052 if(!IsDevice(device
))
1053 alcSetError(device
, ALC_INVALID_DEVICE
);
1055 *data
= device
->Frequency
;
1059 if(!IsDevice(device
))
1060 alcSetError(device
, ALC_INVALID_DEVICE
);
1062 *data
= device
->Frequency
/ device
->UpdateSize
;
1066 if(!IsDevice(device
))
1067 alcSetError(device
, ALC_INVALID_DEVICE
);
1072 case ALC_MONO_SOURCES
:
1073 if(!IsDevice(device
))
1074 alcSetError(device
, ALC_INVALID_DEVICE
);
1076 *data
= device
->lNumMonoSources
;
1079 case ALC_STEREO_SOURCES
:
1080 if(!IsDevice(device
))
1081 alcSetError(device
, ALC_INVALID_DEVICE
);
1083 *data
= device
->lNumStereoSources
;
1087 if(!IsDevice(device
))
1088 alcSetError(device
, ALC_INVALID_DEVICE
);
1090 *data
= device
->Connected
;
1094 alcSetError(device
, ALC_INVALID_ENUM
);
1101 alcIsExtensionPresent
1103 Determines if there is support for a particular extension
1105 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1107 ALCboolean bResult
= ALC_FALSE
;
1114 len
= strlen(extName
);
1115 ptr
= alcExtensionList
;
1118 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1119 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1124 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1128 } while(isspace(*ptr
));
1133 alcSetError(device
, ALC_INVALID_VALUE
);
1142 Retrieves the function address for a particular extension function
1144 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1146 ALCvoid
*pFunction
= NULL
;
1151 while(alcFunctions
[i
].funcName
&&
1152 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1154 pFunction
= alcFunctions
[i
].address
;
1157 alcSetError(device
, ALC_INVALID_VALUE
);
1166 Get the value for a particular ALC Enumerated Value
1168 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1173 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1175 val
= enumeration
[i
].value
;
1177 if(!enumeration
[i
].enumName
)
1178 alcSetError(device
, ALC_INVALID_VALUE
);
1187 Create and attach a Context to a particular Device.
1189 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1191 ALuint attrIdx
, reqStereoSources
;
1192 ALCcontext
*ALContext
;
1196 SuspendContext(NULL
);
1198 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1200 alcSetError(device
, ALC_INVALID_DEVICE
);
1201 ProcessContext(NULL
);
1205 // Reset Context Last Error code
1206 device
->LastError
= ALC_NO_ERROR
;
1208 // If a context is already running on the device, stop playback so the
1209 // device attributes can be updated
1210 if(device
->NumContexts
> 0)
1212 ProcessContext(NULL
);
1213 ALCdevice_StopPlayback(device
);
1214 SuspendContext(NULL
);
1217 // Check for attributes
1220 ALCint level
= device
->Bs2bLevel
;
1221 ALCuint freq
= device
->Frequency
;
1222 ALCint numMono
= device
->lNumMonoSources
;
1223 ALCint numStereo
= device
->lNumStereoSources
;
1224 ALCuint numSends
= device
->NumAuxSends
;
1227 while(attrList
[attrIdx
])
1229 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
1230 !ConfigValueExists(NULL
, "frequency"))
1232 freq
= attrList
[attrIdx
+ 1];
1237 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1239 reqStereoSources
= attrList
[attrIdx
+ 1];
1240 if(reqStereoSources
> device
->MaxNoOfSources
)
1241 reqStereoSources
= device
->MaxNoOfSources
;
1243 numStereo
= reqStereoSources
;
1244 numMono
= device
->MaxNoOfSources
- numStereo
;
1247 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
1248 !ConfigValueExists(NULL
, "sends"))
1250 numSends
= attrList
[attrIdx
+ 1];
1251 if(numSends
> MAX_SENDS
)
1252 numSends
= MAX_SENDS
;
1258 device
->Bs2bLevel
= level
;
1259 device
->Frequency
= freq
;
1260 device
->lNumMonoSources
= numMono
;
1261 device
->lNumStereoSources
= numStereo
;
1262 device
->NumAuxSends
= numSends
;
1265 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1267 alcSetError(device
, ALC_INVALID_DEVICE
);
1268 aluHandleDisconnect(device
);
1269 ProcessContext(NULL
);
1273 for(i
= 0;i
< device
->NumContexts
;i
++)
1275 ALCcontext
*context
= device
->Contexts
[i
];
1279 SuspendContext(context
);
1280 for(slot
= context
->AuxiliaryEffectSlot
;slot
!= NULL
;slot
= slot
->next
)
1282 if(!slot
->EffectState
)
1285 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1287 alcSetError(device
, ALC_INVALID_DEVICE
);
1288 aluHandleDisconnect(device
);
1289 ProcessContext(context
);
1290 ProcessContext(NULL
);
1291 ALCdevice_StopPlayback(device
);
1294 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1297 for(source
= context
->Source
;source
!= NULL
;source
= source
->next
)
1299 ALuint s
= device
->NumAuxSends
;
1300 while(s
< MAX_SENDS
)
1302 if(source
->Send
[s
].Slot
)
1303 source
->Send
[s
].Slot
->refcount
--;
1304 source
->Send
[s
].Slot
= NULL
;
1305 source
->Send
[s
].WetFilter
.type
= 0;
1306 source
->Send
[s
].WetFilter
.filter
= 0;
1309 source
->NeedsUpdate
= AL_TRUE
;
1311 aluInitPanning(context
);
1312 ProcessContext(context
);
1315 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1319 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1320 bs2b_clear(device
->Bs2b
);
1322 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1323 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1328 device
->Bs2b
= NULL
;
1331 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1334 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1335 ProcessContext(NULL
);
1338 device
->Contexts
= temp
;
1340 ALContext
= calloc(1, sizeof(ALCcontext
));
1343 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1344 ProcessContext(NULL
);
1348 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1349 ALContext
->Device
= device
;
1351 InitContext(ALContext
);
1352 aluInitPanning(ALContext
);
1354 ALContext
->next
= g_pContextList
;
1355 g_pContextList
= ALContext
;
1358 ProcessContext(NULL
);
1369 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1374 if (IsContext(context
))
1376 ALCdevice
*Device
= context
->Device
;
1378 if(Device
->NumContexts
== 1)
1379 ALCdevice_StopPlayback(Device
);
1381 SuspendContext(NULL
);
1383 for(i
= 0;i
< Device
->NumContexts
-1;i
++)
1385 if(Device
->Contexts
[i
] == context
)
1387 memmove(&Device
->Contexts
[i
], &Device
->Contexts
[i
+1],
1388 (Device
->NumContexts
-i
-1) * sizeof(*Device
->Contexts
));
1392 Device
->NumContexts
--;
1395 SuspendContext(context
);
1397 if(context
->SourceCount
> 0)
1400 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceCount
);
1402 ReleaseALSources(context
);
1404 if(context
->AuxiliaryEffectSlotCount
> 0)
1407 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->AuxiliaryEffectSlotCount
);
1409 ReleaseALAuxiliaryEffectSlots(context
);
1412 list
= &g_pContextList
;
1413 while(*list
!= context
)
1414 list
= &(*list
)->next
;
1416 *list
= (*list
)->next
;
1420 ProcessContext(context
);
1421 ProcessContext(NULL
);
1423 ExitContext(context
);
1425 // Free memory (MUST do this after ProcessContext)
1426 memset(context
, 0, sizeof(ALCcontext
));
1430 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1435 alcGetCurrentContext
1437 Returns the currently active Context
1439 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1441 ALCcontext
*pContext
;
1443 if((pContext
=GetContextSuspended()) != NULL
)
1444 ProcessContext(pContext
);
1452 Returns the currently active thread-local Context
1454 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void)
1456 ALCcontext
*pContext
= NULL
;
1458 SuspendContext(NULL
);
1460 pContext
= tls_get(LocalContext
);
1461 if(pContext
&& !IsContext(pContext
))
1463 tls_set(LocalContext
, NULL
);
1467 ProcessContext(NULL
);
1474 alcGetContextsDevice
1476 Returns the Device that a particular Context is attached to
1478 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1480 ALCdevice
*pDevice
= NULL
;
1482 SuspendContext(NULL
);
1483 if (IsContext(pContext
))
1484 pDevice
= pContext
->Device
;
1486 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1487 ProcessContext(NULL
);
1494 alcMakeContextCurrent
1496 Makes the given Context the active Context
1498 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1500 ALCcontext
*ALContext
;
1501 ALboolean bReturn
= AL_TRUE
;
1503 SuspendContext(NULL
);
1505 // context must be a valid Context or NULL
1506 if(context
== NULL
|| IsContext(context
))
1508 ALContext
= g_pContextList
;
1509 while(ALContext
&& !ALContext
->InUse
)
1510 ALContext
= ALContext
->next
;
1512 if(ALContext
!= NULL
)
1514 SuspendContext(ALContext
);
1515 ALContext
->InUse
=AL_FALSE
;
1516 ProcessContext(ALContext
);
1519 if((ALContext
=context
) != NULL
&& ALContext
->Device
)
1521 SuspendContext(ALContext
);
1522 ALContext
->InUse
=AL_TRUE
;
1523 ProcessContext(ALContext
);
1526 tls_set(LocalContext
, NULL
);
1530 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1534 ProcessContext(NULL
);
1542 Makes the given Context the active Context for the current thread
1544 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
)
1546 ALboolean bReturn
= AL_TRUE
;
1548 SuspendContext(NULL
);
1550 // context must be a valid Context or NULL
1551 if(context
== NULL
|| IsContext(context
))
1552 tls_set(LocalContext
, context
);
1555 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1559 ProcessContext(NULL
);
1565 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1566 void SetDefaultChannelOrder(ALCdevice
*device
)
1568 switch(aluChannelsFromFormat(device
->Format
))
1570 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1572 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1573 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1575 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1576 device
->DevChannels
[1] = FRONT_RIGHT
;
1577 device
->DevChannels
[2] = BACK_LEFT
;
1578 device
->DevChannels
[3] = BACK_RIGHT
; break;
1580 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1581 device
->DevChannels
[1] = FRONT_RIGHT
;
1582 device
->DevChannels
[2] = BACK_LEFT
;
1583 device
->DevChannels
[3] = BACK_RIGHT
;
1584 device
->DevChannels
[4] = FRONT_CENTER
;
1585 device
->DevChannels
[5] = LFE
; break;
1587 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1588 device
->DevChannels
[1] = FRONT_RIGHT
;
1589 device
->DevChannels
[2] = FRONT_CENTER
;
1590 device
->DevChannels
[3] = LFE
;
1591 device
->DevChannels
[4] = BACK_CENTER
;
1592 device
->DevChannels
[5] = SIDE_LEFT
;
1593 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1595 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1596 device
->DevChannels
[1] = FRONT_RIGHT
;
1597 device
->DevChannels
[2] = BACK_LEFT
;
1598 device
->DevChannels
[3] = BACK_RIGHT
;
1599 device
->DevChannels
[4] = FRONT_CENTER
;
1600 device
->DevChannels
[5] = LFE
;
1601 device
->DevChannels
[6] = SIDE_LEFT
;
1602 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1605 // Sets the default order used by WaveFormatEx
1606 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1608 switch(aluChannelsFromFormat(device
->Format
))
1610 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1612 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1613 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1615 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1616 device
->DevChannels
[1] = FRONT_RIGHT
;
1617 device
->DevChannels
[2] = BACK_LEFT
;
1618 device
->DevChannels
[3] = BACK_RIGHT
; break;
1620 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1621 device
->DevChannels
[1] = FRONT_RIGHT
;
1622 device
->DevChannels
[2] = FRONT_CENTER
;
1623 device
->DevChannels
[3] = LFE
;
1624 device
->DevChannels
[4] = BACK_LEFT
;
1625 device
->DevChannels
[5] = BACK_RIGHT
; break;
1627 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1628 device
->DevChannels
[1] = FRONT_RIGHT
;
1629 device
->DevChannels
[2] = FRONT_CENTER
;
1630 device
->DevChannels
[3] = LFE
;
1631 device
->DevChannels
[4] = BACK_CENTER
;
1632 device
->DevChannels
[5] = SIDE_LEFT
;
1633 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1635 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1636 device
->DevChannels
[1] = FRONT_RIGHT
;
1637 device
->DevChannels
[2] = FRONT_CENTER
;
1638 device
->DevChannels
[3] = LFE
;
1639 device
->DevChannels
[4] = BACK_LEFT
;
1640 device
->DevChannels
[5] = BACK_RIGHT
;
1641 device
->DevChannels
[6] = SIDE_LEFT
;
1642 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1646 static ALenum
GetFormatFromString(const char *str
)
1648 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1649 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1650 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1651 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1652 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1653 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1655 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1656 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1657 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1658 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1659 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1660 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1662 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1663 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1664 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1665 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1666 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1667 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1669 AL_PRINT("Unknown format: \"%s\"\n", str
);
1670 return AL_FORMAT_STEREO16
;
1676 Open the Device specified.
1678 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1680 ALboolean bDeviceFound
= AL_FALSE
;
1684 if(deviceName
&& !deviceName
[0])
1689 if(!alcAllDeviceList
)
1690 ProbeAllDeviceList();
1692 device
= malloc(sizeof(ALCdevice
));
1697 //Initialise device structure
1698 memset(device
, 0, sizeof(ALCdevice
));
1701 device
->Connected
= ALC_TRUE
;
1702 device
->IsCaptureDevice
= AL_FALSE
;
1703 device
->LastError
= ALC_NO_ERROR
;
1705 device
->Bs2b
= NULL
;
1706 device
->szDeviceName
= NULL
;
1708 device
->Contexts
= NULL
;
1709 device
->NumContexts
= 0;
1712 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1713 if(device
->Frequency
< 8000)
1714 device
->Frequency
= 8000;
1716 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1717 device
->Format
= GetFormatFromString(fmt
);
1719 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1720 if(device
->NumUpdates
< 2)
1721 device
->NumUpdates
= 4;
1723 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1724 if(i
<= 0) i
= 4096;
1726 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1727 if(device
->UpdateSize
<= 0)
1728 device
->UpdateSize
= i
/device
->NumUpdates
;
1730 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1731 if((ALint
)device
->MaxNoOfSources
<= 0)
1732 device
->MaxNoOfSources
= 256;
1734 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1735 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1736 device
->AuxiliaryEffectSlotMax
= 4;
1738 device
->lNumStereoSources
= 1;
1739 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1741 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1742 if(device
->NumAuxSends
> MAX_SENDS
)
1743 device
->NumAuxSends
= MAX_SENDS
;
1745 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1747 if(aluChannelsFromFormat(device
->Format
) <= 2)
1749 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1750 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1751 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1754 device
->HeadDampen
= 0.0f
;
1756 // Find a playback device to open
1757 SuspendContext(NULL
);
1758 for(i
= 0;BackendList
[i
].Init
;i
++)
1760 device
->Funcs
= &BackendList
[i
].Funcs
;
1761 if(ALCdevice_OpenPlayback(device
, deviceName
))
1763 device
->next
= g_pDeviceList
;
1764 g_pDeviceList
= device
;
1767 bDeviceFound
= AL_TRUE
;
1771 ProcessContext(NULL
);
1775 // No suitable output device found
1776 alcSetError(NULL
, ALC_INVALID_VALUE
);
1782 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1791 Close the specified Device
1793 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1795 ALCboolean bReturn
= ALC_FALSE
;
1798 if(IsDevice(pDevice
) && !pDevice
->IsCaptureDevice
)
1800 SuspendContext(NULL
);
1802 list
= &g_pDeviceList
;
1803 while(*list
!= pDevice
)
1804 list
= &(*list
)->next
;
1806 *list
= (*list
)->next
;
1809 ProcessContext(NULL
);
1811 if(pDevice
->NumContexts
> 0)
1814 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1816 while(pDevice
->NumContexts
> 0)
1817 alcDestroyContext(pDevice
->Contexts
[0]);
1819 ALCdevice_ClosePlayback(pDevice
);
1821 if(pDevice
->BufferCount
> 0)
1824 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1826 ReleaseALBuffers(pDevice
);
1828 if(pDevice
->EffectCount
> 0)
1831 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1833 ReleaseALEffects(pDevice
);
1835 if(pDevice
->FilterCount
> 0)
1838 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1840 ReleaseALFilters(pDevice
);
1842 if(pDevice
->DatabufferCount
> 0)
1845 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1847 ReleaseALDatabuffers(pDevice
);
1850 free(pDevice
->Bs2b
);
1851 pDevice
->Bs2b
= NULL
;
1853 free(pDevice
->szDeviceName
);
1854 pDevice
->szDeviceName
= NULL
;
1856 free(pDevice
->Contexts
);
1857 pDevice
->Contexts
= NULL
;
1859 //Release device structure
1860 memset(pDevice
, 0, sizeof(ALCdevice
));
1866 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
1872 ALCvoid
ReleaseALC(ALCvoid
)
1874 free(alcDeviceList
); alcDeviceList
= NULL
;
1875 alcDeviceListSize
= 0;
1876 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
1877 alcAllDeviceListSize
= 0;
1878 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
1879 alcCaptureDeviceListSize
= 0;
1881 free(alcDefaultDeviceSpecifier
);
1882 alcDefaultDeviceSpecifier
= NULL
;
1883 free(alcDefaultAllDeviceSpecifier
);
1884 alcDefaultAllDeviceSpecifier
= NULL
;
1885 free(alcCaptureDefaultDeviceSpecifier
);
1886 alcCaptureDefaultDeviceSpecifier
= NULL
;
1889 if(g_ulDeviceCount
> 0)
1890 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1893 while(g_pDeviceList
)
1895 if(g_pDeviceList
->IsCaptureDevice
)
1896 alcCaptureCloseDevice(g_pDeviceList
);
1898 alcCloseDevice(g_pDeviceList
);
1902 ///////////////////////////////////////////////////////