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_EXTX_source_distance_model "
216 "AL_LOKI_quadriphonic";
218 // Mixing Priority Level
221 ///////////////////////////////////////////////////////
224 ///////////////////////////////////////////////////////
225 // ALC Related helper functions
227 static void alc_init(void);
228 static void alc_deinit(void);
230 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
234 // Perform actions based on the reason for calling.
235 switch(ul_reason_for_call
)
237 case DLL_PROCESS_ATTACH
:
238 DisableThreadLibraryCalls(hModule
);
242 case DLL_PROCESS_DETACH
:
249 #ifdef HAVE_GCC_DESTRUCTOR
250 static void alc_init(void) __attribute__((constructor
));
251 static void alc_deinit(void) __attribute__((destructor
));
255 static void alc_init(void)
258 const char *devs
, *str
;
260 InitializeCriticalSection(&g_csMutex
);
264 tls_create(&LocalContext
);
266 RTPrioLevel
= GetConfigValueInt(NULL
, "rt-prio", 0);
268 devs
= GetConfigValue(NULL
, "drivers", "");
273 const char *next
= devs
;
279 next
= strchr(devs
, ',');
281 if(!devs
[0] || devs
[0] == ',')
288 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
289 for(n
= i
;BackendList
[n
].Init
;n
++)
291 if(len
== strlen(BackendList
[n
].name
) &&
292 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
294 BackendInfo Bkp
= BackendList
[n
];
297 BackendList
[n
] = BackendList
[n
-1];
300 BackendList
[n
] = Bkp
;
310 BackendList
[i
].name
= NULL
;
311 BackendList
[i
].Init
= NULL
;
312 BackendList
[i
].Deinit
= NULL
;
313 BackendList
[i
].Probe
= NULL
;
317 for(i
= 0;BackendList
[i
].Init
;i
++)
319 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
321 BackendList
[i
].Probe(DEVICE_PROBE
);
322 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
323 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
326 DuplicateStereo
= GetConfigValueBool(NULL
, "stereodup", 0);
328 str
= GetConfigValue(NULL
, "excludefx", "");
335 { "eaxreverb", EAXREVERB
},
336 { "reverb", REVERB
},
342 const char *next
= str
;
346 next
= strchr(str
, ',');
348 if(!str
[0] || next
== str
)
351 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
352 for(n
= 0;EffectList
[n
].name
;n
++)
354 if(len
== strlen(EffectList
[n
].name
) &&
355 strncmp(EffectList
[n
].name
, str
, len
) == 0)
356 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
362 static void alc_deinit(void)
368 for(i
= 0;BackendList
[i
].Deinit
;i
++)
369 BackendList
[i
].Deinit();
371 tls_delete(LocalContext
);
375 DeleteCriticalSection(&g_csMutex
);
379 static void ProbeDeviceList()
383 free(alcDeviceList
); alcDeviceList
= NULL
;
384 alcDeviceListSize
= 0;
386 for(i
= 0;BackendList
[i
].Probe
;i
++)
387 BackendList
[i
].Probe(DEVICE_PROBE
);
390 static void ProbeAllDeviceList()
394 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
395 alcAllDeviceListSize
= 0;
397 for(i
= 0;BackendList
[i
].Probe
;i
++)
398 BackendList
[i
].Probe(ALL_DEVICE_PROBE
);
401 static void ProbeCaptureDeviceList()
405 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
406 alcCaptureDeviceListSize
= 0;
408 for(i
= 0;BackendList
[i
].Probe
;i
++)
409 BackendList
[i
].Probe(CAPTURE_DEVICE_PROBE
);
413 #define DECL_APPEND_LIST_FUNC(type) \
414 void Append##type##List(const ALCchar *name) \
416 ALCuint len = strlen(name); \
422 temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
425 AL_PRINT("Realloc failed to add %s!\n", name); \
428 alc##type##List = temp; \
429 sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
430 alc##type##ListSize += len+1; \
431 alc##type##List[alc##type##ListSize] = 0; \
434 DECL_APPEND_LIST_FUNC(Device
)
435 DECL_APPEND_LIST_FUNC(AllDevice
)
436 DECL_APPEND_LIST_FUNC(CaptureDevice
)
439 void EnableRTPrio(ALint level
)
445 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
447 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
448 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
449 struct sched_param param
;
453 /* Use the minimum real-time priority possible for now (on Linux this
454 * should be 1 for SCHED_RR) */
455 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
456 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
460 param
.sched_priority
= 0;
461 failed
= !!pthread_setschedparam(pthread_self(), SCHED_OTHER
, ¶m
);
464 /* Real-time priority not available */
468 AL_PRINT("Failed to set priority level for thread\n");
475 Check pDevice is a valid Device pointer
477 static ALCboolean
IsDevice(ALCdevice
*pDevice
)
479 ALCdevice
*pTempDevice
;
481 SuspendContext(NULL
);
483 pTempDevice
= g_pDeviceList
;
484 while(pTempDevice
&& pTempDevice
!= pDevice
)
485 pTempDevice
= pTempDevice
->next
;
487 ProcessContext(NULL
);
489 return (pTempDevice
? ALC_TRUE
: ALC_FALSE
);
495 Check pContext is a valid Context pointer
497 static ALCboolean
IsContext(ALCcontext
*pContext
)
499 ALCcontext
*pTempContext
;
501 SuspendContext(NULL
);
503 pTempContext
= g_pContextList
;
504 while (pTempContext
&& pTempContext
!= pContext
)
505 pTempContext
= pTempContext
->next
;
507 ProcessContext(NULL
);
509 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
516 Store latest ALC Error
518 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
)
521 device
->LastError
= errorCode
;
523 g_eLastContextError
= errorCode
;
532 ALCvoid
SuspendContext(ALCcontext
*pContext
)
535 EnterCriticalSection(&g_csMutex
);
544 ALCvoid
ProcessContext(ALCcontext
*pContext
)
547 LeaveCriticalSection(&g_csMutex
);
554 Returns the currently active Context, in a locked state
556 ALCcontext
*GetContextSuspended(void)
558 ALCcontext
*pContext
= NULL
;
560 SuspendContext(NULL
);
562 pContext
= tls_get(LocalContext
);
563 if(pContext
&& !IsContext(pContext
))
565 tls_set(LocalContext
, NULL
);
570 pContext
= g_pContextList
;
571 while(pContext
&& !pContext
->InUse
)
572 pContext
= pContext
->next
;
575 SuspendContext(pContext
);
577 ProcessContext(NULL
);
586 Initialize Context variables
588 static ALvoid
InitContext(ALCcontext
*pContext
)
590 //Initialise listener
591 pContext
->Listener
.Gain
= 1.0f
;
592 pContext
->Listener
.MetersPerUnit
= 1.0f
;
593 pContext
->Listener
.Position
[0] = 0.0f
;
594 pContext
->Listener
.Position
[1] = 0.0f
;
595 pContext
->Listener
.Position
[2] = 0.0f
;
596 pContext
->Listener
.Velocity
[0] = 0.0f
;
597 pContext
->Listener
.Velocity
[1] = 0.0f
;
598 pContext
->Listener
.Velocity
[2] = 0.0f
;
599 pContext
->Listener
.Forward
[0] = 0.0f
;
600 pContext
->Listener
.Forward
[1] = 0.0f
;
601 pContext
->Listener
.Forward
[2] = -1.0f
;
602 pContext
->Listener
.Up
[0] = 0.0f
;
603 pContext
->Listener
.Up
[1] = 1.0f
;
604 pContext
->Listener
.Up
[2] = 0.0f
;
607 pContext
->LastError
= AL_NO_ERROR
;
608 pContext
->InUse
= AL_FALSE
;
609 pContext
->Suspended
= AL_FALSE
;
612 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
613 pContext
->SourceDistanceModel
= AL_FALSE
;
614 pContext
->DopplerFactor
= 1.0f
;
615 pContext
->DopplerVelocity
= 1.0f
;
616 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
618 pContext
->ExtensionList
= alExtList
;
625 Clean up Context, destroy any remaining Sources
627 static ALCvoid
ExitContext(ALCcontext
*pContext
)
630 pContext
->LastError
= AL_NO_ERROR
;
631 pContext
->InUse
= AL_FALSE
;
634 ///////////////////////////////////////////////////////
637 ///////////////////////////////////////////////////////
638 // ALC Functions calls
641 // This should probably move to another c file but for now ...
642 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
644 ALCboolean DeviceFound
= ALC_FALSE
;
645 ALCdevice
*pDevice
= NULL
;
650 alcSetError(NULL
, ALC_INVALID_VALUE
);
654 if(deviceName
&& !deviceName
[0])
657 pDevice
= malloc(sizeof(ALCdevice
));
660 //Initialise device structure
661 memset(pDevice
, 0, sizeof(ALCdevice
));
664 pDevice
->Connected
= ALC_TRUE
;
665 pDevice
->IsCaptureDevice
= AL_TRUE
;
667 pDevice
->szDeviceName
= NULL
;
669 pDevice
->Frequency
= frequency
;
670 pDevice
->Format
= format
;
671 pDevice
->UpdateSize
= SampleSize
;
672 pDevice
->NumUpdates
= 1;
674 SuspendContext(NULL
);
675 for(i
= 0;BackendList
[i
].Init
;i
++)
677 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
678 if(ALCdevice_OpenCapture(pDevice
, deviceName
))
680 pDevice
->next
= g_pDeviceList
;
681 g_pDeviceList
= pDevice
;
684 DeviceFound
= ALC_TRUE
;
688 ProcessContext(NULL
);
692 alcSetError(NULL
, ALC_INVALID_VALUE
);
698 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
703 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
705 ALCboolean bReturn
= ALC_FALSE
;
708 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
710 SuspendContext(NULL
);
712 list
= &g_pDeviceList
;
713 while(*list
!= pDevice
)
714 list
= &(*list
)->next
;
716 *list
= (*list
)->next
;
719 ProcessContext(NULL
);
721 ALCdevice_CloseCapture(pDevice
);
723 free(pDevice
->szDeviceName
);
724 pDevice
->szDeviceName
= NULL
;
731 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
736 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
738 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
739 ALCdevice_StartCapture(pDevice
);
741 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
744 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
746 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
747 ALCdevice_StopCapture(pDevice
);
749 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
752 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
754 if(IsDevice(pDevice
) && pDevice
->IsCaptureDevice
)
755 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
757 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
763 Return last ALC generated error code
765 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
767 ALCenum errorCode
= ALC_NO_ERROR
;
771 errorCode
= device
->LastError
;
772 device
->LastError
= ALC_NO_ERROR
;
776 errorCode
= g_eLastContextError
;
777 g_eLastContextError
= ALC_NO_ERROR
;
788 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
790 SuspendContext(NULL
);
791 if(IsContext(pContext
))
792 pContext
->Suspended
= AL_TRUE
;
793 ProcessContext(NULL
);
802 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
804 SuspendContext(NULL
);
805 if(IsContext(pContext
))
806 pContext
->Suspended
= AL_FALSE
;
807 ProcessContext(NULL
);
814 Returns information about the Device, and error strings
816 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
818 const ALCchar
*value
= NULL
;
826 case ALC_INVALID_ENUM
:
827 value
= alcErrInvalidEnum
;
830 case ALC_INVALID_VALUE
:
831 value
= alcErrInvalidValue
;
834 case ALC_INVALID_DEVICE
:
835 value
= alcErrInvalidDevice
;
838 case ALC_INVALID_CONTEXT
:
839 value
= alcErrInvalidContext
;
842 case ALC_OUT_OF_MEMORY
:
843 value
= alcErrOutOfMemory
;
846 case ALC_DEVICE_SPECIFIER
:
847 if(IsDevice(pDevice
))
848 value
= pDevice
->szDeviceName
;
852 value
= alcDeviceList
;
856 case ALC_ALL_DEVICES_SPECIFIER
:
857 ProbeAllDeviceList();
858 value
= alcAllDeviceList
;
861 case ALC_CAPTURE_DEVICE_SPECIFIER
:
862 if(IsDevice(pDevice
))
863 value
= pDevice
->szDeviceName
;
866 ProbeCaptureDeviceList();
867 value
= alcCaptureDeviceList
;
871 /* Default devices are always first in the list */
872 case ALC_DEFAULT_DEVICE_SPECIFIER
:
873 free(alcDefaultDeviceSpecifier
);
874 alcDefaultDeviceSpecifier
= strdup(alcDeviceList
? alcDeviceList
: "");
875 if(!alcDefaultDeviceSpecifier
)
876 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
877 value
= alcDefaultDeviceSpecifier
;
880 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
881 free(alcDefaultAllDeviceSpecifier
);
882 alcDefaultAllDeviceSpecifier
= strdup(alcAllDeviceList
?
883 alcAllDeviceList
: "");
884 if(!alcDefaultAllDeviceSpecifier
)
885 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
886 value
= alcDefaultAllDeviceSpecifier
;
889 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
890 free(alcCaptureDefaultDeviceSpecifier
);
891 alcCaptureDefaultDeviceSpecifier
= strdup(alcCaptureDeviceList
?
892 alcCaptureDeviceList
: "");
893 if(!alcCaptureDefaultDeviceSpecifier
)
894 alcSetError(pDevice
, ALC_OUT_OF_MEMORY
);
895 value
= alcCaptureDefaultDeviceSpecifier
;
899 value
= alcExtensionList
;
903 alcSetError(pDevice
, ALC_INVALID_ENUM
);
914 Returns information about the Device and the version of Open AL
916 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
918 if(size
== 0 || data
== NULL
)
920 alcSetError(device
, ALC_INVALID_VALUE
);
924 if(IsDevice(device
) && device
->IsCaptureDevice
)
926 SuspendContext(NULL
);
931 case ALC_CAPTURE_SAMPLES
:
932 *data
= ALCdevice_AvailableSamples(device
);
936 *data
= device
->Connected
;
940 alcSetError(device
, ALC_INVALID_ENUM
);
944 ProcessContext(NULL
);
951 case ALC_MAJOR_VERSION
:
952 *data
= alcMajorVersion
;
955 case ALC_MINOR_VERSION
:
956 *data
= alcMinorVersion
;
959 case ALC_EFX_MAJOR_VERSION
:
960 *data
= alcEFXMajorVersion
;
963 case ALC_EFX_MINOR_VERSION
:
964 *data
= alcEFXMinorVersion
;
967 case ALC_MAX_AUXILIARY_SENDS
:
968 if(!IsDevice(device
))
969 alcSetError(device
, ALC_INVALID_DEVICE
);
971 *data
= device
->NumAuxSends
;
974 case ALC_ATTRIBUTES_SIZE
:
975 if(!IsDevice(device
))
976 alcSetError(device
, ALC_INVALID_DEVICE
);
981 case ALC_ALL_ATTRIBUTES
:
982 if(!IsDevice(device
))
983 alcSetError(device
, ALC_INVALID_DEVICE
);
985 alcSetError(device
, ALC_INVALID_VALUE
);
990 SuspendContext(NULL
);
991 data
[i
++] = ALC_FREQUENCY
;
992 data
[i
++] = device
->Frequency
;
994 data
[i
++] = ALC_REFRESH
;
995 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
997 data
[i
++] = ALC_SYNC
;
998 data
[i
++] = ALC_FALSE
;
1000 data
[i
++] = ALC_MONO_SOURCES
;
1001 data
[i
++] = device
->lNumMonoSources
;
1003 data
[i
++] = ALC_STEREO_SOURCES
;
1004 data
[i
++] = device
->lNumStereoSources
;
1006 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
1007 data
[i
++] = device
->NumAuxSends
;
1010 ProcessContext(NULL
);
1015 if(!IsDevice(device
))
1016 alcSetError(device
, ALC_INVALID_DEVICE
);
1018 *data
= device
->Frequency
;
1022 if(!IsDevice(device
))
1023 alcSetError(device
, ALC_INVALID_DEVICE
);
1025 *data
= device
->Frequency
/ device
->UpdateSize
;
1029 if(!IsDevice(device
))
1030 alcSetError(device
, ALC_INVALID_DEVICE
);
1035 case ALC_MONO_SOURCES
:
1036 if(!IsDevice(device
))
1037 alcSetError(device
, ALC_INVALID_DEVICE
);
1039 *data
= device
->lNumMonoSources
;
1042 case ALC_STEREO_SOURCES
:
1043 if(!IsDevice(device
))
1044 alcSetError(device
, ALC_INVALID_DEVICE
);
1046 *data
= device
->lNumStereoSources
;
1050 if(!IsDevice(device
))
1051 alcSetError(device
, ALC_INVALID_DEVICE
);
1053 *data
= device
->Connected
;
1057 alcSetError(device
, ALC_INVALID_ENUM
);
1064 alcIsExtensionPresent
1066 Determines if there is support for a particular extension
1068 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
1070 ALCboolean bResult
= ALC_FALSE
;
1077 len
= strlen(extName
);
1078 ptr
= alcExtensionList
;
1081 if(strncasecmp(ptr
, extName
, len
) == 0 &&
1082 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
1087 if((ptr
=strchr(ptr
, ' ')) != NULL
)
1091 } while(isspace(*ptr
));
1096 alcSetError(device
, ALC_INVALID_VALUE
);
1105 Retrieves the function address for a particular extension function
1107 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
1109 ALCvoid
*pFunction
= NULL
;
1114 while(alcFunctions
[i
].funcName
&&
1115 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
1117 pFunction
= alcFunctions
[i
].address
;
1120 alcSetError(device
, ALC_INVALID_VALUE
);
1129 Get the value for a particular ALC Enumerated Value
1131 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1136 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1138 val
= enumeration
[i
].value
;
1140 if(!enumeration
[i
].enumName
)
1141 alcSetError(device
, ALC_INVALID_VALUE
);
1150 Create and attach a Context to a particular Device.
1152 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1154 ALuint attrIdx
, reqStereoSources
;
1155 ALCcontext
*ALContext
;
1159 SuspendContext(NULL
);
1161 if(!IsDevice(device
) || device
->IsCaptureDevice
|| !device
->Connected
)
1163 alcSetError(device
, ALC_INVALID_DEVICE
);
1164 ProcessContext(NULL
);
1168 // Reset Context Last Error code
1169 device
->LastError
= ALC_NO_ERROR
;
1171 // If a context is already running on the device, stop playback so the
1172 // device attributes can be updated
1173 if(device
->NumContexts
> 0)
1175 ProcessContext(NULL
);
1176 ALCdevice_StopPlayback(device
);
1177 SuspendContext(NULL
);
1180 // Check for attributes
1183 ALCint level
= device
->Bs2bLevel
;
1184 ALCuint freq
= device
->Frequency
;
1185 ALCint numMono
= device
->lNumMonoSources
;
1186 ALCint numStereo
= device
->lNumStereoSources
;
1187 ALCuint numSends
= device
->NumAuxSends
;
1190 while(attrList
[attrIdx
])
1192 if(attrList
[attrIdx
] == ALC_FREQUENCY
&&
1193 !ConfigValueExists(NULL
, "frequency"))
1195 freq
= attrList
[attrIdx
+ 1];
1200 if(attrList
[attrIdx
] == ALC_STEREO_SOURCES
)
1202 reqStereoSources
= attrList
[attrIdx
+ 1];
1203 if(reqStereoSources
> device
->MaxNoOfSources
)
1204 reqStereoSources
= device
->MaxNoOfSources
;
1206 numStereo
= reqStereoSources
;
1207 numMono
= device
->MaxNoOfSources
- numStereo
;
1210 if(attrList
[attrIdx
] == ALC_MAX_AUXILIARY_SENDS
&&
1211 !ConfigValueExists(NULL
, "sends"))
1213 numSends
= attrList
[attrIdx
+ 1];
1214 if(numSends
> MAX_SENDS
)
1215 numSends
= MAX_SENDS
;
1221 device
->Bs2bLevel
= level
;
1222 device
->Frequency
= freq
;
1223 device
->lNumMonoSources
= numMono
;
1224 device
->lNumStereoSources
= numStereo
;
1225 device
->NumAuxSends
= numSends
;
1228 if(ALCdevice_ResetPlayback(device
) == ALC_FALSE
)
1230 alcSetError(device
, ALC_INVALID_DEVICE
);
1231 aluHandleDisconnect(device
);
1232 ProcessContext(NULL
);
1236 for(i
= 0;i
< device
->NumContexts
;i
++)
1238 ALCcontext
*context
= device
->Contexts
[i
];
1242 SuspendContext(context
);
1243 for(slot
= context
->AuxiliaryEffectSlot
;slot
!= NULL
;slot
= slot
->next
)
1245 if(!slot
->EffectState
)
1248 if(ALEffect_DeviceUpdate(slot
->EffectState
, device
) == AL_FALSE
)
1250 alcSetError(device
, ALC_INVALID_DEVICE
);
1251 aluHandleDisconnect(device
);
1252 ProcessContext(context
);
1253 ProcessContext(NULL
);
1254 ALCdevice_StopPlayback(device
);
1257 ALEffect_Update(slot
->EffectState
, context
, &slot
->effect
);
1260 for(source
= context
->Source
;source
!= NULL
;source
= source
->next
)
1262 ALuint s
= device
->NumAuxSends
;
1263 while(s
< MAX_SENDS
)
1265 if(source
->Send
[s
].Slot
)
1266 source
->Send
[s
].Slot
->refcount
--;
1267 source
->Send
[s
].Slot
= NULL
;
1268 source
->Send
[s
].WetFilter
.type
= 0;
1269 source
->Send
[s
].WetFilter
.filter
= 0;
1272 source
->NeedsUpdate
= AL_TRUE
;
1274 aluInitPanning(context
);
1275 ProcessContext(context
);
1278 if(device
->Bs2bLevel
> 0 && device
->Bs2bLevel
<= 6)
1282 device
->Bs2b
= calloc(1, sizeof(*device
->Bs2b
));
1283 bs2b_clear(device
->Bs2b
);
1285 bs2b_set_srate(device
->Bs2b
, device
->Frequency
);
1286 bs2b_set_level(device
->Bs2b
, device
->Bs2bLevel
);
1291 device
->Bs2b
= NULL
;
1294 temp
= realloc(device
->Contexts
, (device
->NumContexts
+1) * sizeof(*device
->Contexts
));
1297 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1298 ProcessContext(NULL
);
1301 device
->Contexts
= temp
;
1303 ALContext
= calloc(1, sizeof(ALCcontext
));
1306 alcSetError(device
, ALC_OUT_OF_MEMORY
);
1307 ProcessContext(NULL
);
1311 device
->Contexts
[device
->NumContexts
++] = ALContext
;
1312 ALContext
->Device
= device
;
1314 InitContext(ALContext
);
1315 aluInitPanning(ALContext
);
1317 ALContext
->next
= g_pContextList
;
1318 g_pContextList
= ALContext
;
1321 ProcessContext(NULL
);
1332 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1337 if (IsContext(context
))
1339 ALCdevice
*Device
= context
->Device
;
1341 if(Device
->NumContexts
== 1)
1342 ALCdevice_StopPlayback(Device
);
1344 SuspendContext(NULL
);
1346 for(i
= 0;i
< Device
->NumContexts
-1;i
++)
1348 if(Device
->Contexts
[i
] == context
)
1350 memmove(&Device
->Contexts
[i
], &Device
->Contexts
[i
+1],
1351 (Device
->NumContexts
-i
-1) * sizeof(*Device
->Contexts
));
1355 Device
->NumContexts
--;
1358 SuspendContext(context
);
1360 if(context
->SourceCount
> 0)
1363 AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context
->SourceCount
);
1365 ReleaseALSources(context
);
1367 if(context
->AuxiliaryEffectSlotCount
> 0)
1370 AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context
->AuxiliaryEffectSlotCount
);
1372 ReleaseALAuxiliaryEffectSlots(context
);
1375 list
= &g_pContextList
;
1376 while(*list
!= context
)
1377 list
= &(*list
)->next
;
1379 *list
= (*list
)->next
;
1383 ProcessContext(context
);
1384 ProcessContext(NULL
);
1386 ExitContext(context
);
1388 // Free memory (MUST do this after ProcessContext)
1389 memset(context
, 0, sizeof(ALCcontext
));
1393 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1398 alcGetCurrentContext
1400 Returns the currently active Context
1402 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1404 ALCcontext
*pContext
;
1406 if((pContext
=GetContextSuspended()) != NULL
)
1407 ProcessContext(pContext
);
1415 Returns the currently active thread-local Context
1417 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void)
1419 ALCcontext
*pContext
= NULL
;
1421 SuspendContext(NULL
);
1423 pContext
= tls_get(LocalContext
);
1424 if(pContext
&& !IsContext(pContext
))
1426 tls_set(LocalContext
, NULL
);
1430 ProcessContext(NULL
);
1437 alcGetContextsDevice
1439 Returns the Device that a particular Context is attached to
1441 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1443 ALCdevice
*pDevice
= NULL
;
1445 SuspendContext(NULL
);
1446 if (IsContext(pContext
))
1447 pDevice
= pContext
->Device
;
1449 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1450 ProcessContext(NULL
);
1457 alcMakeContextCurrent
1459 Makes the given Context the active Context
1461 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1463 ALCcontext
*ALContext
;
1464 ALboolean bReturn
= AL_TRUE
;
1466 SuspendContext(NULL
);
1468 // context must be a valid Context or NULL
1469 if(context
== NULL
|| IsContext(context
))
1471 if((ALContext
=GetContextSuspended()) != NULL
)
1473 ALContext
->InUse
=AL_FALSE
;
1474 ProcessContext(ALContext
);
1477 if((ALContext
=context
) != NULL
&& ALContext
->Device
)
1479 SuspendContext(ALContext
);
1480 ALContext
->InUse
=AL_TRUE
;
1481 ProcessContext(ALContext
);
1484 tls_set(LocalContext
, NULL
);
1488 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1492 ProcessContext(NULL
);
1500 Makes the given Context the active Context for the current thread
1502 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
)
1504 ALboolean bReturn
= AL_TRUE
;
1506 SuspendContext(NULL
);
1508 // context must be a valid Context or NULL
1509 if(context
== NULL
|| IsContext(context
))
1510 tls_set(LocalContext
, context
);
1513 alcSetError(NULL
, ALC_INVALID_CONTEXT
);
1517 ProcessContext(NULL
);
1523 // Sets the default channel order used by most non-WaveFormatEx-based APIs
1524 void SetDefaultChannelOrder(ALCdevice
*device
)
1526 switch(aluChannelsFromFormat(device
->Format
))
1528 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1530 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1531 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1533 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1534 device
->DevChannels
[1] = FRONT_RIGHT
;
1535 device
->DevChannels
[2] = BACK_LEFT
;
1536 device
->DevChannels
[3] = BACK_RIGHT
; break;
1538 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1539 device
->DevChannels
[1] = FRONT_RIGHT
;
1540 device
->DevChannels
[2] = BACK_LEFT
;
1541 device
->DevChannels
[3] = BACK_RIGHT
;
1542 device
->DevChannels
[4] = FRONT_CENTER
;
1543 device
->DevChannels
[5] = LFE
; break;
1545 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1546 device
->DevChannels
[1] = FRONT_RIGHT
;
1547 device
->DevChannels
[2] = FRONT_CENTER
;
1548 device
->DevChannels
[3] = LFE
;
1549 device
->DevChannels
[4] = BACK_CENTER
;
1550 device
->DevChannels
[5] = SIDE_LEFT
;
1551 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1553 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1554 device
->DevChannels
[1] = FRONT_RIGHT
;
1555 device
->DevChannels
[2] = BACK_LEFT
;
1556 device
->DevChannels
[3] = BACK_RIGHT
;
1557 device
->DevChannels
[4] = FRONT_CENTER
;
1558 device
->DevChannels
[5] = LFE
;
1559 device
->DevChannels
[6] = SIDE_LEFT
;
1560 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1563 // Sets the default order used by WaveFormatEx
1564 void SetDefaultWFXChannelOrder(ALCdevice
*device
)
1566 switch(aluChannelsFromFormat(device
->Format
))
1568 case 1: device
->DevChannels
[0] = FRONT_CENTER
; break;
1570 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
1571 device
->DevChannels
[1] = FRONT_RIGHT
; break;
1573 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
1574 device
->DevChannels
[1] = FRONT_RIGHT
;
1575 device
->DevChannels
[2] = BACK_LEFT
;
1576 device
->DevChannels
[3] = BACK_RIGHT
; break;
1578 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
1579 device
->DevChannels
[1] = FRONT_RIGHT
;
1580 device
->DevChannels
[2] = FRONT_CENTER
;
1581 device
->DevChannels
[3] = LFE
;
1582 device
->DevChannels
[4] = BACK_LEFT
;
1583 device
->DevChannels
[5] = BACK_RIGHT
; break;
1585 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
1586 device
->DevChannels
[1] = FRONT_RIGHT
;
1587 device
->DevChannels
[2] = FRONT_CENTER
;
1588 device
->DevChannels
[3] = LFE
;
1589 device
->DevChannels
[4] = BACK_CENTER
;
1590 device
->DevChannels
[5] = SIDE_LEFT
;
1591 device
->DevChannels
[6] = SIDE_RIGHT
; break;
1593 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
1594 device
->DevChannels
[1] = FRONT_RIGHT
;
1595 device
->DevChannels
[2] = FRONT_CENTER
;
1596 device
->DevChannels
[3] = LFE
;
1597 device
->DevChannels
[4] = BACK_LEFT
;
1598 device
->DevChannels
[5] = BACK_RIGHT
;
1599 device
->DevChannels
[6] = SIDE_LEFT
;
1600 device
->DevChannels
[7] = SIDE_RIGHT
; break;
1604 static ALenum
GetFormatFromString(const char *str
)
1606 if(strcasecmp(str
, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32
;
1607 if(strcasecmp(str
, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32
;
1608 if(strcasecmp(str
, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32
;
1609 if(strcasecmp(str
, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32
;
1610 if(strcasecmp(str
, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32
;
1611 if(strcasecmp(str
, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32
;
1613 if(strcasecmp(str
, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16
;
1614 if(strcasecmp(str
, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16
;
1615 if(strcasecmp(str
, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16
;
1616 if(strcasecmp(str
, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16
;
1617 if(strcasecmp(str
, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16
;
1618 if(strcasecmp(str
, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16
;
1620 if(strcasecmp(str
, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8
;
1621 if(strcasecmp(str
, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8
;
1622 if(strcasecmp(str
, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8
;
1623 if(strcasecmp(str
, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8
;
1624 if(strcasecmp(str
, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8
;
1625 if(strcasecmp(str
, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8
;
1627 AL_PRINT("Unknown format: \"%s\"\n", str
);
1628 return AL_FORMAT_STEREO16
;
1634 Open the Device specified.
1636 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1638 ALboolean bDeviceFound
= AL_FALSE
;
1642 if(deviceName
&& !deviceName
[0])
1645 device
= malloc(sizeof(ALCdevice
));
1650 //Initialise device structure
1651 memset(device
, 0, sizeof(ALCdevice
));
1654 device
->Connected
= ALC_TRUE
;
1655 device
->IsCaptureDevice
= AL_FALSE
;
1656 device
->LastError
= ALC_NO_ERROR
;
1658 device
->Bs2b
= NULL
;
1659 device
->szDeviceName
= NULL
;
1661 device
->Contexts
= NULL
;
1662 device
->NumContexts
= 0;
1665 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1666 if(device
->Frequency
< 8000)
1667 device
->Frequency
= 8000;
1669 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1670 device
->Format
= GetFormatFromString(fmt
);
1672 device
->NumUpdates
= GetConfigValueInt(NULL
, "periods", 4);
1673 if(device
->NumUpdates
< 2)
1674 device
->NumUpdates
= 4;
1676 i
= GetConfigValueInt(NULL
, "refresh", 4096);
1677 if(i
<= 0) i
= 4096;
1679 device
->UpdateSize
= GetConfigValueInt(NULL
, "period_size", i
/device
->NumUpdates
);
1680 if(device
->UpdateSize
<= 0)
1681 device
->UpdateSize
= i
/device
->NumUpdates
;
1683 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1684 if((ALint
)device
->MaxNoOfSources
<= 0)
1685 device
->MaxNoOfSources
= 256;
1687 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1688 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1689 device
->AuxiliaryEffectSlotMax
= 4;
1691 device
->lNumStereoSources
= 1;
1692 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1694 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1695 if(device
->NumAuxSends
> MAX_SENDS
)
1696 device
->NumAuxSends
= MAX_SENDS
;
1698 device
->Bs2bLevel
= GetConfigValueInt(NULL
, "cf_level", 0);
1700 if(aluChannelsFromFormat(device
->Format
) <= 2)
1702 device
->HeadDampen
= GetConfigValueFloat(NULL
, "head_dampen", DEFAULT_HEAD_DAMPEN
);
1703 device
->HeadDampen
= __min(device
->HeadDampen
, 1.0f
);
1704 device
->HeadDampen
= __max(device
->HeadDampen
, 0.0f
);
1707 device
->HeadDampen
= 0.0f
;
1709 // Find a playback device to open
1710 SuspendContext(NULL
);
1711 for(i
= 0;BackendList
[i
].Init
;i
++)
1713 device
->Funcs
= &BackendList
[i
].Funcs
;
1714 if(ALCdevice_OpenPlayback(device
, deviceName
))
1716 device
->next
= g_pDeviceList
;
1717 g_pDeviceList
= device
;
1720 bDeviceFound
= AL_TRUE
;
1724 ProcessContext(NULL
);
1728 // No suitable output device found
1729 alcSetError(NULL
, ALC_INVALID_VALUE
);
1735 alcSetError(NULL
, ALC_OUT_OF_MEMORY
);
1744 Close the specified Device
1746 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1748 ALCboolean bReturn
= ALC_FALSE
;
1751 if(IsDevice(pDevice
) && !pDevice
->IsCaptureDevice
)
1753 SuspendContext(NULL
);
1755 list
= &g_pDeviceList
;
1756 while(*list
!= pDevice
)
1757 list
= &(*list
)->next
;
1759 *list
= (*list
)->next
;
1762 ProcessContext(NULL
);
1764 if(pDevice
->NumContexts
> 0)
1767 AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice
->NumContexts
);
1769 while(pDevice
->NumContexts
> 0)
1770 alcDestroyContext(pDevice
->Contexts
[0]);
1772 ALCdevice_ClosePlayback(pDevice
);
1774 if(pDevice
->BufferCount
> 0)
1777 AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice
->BufferCount
);
1779 ReleaseALBuffers(pDevice
);
1781 if(pDevice
->EffectCount
> 0)
1784 AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice
->EffectCount
);
1786 ReleaseALEffects(pDevice
);
1788 if(pDevice
->FilterCount
> 0)
1791 AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice
->FilterCount
);
1793 ReleaseALFilters(pDevice
);
1795 if(pDevice
->DatabufferCount
> 0)
1798 AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice
->DatabufferCount
);
1800 ReleaseALDatabuffers(pDevice
);
1803 free(pDevice
->Bs2b
);
1804 pDevice
->Bs2b
= NULL
;
1806 free(pDevice
->szDeviceName
);
1807 pDevice
->szDeviceName
= NULL
;
1809 free(pDevice
->Contexts
);
1810 pDevice
->Contexts
= NULL
;
1812 //Release device structure
1813 memset(pDevice
, 0, sizeof(ALCdevice
));
1819 alcSetError(pDevice
, ALC_INVALID_DEVICE
);
1825 ALCvoid
ReleaseALC(ALCvoid
)
1827 free(alcDeviceList
); alcDeviceList
= NULL
;
1828 alcDeviceListSize
= 0;
1829 free(alcAllDeviceList
); alcAllDeviceList
= NULL
;
1830 alcAllDeviceListSize
= 0;
1831 free(alcCaptureDeviceList
); alcCaptureDeviceList
= NULL
;
1832 alcCaptureDeviceListSize
= 0;
1834 free(alcDefaultDeviceSpecifier
);
1835 alcDefaultDeviceSpecifier
= NULL
;
1836 free(alcDefaultAllDeviceSpecifier
);
1837 alcDefaultAllDeviceSpecifier
= NULL
;
1838 free(alcCaptureDefaultDeviceSpecifier
);
1839 alcCaptureDefaultDeviceSpecifier
= NULL
;
1842 if(g_ulDeviceCount
> 0)
1843 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1846 while(g_pDeviceList
)
1848 if(g_pDeviceList
->IsCaptureDevice
)
1849 alcCaptureCloseDevice(g_pDeviceList
);
1851 alcCloseDevice(g_pDeviceList
);
1855 ///////////////////////////////////////////////////////