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
21 #define _CRT_SECURE_NO_DEPRECATE // get rid of sprintf security warnings on VS2005
36 #include "alExtension.h"
37 #include "alAuxEffectSlot.h"
40 ///////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////
48 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
51 void (*Init
)(BackendFuncs
*);
55 { "alsa", alc_alsa_init
, EmptyFuncs
},
58 { "oss", alc_oss_init
, EmptyFuncs
},
61 { "dsound", alcDSoundInit
, EmptyFuncs
},
64 { "winmm", alcWinMMInit
, EmptyFuncs
},
67 { "wave", alc_wave_init
, EmptyFuncs
},
69 { NULL
, NULL
, EmptyFuncs
}
73 ///////////////////////////////////////////////////////
75 #define ALC_EFX_MAJOR_VERSION 0x20001
76 #define ALC_EFX_MINOR_VERSION 0x20002
77 #define ALC_MAX_AUXILIARY_SENDS 0x20003
79 ///////////////////////////////////////////////////////
80 // STRING and EXTENSIONS
82 typedef struct ALCfunction_struct
88 static ALCfunction alcFunctions
[] = {
89 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
90 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
91 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
92 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
93 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
94 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
95 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
96 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
97 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
98 { "alcGetError", (ALvoid
*) alcGetError
},
99 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
100 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
101 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
102 { "alcGetString", (ALvoid
*) alcGetString
},
103 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
104 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
105 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
106 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
107 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
108 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
109 { NULL
, (ALvoid
*) NULL
}
112 static ALenums enumeration
[]={
114 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
115 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
116 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
119 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
120 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
121 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
122 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
123 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
124 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
125 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
126 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
127 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
128 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
129 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
130 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
131 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
132 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
133 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
134 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
135 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
138 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
139 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
140 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
143 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
144 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
145 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
146 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
147 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
148 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
149 { (ALchar
*)NULL
, (ALenum
)0 }
152 static const ALCchar alcNoError
[] = "No Error";
153 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
154 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
155 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
156 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
157 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
160 static ALCchar alcDeviceList
[2048];
161 static ALCchar alcAllDeviceList
[2048];
162 static ALCchar alcCaptureDeviceList
[2048];
163 // Default is always the first in the list
164 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
165 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
166 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
169 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
170 static ALCint alcMajorVersion
= 1;
171 static ALCint alcMinorVersion
= 1;
173 static ALCint alcEFXMajorVersion
= 1;
174 static ALCint alcEFXMinorVersion
= 0;
176 ///////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////
182 static ALCdevice
*g_pDeviceList
= NULL
;
183 static ALCuint g_ulDeviceCount
= 0;
186 static ALCcontext
*g_pContextList
= NULL
;
187 static ALCuint g_ulContextCount
= 0;
190 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
192 ///////////////////////////////////////////////////////
195 ///////////////////////////////////////////////////////
196 // ALC Related helper functions
198 static void InitAL(void)
204 const char *devs
, *str
;
208 InitializeCriticalSection(&_alMutex
);
212 devs
= GetConfigValue(NULL
, "drivers", "");
217 const char *next
= devs
;
223 next
= strchr(devs
, ',');
225 if(!devs
[0] || devs
[0] == ',')
228 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
229 for(n
= i
;BackendList
[n
].Init
;n
++)
231 if(len
== strlen(BackendList
[n
].name
) &&
232 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
234 const char *name
= BackendList
[i
].name
;
235 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
237 BackendList
[i
].name
= BackendList
[n
].name
;
238 BackendList
[i
].Init
= BackendList
[n
].Init
;
240 BackendList
[n
].name
= name
;
241 BackendList
[n
].Init
= Init
;
248 BackendList
[i
].name
= NULL
;
249 BackendList
[i
].Init
= NULL
;
252 for(i
= 0;BackendList
[i
].Init
;i
++)
253 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
255 str
= GetConfigValue(NULL
, "stereodup", "false");
256 DuplicateStereo
= (strcasecmp(str
, "true") == 0 ||
257 strcasecmp(str
, "yes") == 0 ||
258 strcasecmp(str
, "on") == 0 ||
263 ALCchar
*AppendDeviceList(char *name
)
266 ALCchar
*ret
= alcDeviceList
+pos
;
267 if(pos
>= sizeof(alcDeviceList
))
269 AL_PRINT("Not enough room to add %s!\n", name
);
270 return alcDeviceList
+ sizeof(alcDeviceList
) - 1;
272 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
-1, "%s", name
) + 1;
276 ALCchar
*AppendAllDeviceList(char *name
)
279 ALCchar
*ret
= alcAllDeviceList
+pos
;
280 if(pos
>= sizeof(alcAllDeviceList
))
282 AL_PRINT("Not enough room to add %s!\n", name
);
283 return alcAllDeviceList
+ sizeof(alcAllDeviceList
) - 1;
285 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
-1, "%s", name
) + 1;
289 ALCchar
*AppendCaptureDeviceList(char *name
)
292 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
293 if(pos
>= sizeof(alcCaptureDeviceList
))
295 AL_PRINT("Not enough room to add %s!\n", name
);
296 return alcCaptureDeviceList
+ sizeof(alcCaptureDeviceList
) - 1;
298 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
-1, "%s", name
) + 1;
305 Check pContext is a valid Context pointer
307 static ALCboolean
IsContext(ALCcontext
*pContext
)
309 ALCcontext
*pTempContext
;
311 pTempContext
= g_pContextList
;
312 while (pTempContext
&& pTempContext
!= pContext
)
313 pTempContext
= pTempContext
->next
;
315 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
322 Store latest ALC Error
324 ALCvoid
SetALCError(ALenum errorCode
)
326 g_eLastContextError
= errorCode
;
335 ALCvoid
SuspendContext(ALCcontext
*pContext
)
338 EnterCriticalSection(&_alMutex
);
347 ALCvoid
ProcessContext(ALCcontext
*pContext
)
350 LeaveCriticalSection(&_alMutex
);
357 Initialize Context variables
359 static ALvoid
InitContext(ALCcontext
*pContext
)
363 //Initialise listener
364 pContext
->Listener
.Gain
= 1.0f
;
365 pContext
->Listener
.MetersPerUnit
= 1.0f
;
366 pContext
->Listener
.Position
[0] = 0.0f
;
367 pContext
->Listener
.Position
[1] = 0.0f
;
368 pContext
->Listener
.Position
[2] = 0.0f
;
369 pContext
->Listener
.Velocity
[0] = 0.0f
;
370 pContext
->Listener
.Velocity
[1] = 0.0f
;
371 pContext
->Listener
.Velocity
[2] = 0.0f
;
372 pContext
->Listener
.Forward
[0] = 0.0f
;
373 pContext
->Listener
.Forward
[1] = 0.0f
;
374 pContext
->Listener
.Forward
[2] = -1.0f
;
375 pContext
->Listener
.Up
[0] = 0.0f
;
376 pContext
->Listener
.Up
[1] = 1.0f
;
377 pContext
->Listener
.Up
[2] = 0.0f
;
380 pContext
->LastError
= AL_NO_ERROR
;
381 pContext
->InUse
= AL_FALSE
;
384 pContext
->Frequency
= pContext
->Device
->Frequency
;
387 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
388 pContext
->DopplerFactor
= 1.0f
;
389 pContext
->DopplerVelocity
= 1.0f
;
390 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
392 pContext
->lNumStereoSources
= 1;
393 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
395 strcpy(pContext
->ExtensionList
, "AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_LOKI_quadriphonic");
397 level
= GetConfigValueInt(NULL
, "cf_level", 0);
398 if(level
> 0 && level
<= 6)
400 pContext
->bs2b
= calloc(1, sizeof(*pContext
->bs2b
));
401 bs2b_set_srate(pContext
->bs2b
, pContext
->Frequency
);
402 bs2b_set_level(pContext
->bs2b
, level
);
410 Clean up Context, destroy any remaining Sources
412 static ALCvoid
ExitContext(ALCcontext
*pContext
)
415 pContext
->LastError
= AL_NO_ERROR
;
416 pContext
->InUse
= AL_FALSE
;
418 free(pContext
->bs2b
);
419 pContext
->bs2b
= NULL
;
422 ///////////////////////////////////////////////////////
425 ///////////////////////////////////////////////////////
426 // ALC Functions calls
429 // This should probably move to another c file but for now ...
430 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
432 ALCboolean DeviceFound
= ALC_FALSE
;
433 ALCdevice
*pDevice
= NULL
;
438 if(deviceName
&& !deviceName
[0])
441 pDevice
= malloc(sizeof(ALCdevice
));
446 //Initialise device structure
447 memset(pDevice
, 0, sizeof(ALCdevice
));
450 pDevice
->IsCaptureDevice
= AL_TRUE
;
452 pDevice
->Frequency
= frequency
;
453 pDevice
->Format
= format
;
455 for(i
= 0;BackendList
[i
].Init
;i
++)
457 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
458 if(ALCdevice_OpenCapture(pDevice
, deviceName
, frequency
, format
, SampleSize
))
460 SuspendContext(NULL
);
461 pDevice
->next
= g_pDeviceList
;
462 g_pDeviceList
= pDevice
;
464 ProcessContext(NULL
);
466 DeviceFound
= ALC_TRUE
;
472 SetALCError(ALC_INVALID_VALUE
);
481 SetALCError(ALC_OUT_OF_MEMORY
);
486 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
488 ALCboolean bReturn
= ALC_FALSE
;
491 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
493 SuspendContext(NULL
);
495 list
= &g_pDeviceList
;
496 while(*list
!= pDevice
)
497 list
= &(*list
)->next
;
499 *list
= (*list
)->next
;
502 ProcessContext(NULL
);
504 ALCdevice_CloseCapture(pDevice
);
510 SetALCError(ALC_INVALID_DEVICE
);
515 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
517 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
518 ALCdevice_StartCapture(pDevice
);
520 SetALCError(ALC_INVALID_DEVICE
);
523 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
525 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
526 ALCdevice_StopCapture(pDevice
);
528 SetALCError(ALC_INVALID_DEVICE
);
531 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
533 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
534 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
536 SetALCError(ALC_INVALID_DEVICE
);
542 Return last ALC generated error code
544 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
550 errorCode
= g_eLastContextError
;
551 g_eLastContextError
= ALC_NO_ERROR
;
561 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
563 // Not a lot happens here !
573 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
575 // Not a lot happens here !
583 Returns information about the Device, and error strings
585 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
587 const ALCchar
*value
= NULL
;
597 case ALC_INVALID_ENUM
:
598 value
= alcErrInvalidEnum
;
601 case ALC_INVALID_VALUE
:
602 value
= alcErrInvalidValue
;
605 case ALC_INVALID_DEVICE
:
606 value
= alcErrInvalidDevice
;
609 case ALC_INVALID_CONTEXT
:
610 value
= alcErrInvalidContext
;
613 case ALC_OUT_OF_MEMORY
:
614 value
= alcErrOutOfMemory
;
617 case ALC_DEFAULT_DEVICE_SPECIFIER
:
618 value
= alcDefaultDeviceSpecifier
;
621 case ALC_DEVICE_SPECIFIER
:
623 value
= pDevice
->szDeviceName
;
625 value
= alcDeviceList
;
628 case ALC_ALL_DEVICES_SPECIFIER
:
629 value
= alcAllDeviceList
;
632 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
633 value
= alcDefaultAllDeviceSpecifier
;
636 case ALC_CAPTURE_DEVICE_SPECIFIER
:
638 value
= pDevice
->szDeviceName
;
640 value
= alcCaptureDeviceList
;
643 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
644 value
= alcCaptureDefaultDeviceSpecifier
;
648 value
= alcExtensionList
;
652 SetALCError(ALC_INVALID_ENUM
);
663 Returns information about the Device and the version of Open AL
665 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
669 if ((device
)&&(device
->IsCaptureDevice
))
671 SuspendContext(NULL
);
676 case ALC_CAPTURE_SAMPLES
:
677 if ((size
) && (data
))
678 *data
= ALCdevice_AvailableSamples(device
);
680 SetALCError(ALC_INVALID_VALUE
);
684 SetALCError(ALC_INVALID_ENUM
);
688 ProcessContext(NULL
);
697 case ALC_MAJOR_VERSION
:
699 SetALCError(ALC_INVALID_VALUE
);
701 *data
= alcMajorVersion
;
704 case ALC_MINOR_VERSION
:
706 SetALCError(ALC_INVALID_VALUE
);
708 *data
= alcMinorVersion
;
711 case ALC_EFX_MAJOR_VERSION
:
713 SetALCError(ALC_INVALID_VALUE
);
715 *data
= alcEFXMajorVersion
;
718 case ALC_EFX_MINOR_VERSION
:
720 SetALCError(ALC_INVALID_VALUE
);
722 *data
= alcEFXMinorVersion
;
725 case ALC_MAX_AUXILIARY_SENDS
:
727 SetALCError(ALC_INVALID_VALUE
);
732 case ALC_ATTRIBUTES_SIZE
:
734 SetALCError(ALC_INVALID_DEVICE
);
736 SetALCError(ALC_INVALID_VALUE
);
741 case ALC_ALL_ATTRIBUTES
:
743 SetALCError(ALC_INVALID_DEVICE
);
745 SetALCError(ALC_INVALID_VALUE
);
750 data
[i
++] = ALC_FREQUENCY
;
751 data
[i
++] = device
->Frequency
;
753 data
[i
++] = ALC_REFRESH
;
754 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
756 data
[i
++] = ALC_SYNC
;
757 data
[i
++] = ALC_FALSE
;
759 SuspendContext(NULL
);
760 if(device
->Context
&& size
>= 12)
762 data
[i
++] = ALC_MONO_SOURCES
;
763 data
[i
++] = device
->Context
->lNumMonoSources
;
765 data
[i
++] = ALC_STEREO_SOURCES
;
766 data
[i
++] = device
->Context
->lNumStereoSources
;
768 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
769 data
[i
++] = MAX_SENDS
;
771 ProcessContext(NULL
);
779 SetALCError(ALC_INVALID_DEVICE
);
781 SetALCError(ALC_INVALID_VALUE
);
783 *data
= device
->Frequency
;
788 SetALCError(ALC_INVALID_DEVICE
);
790 SetALCError(ALC_INVALID_VALUE
);
792 *data
= device
->Frequency
/ device
->UpdateSize
;
797 SetALCError(ALC_INVALID_DEVICE
);
799 SetALCError(ALC_INVALID_VALUE
);
804 case ALC_MONO_SOURCES
:
805 if(!device
|| !device
->Context
)
806 SetALCError(ALC_INVALID_DEVICE
);
808 SetALCError(ALC_INVALID_VALUE
);
810 *data
= device
->Context
->lNumMonoSources
;
813 case ALC_STEREO_SOURCES
:
814 if(!device
|| !device
->Context
)
815 SetALCError(ALC_INVALID_DEVICE
);
817 SetALCError(ALC_INVALID_VALUE
);
819 *data
= device
->Context
->lNumStereoSources
;
823 SetALCError(ALC_INVALID_ENUM
);
828 SetALCError(ALC_INVALID_VALUE
);
836 alcIsExtensionPresent
838 Determines if there is support for a particular extension
840 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
842 ALCboolean bResult
= ALC_FALSE
;
851 len
= strlen(extName
);
852 ptr
= alcExtensionList
;
855 if(strncasecmp(ptr
, extName
, len
) == 0 &&
856 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
861 if((ptr
=strchr(ptr
, ' ')) != NULL
)
865 } while(isspace(*ptr
));
870 SetALCError(ALC_INVALID_VALUE
);
879 Retrieves the function address for a particular extension function
881 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
883 ALCvoid
*pFunction
= NULL
;
890 while(alcFunctions
[i
].funcName
&&
891 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
893 pFunction
= alcFunctions
[i
].address
;
896 SetALCError(ALC_INVALID_VALUE
);
905 Get the value for a particular ALC Enumerated Value
907 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
914 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
916 val
= enumeration
[i
].value
;
918 if(!enumeration
[i
].enumName
)
919 SetALCError(ALC_INVALID_VALUE
);
928 Create and attach a Context to a particular Device.
930 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
932 ALCcontext
*ALContext
= NULL
;
933 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
935 if ((device
)&&(!device
->IsCaptureDevice
))
937 // Reset Context Last Error code
938 g_eLastContextError
= ALC_NO_ERROR
;
940 // Current implementation only allows one Context per Device
943 ALContext
= calloc(1, sizeof(ALCcontext
));
946 SetALCError(ALC_OUT_OF_MEMORY
);
950 ALContext
->Device
= device
;
951 InitContext(ALContext
);
953 device
->Context
= ALContext
;
955 SuspendContext(NULL
);
957 ALContext
->next
= g_pContextList
;
958 g_pContextList
= ALContext
;
961 ProcessContext(NULL
);
963 // Check for Voice Count attributes
966 ulAttributeIndex
= 0;
967 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
969 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
971 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
973 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
974 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
976 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
977 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
981 ulAttributeIndex
+= 2;
987 SetALCError(ALC_INVALID_VALUE
);
992 SetALCError(ALC_INVALID_DEVICE
);
1003 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1009 // Lock context list
1010 SuspendContext(NULL
);
1012 if (IsContext(context
))
1015 SuspendContext(context
);
1017 ReleaseALSources(context
);
1018 ReleaseALAuxiliaryEffectSlots(context
);
1020 context
->Device
->Context
= NULL
;
1022 list
= &g_pContextList
;
1023 while(*list
!= context
)
1024 list
= &(*list
)->next
;
1026 *list
= (*list
)->next
;
1030 ProcessContext(context
);
1032 ExitContext(context
);
1034 // Free memory (MUST do this after ProcessContext)
1035 memset(context
, 0, sizeof(ALCcontext
));
1039 SetALCError(ALC_INVALID_CONTEXT
);
1041 ProcessContext(NULL
);
1046 alcGetCurrentContext
1048 Returns the currently active Context
1050 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1052 ALCcontext
*pContext
= NULL
;
1056 SuspendContext(NULL
);
1058 pContext
= g_pContextList
;
1059 while ((pContext
) && (!pContext
->InUse
))
1060 pContext
= pContext
->next
;
1062 ProcessContext(NULL
);
1069 alcGetContextsDevice
1071 Returns the Device that a particular Context is attached to
1073 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1075 ALCdevice
*pDevice
= NULL
;
1079 SuspendContext(NULL
);
1080 if (IsContext(pContext
))
1081 pDevice
= pContext
->Device
;
1083 SetALCError(ALC_INVALID_CONTEXT
);
1084 ProcessContext(NULL
);
1091 alcMakeContextCurrent
1093 Makes the given Context the active Context
1095 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1097 ALCcontext
*ALContext
;
1098 ALboolean bReturn
= AL_TRUE
;
1102 SuspendContext(NULL
);
1104 // context must be a valid Context or NULL
1105 if ((IsContext(context
)) || (context
== NULL
))
1107 if ((ALContext
=alcGetCurrentContext()))
1109 SuspendContext(ALContext
);
1110 ALContext
->InUse
=AL_FALSE
;
1111 ProcessContext(ALContext
);
1114 if ((ALContext
=context
) && (ALContext
->Device
))
1116 SuspendContext(ALContext
);
1117 ALContext
->InUse
=AL_TRUE
;
1118 ProcessContext(ALContext
);
1123 SetALCError(ALC_INVALID_CONTEXT
);
1127 ProcessContext(NULL
);
1136 Open the Device specified.
1138 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1140 ALboolean bDeviceFound
= AL_FALSE
;
1146 if(deviceName
&& !deviceName
[0])
1149 device
= malloc(sizeof(ALCdevice
));
1154 //Initialise device structure
1155 memset(device
, 0, sizeof(ALCdevice
));
1158 device
->IsCaptureDevice
= AL_FALSE
;
1161 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1162 if((ALint
)device
->Frequency
<= 0)
1163 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1165 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1167 device
->Format
= alGetEnumValue(fmt
);
1169 if(!aluChannelsFromFormat(device
->Format
))
1170 device
->Format
= AL_FORMAT_STEREO16
;
1172 device
->UpdateSize
= GetConfigValueInt(NULL
, "refresh", 8192);
1173 if((ALint
)device
->UpdateSize
<= 0)
1174 device
->UpdateSize
= 8192;
1176 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1177 if((ALint
)device
->MaxNoOfSources
<= 0)
1178 device
->MaxNoOfSources
= 256;
1180 // Find a playback device to open
1181 for(i
= 0;BackendList
[i
].Init
;i
++)
1183 device
->Funcs
= &BackendList
[i
].Funcs
;
1184 if(ALCdevice_OpenPlayback(device
, deviceName
))
1186 SuspendContext(NULL
);
1187 device
->next
= g_pDeviceList
;
1188 g_pDeviceList
= device
;
1190 ProcessContext(NULL
);
1192 bDeviceFound
= AL_TRUE
;
1199 // No suitable output device found
1212 Close the specified Device
1214 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1216 ALCboolean bReturn
= ALC_FALSE
;
1219 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1221 SuspendContext(NULL
);
1223 list
= &g_pDeviceList
;
1224 while(*list
!= pDevice
)
1225 list
= &(*list
)->next
;
1227 *list
= (*list
)->next
;
1230 ProcessContext(NULL
);
1232 if(pDevice
->Context
)
1233 alcDestroyContext(pDevice
->Context
);
1234 ALCdevice_ClosePlayback(pDevice
);
1236 //Release device structure
1237 memset(pDevice
, 0, sizeof(ALCdevice
));
1243 SetALCError(ALC_INVALID_DEVICE
);
1249 ALCvoid
ReleaseALC(ALCvoid
)
1252 if(g_ulContextCount
> 0)
1253 AL_PRINT("exit() %u device(s) and %u context(s) NOT deleted\n", g_ulDeviceCount
, g_ulContextCount
);
1256 while(g_pDeviceList
)
1258 if(g_pDeviceList
->IsCaptureDevice
)
1259 alcCaptureCloseDevice(g_pDeviceList
);
1261 alcCloseDevice(g_pDeviceList
);
1265 ///////////////////////////////////////////////////////