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"
41 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
44 void (*Init
)(BackendFuncs
*);
48 { "alsa", alc_alsa_init
, EmptyFuncs
},
51 { "oss", alc_oss_init
, EmptyFuncs
},
54 { "solaris", alc_solaris_init
, EmptyFuncs
},
57 { "dsound", alcDSoundInit
, EmptyFuncs
},
60 { "winmm", alcWinMMInit
, EmptyFuncs
},
63 { "port", alc_pa_init
, EmptyFuncs
},
65 #ifdef HAVE_PULSEAUDIO
66 { "pulse", alc_pulse_init
, EmptyFuncs
},
69 { "wave", alc_wave_init
, EmptyFuncs
},
71 { NULL
, NULL
, EmptyFuncs
}
75 ///////////////////////////////////////////////////////
77 #define ALC_EFX_MAJOR_VERSION 0x20001
78 #define ALC_EFX_MINOR_VERSION 0x20002
79 #define ALC_MAX_AUXILIARY_SENDS 0x20003
81 ///////////////////////////////////////////////////////
82 // STRING and EXTENSIONS
84 typedef struct ALCfunction_struct
90 static ALCfunction alcFunctions
[] = {
91 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
92 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
93 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
94 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
95 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
96 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
97 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
98 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
99 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
100 { "alcGetError", (ALvoid
*) alcGetError
},
101 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
102 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
103 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
104 { "alcGetString", (ALvoid
*) alcGetString
},
105 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
106 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
107 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
108 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
109 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
110 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
111 { NULL
, (ALvoid
*) NULL
}
114 static ALenums enumeration
[]={
116 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
117 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
118 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
121 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
122 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
123 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
124 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
125 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
126 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
127 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
128 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
129 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
130 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
131 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
132 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
133 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
134 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
135 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
136 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
137 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
140 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
141 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
142 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
145 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
146 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
147 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
148 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
149 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
150 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
151 { (ALchar
*)NULL
, (ALenum
)0 }
154 static const ALCchar alcNoError
[] = "No Error";
155 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
156 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
157 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
158 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
159 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
162 static ALCchar alcDeviceList
[2048];
163 static ALCchar alcAllDeviceList
[2048];
164 static ALCchar alcCaptureDeviceList
[2048];
165 // Default is always the first in the list
166 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
167 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
168 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
171 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
172 static ALCint alcMajorVersion
= 1;
173 static ALCint alcMinorVersion
= 1;
175 static ALCint alcEFXMajorVersion
= 1;
176 static ALCint alcEFXMinorVersion
= 0;
178 ///////////////////////////////////////////////////////
181 ///////////////////////////////////////////////////////
184 static ALCdevice
*g_pDeviceList
= NULL
;
185 static ALCuint g_ulDeviceCount
= 0;
187 static CRITICAL_SECTION g_csMutex
;
190 static ALCcontext
*g_pContextList
= NULL
;
191 static ALCuint g_ulContextCount
= 0;
194 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
196 static ALboolean init_done
= AL_FALSE
;
198 ///////////////////////////////////////////////////////
201 ///////////////////////////////////////////////////////
202 // ALC Related helper functions
204 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
208 // Perform actions based on the reason for calling.
209 switch(ul_reason_for_call
)
211 case DLL_PROCESS_ATTACH
:
212 DisableThreadLibraryCalls(hModule
);
215 case DLL_PROCESS_DETACH
:
224 DeleteCriticalSection(&g_csMutex
);
230 #ifdef HAVE_GCC_DESTRUCTOR
231 static void my_deinit() __attribute__((destructor
));
232 static void my_deinit()
234 static ALenum once
= AL_FALSE
;
235 if(once
|| !init_done
) return;
244 DeleteCriticalSection(&g_csMutex
);
249 static void InitAL(void)
254 const char *devs
, *str
;
258 InitializeCriticalSection(&g_csMutex
);
262 devs
= GetConfigValue(NULL
, "drivers", "");
267 const char *next
= devs
;
273 next
= strchr(devs
, ',');
275 if(!devs
[0] || devs
[0] == ',')
278 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
279 for(n
= i
;BackendList
[n
].Init
;n
++)
281 if(len
== strlen(BackendList
[n
].name
) &&
282 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
284 const char *name
= BackendList
[i
].name
;
285 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
287 BackendList
[i
].name
= BackendList
[n
].name
;
288 BackendList
[i
].Init
= BackendList
[n
].Init
;
290 BackendList
[n
].name
= name
;
291 BackendList
[n
].Init
= Init
;
298 BackendList
[i
].name
= NULL
;
299 BackendList
[i
].Init
= NULL
;
302 for(i
= 0;BackendList
[i
].Init
;i
++)
303 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
305 str
= GetConfigValue(NULL
, "stereodup", "false");
306 DuplicateStereo
= (strcasecmp(str
, "true") == 0 ||
307 strcasecmp(str
, "yes") == 0 ||
308 strcasecmp(str
, "on") == 0 ||
311 str
= GetConfigValue(NULL
, "excludefx", "");
318 { "eaxreverb", EAXREVERB
},
319 { "reverb", REVERB
},
325 const char *next
= str
;
329 next
= strchr(str
, ',');
331 if(!str
[0] || next
== str
)
334 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
335 for(n
= 0;EffectList
[n
].name
;n
++)
337 if(len
== strlen(EffectList
[n
].name
) &&
338 strncmp(EffectList
[n
].name
, str
, len
) == 0)
339 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
346 ALCchar
*AppendDeviceList(char *name
)
349 ALCchar
*ret
= alcDeviceList
+pos
;
350 if(pos
>= sizeof(alcDeviceList
))
352 AL_PRINT("Not enough room to add %s!\n", name
);
353 return alcDeviceList
+ sizeof(alcDeviceList
) - 1;
355 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
-1, "%s", name
) + 1;
359 ALCchar
*AppendAllDeviceList(char *name
)
362 ALCchar
*ret
= alcAllDeviceList
+pos
;
363 if(pos
>= sizeof(alcAllDeviceList
))
365 AL_PRINT("Not enough room to add %s!\n", name
);
366 return alcAllDeviceList
+ sizeof(alcAllDeviceList
) - 1;
368 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
-1, "%s", name
) + 1;
372 ALCchar
*AppendCaptureDeviceList(char *name
)
375 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
376 if(pos
>= sizeof(alcCaptureDeviceList
))
378 AL_PRINT("Not enough room to add %s!\n", name
);
379 return alcCaptureDeviceList
+ sizeof(alcCaptureDeviceList
) - 1;
381 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
-1, "%s", name
) + 1;
388 Check pContext is a valid Context pointer
390 static ALCboolean
IsContext(ALCcontext
*pContext
)
392 ALCcontext
*pTempContext
;
394 pTempContext
= g_pContextList
;
395 while (pTempContext
&& pTempContext
!= pContext
)
396 pTempContext
= pTempContext
->next
;
398 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
405 Store latest ALC Error
407 ALCvoid
SetALCError(ALenum errorCode
)
409 g_eLastContextError
= errorCode
;
418 ALCvoid
SuspendContext(ALCcontext
*pContext
)
421 EnterCriticalSection(&g_csMutex
);
430 ALCvoid
ProcessContext(ALCcontext
*pContext
)
433 LeaveCriticalSection(&g_csMutex
);
440 Initialize Context variables
442 static ALvoid
InitContext(ALCcontext
*pContext
)
446 //Initialise listener
447 pContext
->Listener
.Gain
= 1.0f
;
448 pContext
->Listener
.MetersPerUnit
= 1.0f
;
449 pContext
->Listener
.Position
[0] = 0.0f
;
450 pContext
->Listener
.Position
[1] = 0.0f
;
451 pContext
->Listener
.Position
[2] = 0.0f
;
452 pContext
->Listener
.Velocity
[0] = 0.0f
;
453 pContext
->Listener
.Velocity
[1] = 0.0f
;
454 pContext
->Listener
.Velocity
[2] = 0.0f
;
455 pContext
->Listener
.Forward
[0] = 0.0f
;
456 pContext
->Listener
.Forward
[1] = 0.0f
;
457 pContext
->Listener
.Forward
[2] = -1.0f
;
458 pContext
->Listener
.Up
[0] = 0.0f
;
459 pContext
->Listener
.Up
[1] = 1.0f
;
460 pContext
->Listener
.Up
[2] = 0.0f
;
463 pContext
->LastError
= AL_NO_ERROR
;
464 pContext
->InUse
= AL_FALSE
;
467 pContext
->Frequency
= pContext
->Device
->Frequency
;
470 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
471 pContext
->DopplerFactor
= 1.0f
;
472 pContext
->DopplerVelocity
= 1.0f
;
473 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
475 pContext
->ExtensionList
= "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_EXTX_source_distance_model AL_LOKI_quadriphonic";
477 level
= GetConfigValueInt(NULL
, "cf_level", 0);
478 if(level
> 0 && level
<= 6)
480 pContext
->bs2b
= calloc(1, sizeof(*pContext
->bs2b
));
481 bs2b_set_srate(pContext
->bs2b
, pContext
->Frequency
);
482 bs2b_set_level(pContext
->bs2b
, level
);
485 aluInitPanning(pContext
);
492 Clean up Context, destroy any remaining Sources
494 static ALCvoid
ExitContext(ALCcontext
*pContext
)
497 pContext
->LastError
= AL_NO_ERROR
;
498 pContext
->InUse
= AL_FALSE
;
500 free(pContext
->bs2b
);
501 pContext
->bs2b
= NULL
;
504 ///////////////////////////////////////////////////////
507 ///////////////////////////////////////////////////////
508 // ALC Functions calls
511 // This should probably move to another c file but for now ...
512 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
514 ALCboolean DeviceFound
= ALC_FALSE
;
515 ALCdevice
*pDevice
= NULL
;
522 SetALCError(ALC_INVALID_VALUE
);
526 if(deviceName
&& !deviceName
[0])
529 pDevice
= malloc(sizeof(ALCdevice
));
532 //Initialise device structure
533 memset(pDevice
, 0, sizeof(ALCdevice
));
536 pDevice
->IsCaptureDevice
= AL_TRUE
;
538 pDevice
->Frequency
= frequency
;
539 pDevice
->Format
= format
;
541 for(i
= 0;BackendList
[i
].Init
;i
++)
543 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
544 if(ALCdevice_OpenCapture(pDevice
, deviceName
, frequency
, format
, SampleSize
))
546 SuspendContext(NULL
);
547 pDevice
->next
= g_pDeviceList
;
548 g_pDeviceList
= pDevice
;
550 ProcessContext(NULL
);
552 DeviceFound
= ALC_TRUE
;
559 SetALCError(ALC_INVALID_VALUE
);
565 SetALCError(ALC_OUT_OF_MEMORY
);
570 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
572 ALCboolean bReturn
= ALC_FALSE
;
575 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
577 SuspendContext(NULL
);
579 list
= &g_pDeviceList
;
580 while(*list
!= pDevice
)
581 list
= &(*list
)->next
;
583 *list
= (*list
)->next
;
586 ProcessContext(NULL
);
588 ALCdevice_CloseCapture(pDevice
);
594 SetALCError(ALC_INVALID_DEVICE
);
599 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
601 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
602 ALCdevice_StartCapture(pDevice
);
604 SetALCError(ALC_INVALID_DEVICE
);
607 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
609 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
610 ALCdevice_StopCapture(pDevice
);
612 SetALCError(ALC_INVALID_DEVICE
);
615 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
617 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
618 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
620 SetALCError(ALC_INVALID_DEVICE
);
626 Return last ALC generated error code
628 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
634 errorCode
= g_eLastContextError
;
635 g_eLastContextError
= ALC_NO_ERROR
;
645 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
647 // Not a lot happens here !
657 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
659 // Not a lot happens here !
667 Returns information about the Device, and error strings
669 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
671 const ALCchar
*value
= NULL
;
681 case ALC_INVALID_ENUM
:
682 value
= alcErrInvalidEnum
;
685 case ALC_INVALID_VALUE
:
686 value
= alcErrInvalidValue
;
689 case ALC_INVALID_DEVICE
:
690 value
= alcErrInvalidDevice
;
693 case ALC_INVALID_CONTEXT
:
694 value
= alcErrInvalidContext
;
697 case ALC_OUT_OF_MEMORY
:
698 value
= alcErrOutOfMemory
;
701 case ALC_DEFAULT_DEVICE_SPECIFIER
:
702 value
= alcDefaultDeviceSpecifier
;
705 case ALC_DEVICE_SPECIFIER
:
707 value
= pDevice
->szDeviceName
;
709 value
= alcDeviceList
;
712 case ALC_ALL_DEVICES_SPECIFIER
:
713 value
= alcAllDeviceList
;
716 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
717 value
= alcDefaultAllDeviceSpecifier
;
720 case ALC_CAPTURE_DEVICE_SPECIFIER
:
722 value
= pDevice
->szDeviceName
;
724 value
= alcCaptureDeviceList
;
727 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
728 value
= alcCaptureDefaultDeviceSpecifier
;
732 value
= alcExtensionList
;
736 SetALCError(ALC_INVALID_ENUM
);
747 Returns information about the Device and the version of Open AL
749 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
753 if ((device
)&&(device
->IsCaptureDevice
))
755 SuspendContext(NULL
);
760 case ALC_CAPTURE_SAMPLES
:
761 if ((size
) && (data
))
762 *data
= ALCdevice_AvailableSamples(device
);
764 SetALCError(ALC_INVALID_VALUE
);
768 SetALCError(ALC_INVALID_ENUM
);
772 ProcessContext(NULL
);
781 case ALC_MAJOR_VERSION
:
783 SetALCError(ALC_INVALID_VALUE
);
785 *data
= alcMajorVersion
;
788 case ALC_MINOR_VERSION
:
790 SetALCError(ALC_INVALID_VALUE
);
792 *data
= alcMinorVersion
;
795 case ALC_EFX_MAJOR_VERSION
:
797 SetALCError(ALC_INVALID_VALUE
);
799 *data
= alcEFXMajorVersion
;
802 case ALC_EFX_MINOR_VERSION
:
804 SetALCError(ALC_INVALID_VALUE
);
806 *data
= alcEFXMinorVersion
;
809 case ALC_MAX_AUXILIARY_SENDS
:
811 SetALCError(ALC_INVALID_VALUE
);
813 *data
= (device
?device
->NumAuxSends
:MAX_SENDS
);
816 case ALC_ATTRIBUTES_SIZE
:
818 SetALCError(ALC_INVALID_DEVICE
);
820 SetALCError(ALC_INVALID_VALUE
);
825 case ALC_ALL_ATTRIBUTES
:
827 SetALCError(ALC_INVALID_DEVICE
);
829 SetALCError(ALC_INVALID_VALUE
);
834 SuspendContext(NULL
);
835 data
[i
++] = ALC_FREQUENCY
;
836 data
[i
++] = device
->Frequency
;
838 data
[i
++] = ALC_REFRESH
;
839 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
841 data
[i
++] = ALC_SYNC
;
842 data
[i
++] = ALC_FALSE
;
844 data
[i
++] = ALC_MONO_SOURCES
;
845 data
[i
++] = device
->lNumMonoSources
;
847 data
[i
++] = ALC_STEREO_SOURCES
;
848 data
[i
++] = device
->lNumStereoSources
;
850 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
851 data
[i
++] = device
->NumAuxSends
;
854 ProcessContext(NULL
);
860 SetALCError(ALC_INVALID_DEVICE
);
862 SetALCError(ALC_INVALID_VALUE
);
864 *data
= device
->Frequency
;
869 SetALCError(ALC_INVALID_DEVICE
);
871 SetALCError(ALC_INVALID_VALUE
);
873 *data
= device
->Frequency
/ device
->UpdateSize
;
878 SetALCError(ALC_INVALID_DEVICE
);
880 SetALCError(ALC_INVALID_VALUE
);
885 case ALC_MONO_SOURCES
:
886 if(!device
|| !device
->Context
)
887 SetALCError(ALC_INVALID_DEVICE
);
889 SetALCError(ALC_INVALID_VALUE
);
891 *data
= device
->lNumMonoSources
;
894 case ALC_STEREO_SOURCES
:
895 if(!device
|| !device
->Context
)
896 SetALCError(ALC_INVALID_DEVICE
);
898 SetALCError(ALC_INVALID_VALUE
);
900 *data
= device
->lNumStereoSources
;
904 SetALCError(ALC_INVALID_ENUM
);
909 SetALCError(ALC_INVALID_VALUE
);
917 alcIsExtensionPresent
919 Determines if there is support for a particular extension
921 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
923 ALCboolean bResult
= ALC_FALSE
;
932 len
= strlen(extName
);
933 ptr
= alcExtensionList
;
936 if(strncasecmp(ptr
, extName
, len
) == 0 &&
937 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
942 if((ptr
=strchr(ptr
, ' ')) != NULL
)
946 } while(isspace(*ptr
));
951 SetALCError(ALC_INVALID_VALUE
);
960 Retrieves the function address for a particular extension function
962 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
964 ALCvoid
*pFunction
= NULL
;
971 while(alcFunctions
[i
].funcName
&&
972 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
974 pFunction
= alcFunctions
[i
].address
;
977 SetALCError(ALC_INVALID_VALUE
);
986 Get the value for a particular ALC Enumerated Value
988 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
995 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
997 val
= enumeration
[i
].value
;
999 if(!enumeration
[i
].enumName
)
1000 SetALCError(ALC_INVALID_VALUE
);
1009 Create and attach a Context to a particular Device.
1011 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1013 ALCcontext
*ALContext
= NULL
;
1014 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
1015 ALuint RequestedSends
;
1017 if ((device
)&&(!device
->IsCaptureDevice
))
1019 // Reset Context Last Error code
1020 g_eLastContextError
= ALC_NO_ERROR
;
1022 // Current implementation only allows one Context per Device
1023 if(!device
->Context
)
1025 ALContext
= calloc(1, sizeof(ALCcontext
));
1028 SetALCError(ALC_OUT_OF_MEMORY
);
1032 ALContext
->Device
= device
;
1033 InitContext(ALContext
);
1035 device
->Context
= ALContext
;
1037 SuspendContext(NULL
);
1039 ALContext
->next
= g_pContextList
;
1040 g_pContextList
= ALContext
;
1043 ProcessContext(NULL
);
1045 // Check for attributes
1048 ALCint numMono
= ALContext
->Device
->lNumMonoSources
;
1049 ALCint numStereo
= ALContext
->Device
->lNumStereoSources
;
1050 ALCuint numSends
= ALContext
->Device
->NumAuxSends
;
1052 ulAttributeIndex
= 0;
1053 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
1055 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
1057 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
1059 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
1060 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
1062 numStereo
= ulRequestedStereoSources
;
1063 numMono
= ALContext
->Device
->MaxNoOfSources
- numStereo
;
1066 if(attrList
[ulAttributeIndex
] == ALC_MAX_AUXILIARY_SENDS
)
1068 RequestedSends
= attrList
[ulAttributeIndex
+ 1];
1070 if(RequestedSends
> ALContext
->Device
->NumAuxSends
)
1071 RequestedSends
= ALContext
->Device
->NumAuxSends
;
1073 numSends
= RequestedSends
;
1076 ulAttributeIndex
+= 2;
1079 ALContext
->Device
->lNumMonoSources
= numMono
;
1080 ALContext
->Device
->lNumStereoSources
= numStereo
;
1081 ALContext
->Device
->NumAuxSends
= numSends
;
1086 SetALCError(ALC_INVALID_VALUE
);
1091 SetALCError(ALC_INVALID_DEVICE
);
1102 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1108 // Lock context list
1109 SuspendContext(NULL
);
1111 if (IsContext(context
))
1114 SuspendContext(context
);
1116 ReleaseALSources(context
);
1117 ReleaseALAuxiliaryEffectSlots(context
);
1119 context
->Device
->Context
= NULL
;
1121 list
= &g_pContextList
;
1122 while(*list
!= context
)
1123 list
= &(*list
)->next
;
1125 *list
= (*list
)->next
;
1129 ProcessContext(context
);
1131 ExitContext(context
);
1133 // Free memory (MUST do this after ProcessContext)
1134 memset(context
, 0, sizeof(ALCcontext
));
1138 SetALCError(ALC_INVALID_CONTEXT
);
1140 ProcessContext(NULL
);
1145 alcGetCurrentContext
1147 Returns the currently active Context
1149 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1151 ALCcontext
*pContext
= NULL
;
1155 SuspendContext(NULL
);
1157 pContext
= g_pContextList
;
1158 while ((pContext
) && (!pContext
->InUse
))
1159 pContext
= pContext
->next
;
1161 ProcessContext(NULL
);
1168 alcGetContextsDevice
1170 Returns the Device that a particular Context is attached to
1172 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1174 ALCdevice
*pDevice
= NULL
;
1178 SuspendContext(NULL
);
1179 if (IsContext(pContext
))
1180 pDevice
= pContext
->Device
;
1182 SetALCError(ALC_INVALID_CONTEXT
);
1183 ProcessContext(NULL
);
1190 alcMakeContextCurrent
1192 Makes the given Context the active Context
1194 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1196 ALCcontext
*ALContext
;
1197 ALboolean bReturn
= AL_TRUE
;
1201 SuspendContext(NULL
);
1203 // context must be a valid Context or NULL
1204 if ((IsContext(context
)) || (context
== NULL
))
1206 if ((ALContext
=alcGetCurrentContext()))
1208 SuspendContext(ALContext
);
1209 ALContext
->InUse
=AL_FALSE
;
1210 ProcessContext(ALContext
);
1213 if ((ALContext
=context
) && (ALContext
->Device
))
1215 SuspendContext(ALContext
);
1216 ALContext
->InUse
=AL_TRUE
;
1217 ProcessContext(ALContext
);
1222 SetALCError(ALC_INVALID_CONTEXT
);
1226 ProcessContext(NULL
);
1235 Open the Device specified.
1237 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1239 ALboolean bDeviceFound
= AL_FALSE
;
1245 if(deviceName
&& !deviceName
[0])
1248 device
= malloc(sizeof(ALCdevice
));
1253 //Initialise device structure
1254 memset(device
, 0, sizeof(ALCdevice
));
1257 device
->IsCaptureDevice
= AL_FALSE
;
1260 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1261 if((ALint
)device
->Frequency
<= 0)
1262 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1264 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1266 device
->Format
= alGetEnumValue(fmt
);
1268 if(!aluChannelsFromFormat(device
->Format
))
1269 device
->Format
= AL_FORMAT_STEREO16
;
1271 device
->UpdateSize
= GetConfigValueInt(NULL
, "refresh", 4096);
1272 if((ALint
)device
->UpdateSize
<= 0)
1273 device
->UpdateSize
= 4096;
1275 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1276 if((ALint
)device
->MaxNoOfSources
<= 0)
1277 device
->MaxNoOfSources
= 256;
1279 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1280 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1281 device
->AuxiliaryEffectSlotMax
= 4;
1283 device
->lNumStereoSources
= 1;
1284 device
->lNumMonoSources
= device
->MaxNoOfSources
- device
->lNumStereoSources
;
1286 device
->NumAuxSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
1287 if(device
->NumAuxSends
> MAX_SENDS
)
1288 device
->NumAuxSends
= MAX_SENDS
;
1290 // Find a playback device to open
1291 SuspendContext(NULL
);
1292 for(i
= 0;BackendList
[i
].Init
;i
++)
1294 device
->Funcs
= &BackendList
[i
].Funcs
;
1295 if(ALCdevice_OpenPlayback(device
, deviceName
))
1297 device
->next
= g_pDeviceList
;
1298 g_pDeviceList
= device
;
1301 bDeviceFound
= AL_TRUE
;
1305 ProcessContext(NULL
);
1309 // No suitable output device found
1310 SetALCError(ALC_INVALID_VALUE
);
1316 SetALCError(ALC_OUT_OF_MEMORY
);
1325 Close the specified Device
1327 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1329 ALCboolean bReturn
= ALC_FALSE
;
1332 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1334 SuspendContext(NULL
);
1336 list
= &g_pDeviceList
;
1337 while(*list
!= pDevice
)
1338 list
= &(*list
)->next
;
1340 *list
= (*list
)->next
;
1343 ProcessContext(NULL
);
1345 if(pDevice
->Context
)
1348 AL_PRINT("alcCloseDevice(): destroying 1 Context\n");
1350 alcDestroyContext(pDevice
->Context
);
1352 ALCdevice_ClosePlayback(pDevice
);
1354 //Release device structure
1355 memset(pDevice
, 0, sizeof(ALCdevice
));
1361 SetALCError(ALC_INVALID_DEVICE
);
1367 ALCvoid
ReleaseALC(ALCvoid
)
1370 if(g_ulDeviceCount
> 0)
1371 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1374 while(g_pDeviceList
)
1376 if(g_pDeviceList
->IsCaptureDevice
)
1377 alcCaptureCloseDevice(g_pDeviceList
);
1379 alcCloseDevice(g_pDeviceList
);
1383 ///////////////////////////////////////////////////////