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
35 #include "alExtension.h"
36 #include "alAuxEffectSlot.h"
39 ///////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////
47 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
50 void (*Init
)(BackendFuncs
*);
54 { "alsa", alc_alsa_init
, EmptyFuncs
},
57 { "oss", alc_oss_init
, EmptyFuncs
},
60 { "dsound", alcDSoundInit
, EmptyFuncs
},
63 { "winmm", alcWinMMInit
, EmptyFuncs
},
66 { "wave", alc_wave_init
, EmptyFuncs
},
68 { NULL
, NULL
, EmptyFuncs
}
72 ///////////////////////////////////////////////////////
74 #define ALC_EFX_MAJOR_VERSION 0x20001
75 #define ALC_EFX_MINOR_VERSION 0x20002
76 #define ALC_MAX_AUXILIARY_SENDS 0x20003
78 ///////////////////////////////////////////////////////
79 // STRING and EXTENSIONS
81 typedef struct ALCextension_struct
87 typedef struct ALCfunction_struct
93 static ALCextension alcExtensions
[] = {
94 { "ALC_ENUMERATE_ALL_EXT", (ALvoid
*) NULL
},
95 { "ALC_ENUMERATION_EXT", (ALvoid
*) NULL
},
96 { "ALC_EXT_CAPTURE", (ALvoid
*) NULL
},
97 { "ALC_EXT_EFX", (ALvoid
*) NULL
},
98 { NULL
, (ALvoid
*) NULL
}
101 static ALCfunction alcFunctions
[] = {
102 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
103 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
104 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
105 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
106 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
107 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
108 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
109 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
110 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
111 { "alcGetError", (ALvoid
*) alcGetError
},
112 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
113 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
114 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
115 { "alcGetString", (ALvoid
*) alcGetString
},
116 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
117 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
118 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
119 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
120 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
121 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
122 { NULL
, (ALvoid
*) NULL
}
125 static ALenums enumeration
[]={
127 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
128 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
129 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
132 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
133 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
134 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
135 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
136 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
137 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
138 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
139 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
140 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
141 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
142 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
143 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
144 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
145 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
146 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
147 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
148 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
151 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
152 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
153 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
156 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
157 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
158 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
159 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
160 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
161 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
162 { (ALchar
*)NULL
, (ALenum
)0 }
165 static const ALCchar alcNoError
[] = "No Error";
166 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
167 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
168 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
169 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
170 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
173 static ALCchar alcDeviceList
[2048];
174 static ALCchar alcAllDeviceList
[2048];
175 static ALCchar alcCaptureDeviceList
[2048];
176 // Default is always the first in the list
177 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
178 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
179 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
182 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
183 static ALCint alcMajorVersion
= 1;
184 static ALCint alcMinorVersion
= 1;
186 static ALCint alcEFXMajorVersion
= 1;
187 static ALCint alcEFXMinorVersion
= 0;
189 ///////////////////////////////////////////////////////
192 ///////////////////////////////////////////////////////
195 static ALCdevice
*g_pDeviceList
= NULL
;
196 static ALCuint g_ulDeviceCount
= 0;
199 static ALCcontext
*g_pContextList
= NULL
;
200 static ALCuint g_ulContextCount
= 0;
203 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
205 ///////////////////////////////////////////////////////
208 ///////////////////////////////////////////////////////
209 // ALC Related helper functions
211 static void InitAL(void)
219 InitializeCriticalSection(&_alMutex
);
223 devs
= GetConfigValue(NULL
, "drivers", "");
228 const char *next
= devs
;
234 next
= strchr(devs
, ',');
236 if(!devs
[0] || devs
[0] == ',')
239 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
240 for(n
= i
;BackendList
[n
].Init
;n
++)
242 if(len
== strlen(BackendList
[n
].name
) &&
243 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
245 const char *name
= BackendList
[i
].name
;
246 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
248 BackendList
[i
].name
= BackendList
[n
].name
;
249 BackendList
[i
].Init
= BackendList
[n
].Init
;
251 BackendList
[n
].name
= name
;
252 BackendList
[n
].Init
= Init
;
259 BackendList
[i
].name
= NULL
;
260 BackendList
[i
].Init
= NULL
;
263 for(i
= 0;BackendList
[i
].Init
;i
++)
264 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
269 ALCchar
*AppendDeviceList(char *name
)
272 ALCchar
*ret
= alcDeviceList
+pos
;
273 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
, "%s", name
) + 1;
277 ALCchar
*AppendAllDeviceList(char *name
)
280 ALCchar
*ret
= alcAllDeviceList
+pos
;
281 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
, "%s", name
) + 1;
285 ALCchar
*AppendCaptureDeviceList(char *name
)
288 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
289 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
, "%s", name
) + 1;
296 Check pContext is a valid Context pointer
298 static ALCboolean
IsContext(ALCcontext
*pContext
)
300 ALCcontext
*pTempContext
;
302 pTempContext
= g_pContextList
;
303 while (pTempContext
&& pTempContext
!= pContext
)
304 pTempContext
= pTempContext
->next
;
306 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
313 Store latest ALC Error
315 ALCvoid
SetALCError(ALenum errorCode
)
317 g_eLastContextError
= errorCode
;
326 ALCvoid
SuspendContext(ALCcontext
*pContext
)
329 EnterCriticalSection(&_alMutex
);
338 ALCvoid
ProcessContext(ALCcontext
*pContext
)
341 LeaveCriticalSection(&_alMutex
);
348 Initialize Context variables
350 static ALvoid
InitContext(ALCcontext
*pContext
)
354 //Initialise listener
355 pContext
->Listener
.Gain
= 1.0f
;
356 pContext
->Listener
.MetersPerUnit
= 1.0f
;
357 pContext
->Listener
.Position
[0] = 0.0f
;
358 pContext
->Listener
.Position
[1] = 0.0f
;
359 pContext
->Listener
.Position
[2] = 0.0f
;
360 pContext
->Listener
.Velocity
[0] = 0.0f
;
361 pContext
->Listener
.Velocity
[1] = 0.0f
;
362 pContext
->Listener
.Velocity
[2] = 0.0f
;
363 pContext
->Listener
.Forward
[0] = 0.0f
;
364 pContext
->Listener
.Forward
[1] = 0.0f
;
365 pContext
->Listener
.Forward
[2] = -1.0f
;
366 pContext
->Listener
.Up
[0] = 0.0f
;
367 pContext
->Listener
.Up
[1] = 1.0f
;
368 pContext
->Listener
.Up
[2] = 0.0f
;
371 pContext
->LastError
= AL_NO_ERROR
;
372 pContext
->InUse
= AL_FALSE
;
375 pContext
->Frequency
= pContext
->Device
->Frequency
;
378 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
379 pContext
->DopplerFactor
= 1.0f
;
380 pContext
->DopplerVelocity
= 1.0f
;
381 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
383 pContext
->lNumStereoSources
= 1;
384 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
386 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");
388 level
= GetConfigValueInt(NULL
, "cf_level", 0);
389 if(level
> 0 && level
<= 6)
391 pContext
->bs2b
= calloc(1, sizeof(*pContext
->bs2b
));
392 bs2b_set_srate(pContext
->bs2b
, pContext
->Frequency
);
393 bs2b_set_level(pContext
->bs2b
, level
);
401 Clean up Context, destroy any remaining Sources
403 static ALCvoid
ExitContext(ALCcontext
*pContext
)
406 pContext
->LastError
= AL_NO_ERROR
;
407 pContext
->InUse
= AL_FALSE
;
409 free(pContext
->bs2b
);
410 pContext
->bs2b
= NULL
;
413 ///////////////////////////////////////////////////////
416 ///////////////////////////////////////////////////////
417 // ALC Functions calls
420 // This should probably move to another c file but for now ...
421 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
423 ALCboolean DeviceFound
= ALC_FALSE
;
424 ALCdevice
*pDevice
= NULL
;
429 if(deviceName
&& !deviceName
[0])
432 pDevice
= malloc(sizeof(ALCdevice
));
437 //Initialise device structure
438 memset(pDevice
, 0, sizeof(ALCdevice
));
441 pDevice
->InUse
= AL_TRUE
;
442 pDevice
->IsCaptureDevice
= AL_TRUE
;
444 pDevice
->Frequency
= frequency
;
445 pDevice
->Format
= format
;
446 pDevice
->Channels
= aluChannelsFromFormat(format
);
447 pDevice
->FrameSize
= aluBytesFromFormat(format
) *
450 for(i
= 0;BackendList
[i
].Init
;i
++)
452 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
453 if(ALCdevice_OpenCapture(pDevice
, deviceName
, frequency
, format
, SampleSize
))
455 SuspendContext(NULL
);
456 pDevice
->next
= g_pDeviceList
;
457 g_pDeviceList
= pDevice
;
459 ProcessContext(NULL
);
461 DeviceFound
= ALC_TRUE
;
467 SetALCError(ALC_INVALID_VALUE
);
476 SetALCError(ALC_OUT_OF_MEMORY
);
481 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
483 ALCboolean bReturn
= ALC_FALSE
;
486 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
488 SuspendContext(NULL
);
490 list
= &g_pDeviceList
;
491 while(*list
!= pDevice
)
492 list
= &(*list
)->next
;
494 *list
= (*list
)->next
;
497 ProcessContext(NULL
);
499 ALCdevice_CloseCapture(pDevice
);
505 SetALCError(ALC_INVALID_DEVICE
);
510 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
512 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
513 ALCdevice_StartCapture(pDevice
);
515 SetALCError(ALC_INVALID_DEVICE
);
518 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
520 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
521 ALCdevice_StopCapture(pDevice
);
523 SetALCError(ALC_INVALID_DEVICE
);
526 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
528 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
529 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
531 SetALCError(ALC_INVALID_DEVICE
);
537 Return last ALC generated error code
539 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
545 errorCode
= g_eLastContextError
;
546 g_eLastContextError
= ALC_NO_ERROR
;
556 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
558 // Not a lot happens here !
568 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
570 // Not a lot happens here !
578 Returns information about the Device, and error strings
580 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
582 const ALCchar
*value
= NULL
;
592 case ALC_INVALID_ENUM
:
593 value
= alcErrInvalidEnum
;
596 case ALC_INVALID_VALUE
:
597 value
= alcErrInvalidValue
;
600 case ALC_INVALID_DEVICE
:
601 value
= alcErrInvalidDevice
;
604 case ALC_INVALID_CONTEXT
:
605 value
= alcErrInvalidContext
;
608 case ALC_OUT_OF_MEMORY
:
609 value
= alcErrOutOfMemory
;
612 case ALC_DEFAULT_DEVICE_SPECIFIER
:
613 value
= alcDefaultDeviceSpecifier
;
616 case ALC_DEVICE_SPECIFIER
:
618 value
= pDevice
->szDeviceName
;
620 value
= alcDeviceList
;
623 case ALC_ALL_DEVICES_SPECIFIER
:
624 value
= alcAllDeviceList
;
627 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
628 value
= alcDefaultAllDeviceSpecifier
;
631 case ALC_CAPTURE_DEVICE_SPECIFIER
:
633 value
= pDevice
->szDeviceName
;
635 value
= alcCaptureDeviceList
;
638 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
639 value
= alcCaptureDefaultDeviceSpecifier
;
643 value
= alcExtensionList
;
647 SetALCError(ALC_INVALID_ENUM
);
658 Returns information about the Device and the version of Open AL
660 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
664 if ((device
)&&(device
->IsCaptureDevice
))
666 SuspendContext(NULL
);
671 case ALC_CAPTURE_SAMPLES
:
672 if ((size
) && (data
))
673 *data
= ALCdevice_AvailableSamples(device
);
675 SetALCError(ALC_INVALID_VALUE
);
679 SetALCError(ALC_INVALID_ENUM
);
683 ProcessContext(NULL
);
692 case ALC_MAJOR_VERSION
:
694 SetALCError(ALC_INVALID_VALUE
);
696 *data
= alcMajorVersion
;
699 case ALC_MINOR_VERSION
:
701 SetALCError(ALC_INVALID_VALUE
);
703 *data
= alcMinorVersion
;
706 case ALC_EFX_MAJOR_VERSION
:
708 SetALCError(ALC_INVALID_VALUE
);
710 *data
= alcEFXMajorVersion
;
713 case ALC_EFX_MINOR_VERSION
:
715 SetALCError(ALC_INVALID_VALUE
);
717 *data
= alcEFXMinorVersion
;
720 case ALC_MAX_AUXILIARY_SENDS
:
722 SetALCError(ALC_INVALID_VALUE
);
727 case ALC_ATTRIBUTES_SIZE
:
729 SetALCError(ALC_INVALID_DEVICE
);
731 SetALCError(ALC_INVALID_VALUE
);
736 case ALC_ALL_ATTRIBUTES
:
738 SetALCError(ALC_INVALID_DEVICE
);
740 SetALCError(ALC_INVALID_VALUE
);
745 data
[i
++] = ALC_FREQUENCY
;
746 data
[i
++] = device
->Frequency
;
748 data
[i
++] = ALC_REFRESH
;
749 data
[i
++] = device
->Frequency
/ device
->UpdateFreq
;
751 data
[i
++] = ALC_SYNC
;
752 data
[i
++] = ALC_FALSE
;
754 SuspendContext(NULL
);
755 if(device
->Context
&& size
>= 12)
757 data
[i
++] = ALC_MONO_SOURCES
;
758 data
[i
++] = device
->Context
->lNumMonoSources
;
760 data
[i
++] = ALC_STEREO_SOURCES
;
761 data
[i
++] = device
->Context
->lNumStereoSources
;
763 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
764 data
[i
++] = MAX_SENDS
;
766 ProcessContext(NULL
);
774 SetALCError(ALC_INVALID_DEVICE
);
776 SetALCError(ALC_INVALID_VALUE
);
778 *data
= device
->Frequency
;
783 SetALCError(ALC_INVALID_DEVICE
);
785 SetALCError(ALC_INVALID_VALUE
);
787 *data
= device
->Frequency
/ device
->UpdateFreq
;
792 SetALCError(ALC_INVALID_DEVICE
);
794 SetALCError(ALC_INVALID_VALUE
);
799 case ALC_MONO_SOURCES
:
800 if(!device
|| !device
->Context
)
801 SetALCError(ALC_INVALID_DEVICE
);
803 SetALCError(ALC_INVALID_VALUE
);
805 *data
= device
->Context
->lNumMonoSources
;
808 case ALC_STEREO_SOURCES
:
809 if(!device
|| !device
->Context
)
810 SetALCError(ALC_INVALID_DEVICE
);
812 SetALCError(ALC_INVALID_VALUE
);
814 *data
= device
->Context
->lNumStereoSources
;
818 SetALCError(ALC_INVALID_ENUM
);
823 SetALCError(ALC_INVALID_VALUE
);
831 alcIsExtensionPresent
833 Determines if there is support for a particular extension
835 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
837 ALCboolean bResult
= ALC_FALSE
;
844 while(alcExtensions
[i
].extName
&&
845 strcasecmp(alcExtensions
[i
].extName
,extName
) != 0)
848 if (alcExtensions
[i
].extName
)
852 SetALCError(ALC_INVALID_VALUE
);
861 Retrieves the function address for a particular extension function
863 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
865 ALCvoid
*pFunction
= NULL
;
872 while(alcFunctions
[i
].funcName
&&
873 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
875 pFunction
= alcFunctions
[i
].address
;
878 SetALCError(ALC_INVALID_VALUE
);
887 Get the value for a particular ALC Enumerated Value
889 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
896 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
898 val
= enumeration
[i
].value
;
900 if(!enumeration
[i
].enumName
)
901 SetALCError(ALC_INVALID_VALUE
);
910 Create and attach a Context to a particular Device.
912 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
914 ALCcontext
*ALContext
= NULL
;
915 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
917 if ((device
)&&(!device
->IsCaptureDevice
))
919 // Reset Context Last Error code
920 g_eLastContextError
= ALC_NO_ERROR
;
922 // Current implementation only allows one Context per Device
925 ALContext
= calloc(1, sizeof(ALCcontext
));
928 SetALCError(ALC_OUT_OF_MEMORY
);
932 ALContext
->Device
= device
;
933 InitContext(ALContext
);
935 device
->Context
= ALContext
;
937 SuspendContext(NULL
);
939 ALContext
->next
= g_pContextList
;
940 g_pContextList
= ALContext
;
943 ProcessContext(NULL
);
945 // Check for Voice Count attributes
948 ulAttributeIndex
= 0;
949 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
951 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
953 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
955 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
956 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
958 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
959 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
963 ulAttributeIndex
+= 2;
969 SetALCError(ALC_INVALID_VALUE
);
974 SetALCError(ALC_INVALID_DEVICE
);
985 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
990 SuspendContext(NULL
);
992 if (IsContext(context
))
995 SuspendContext(context
);
997 ReleaseALSources(context
);
998 ReleaseALAuxiliaryEffectSlots(context
);
1000 context
->Device
->Context
= NULL
;
1002 list
= &g_pContextList
;
1003 while(*list
!= context
)
1004 list
= &(*list
)->next
;
1006 *list
= (*list
)->next
;
1010 ProcessContext(context
);
1012 ExitContext(context
);
1014 // Free memory (MUST do this after ProcessContext)
1015 memset(context
, 0, sizeof(ALCcontext
));
1019 SetALCError(ALC_INVALID_CONTEXT
);
1021 ProcessContext(NULL
);
1026 alcGetCurrentContext
1028 Returns the currently active Context
1030 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1032 ALCcontext
*pContext
= NULL
;
1034 SuspendContext(NULL
);
1036 pContext
= g_pContextList
;
1037 while ((pContext
) && (!pContext
->InUse
))
1038 pContext
= pContext
->next
;
1040 ProcessContext(NULL
);
1047 alcGetContextsDevice
1049 Returns the Device that a particular Context is attached to
1051 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1053 ALCdevice
*pDevice
= NULL
;
1055 SuspendContext(NULL
);
1056 if (IsContext(pContext
))
1057 pDevice
= pContext
->Device
;
1059 SetALCError(ALC_INVALID_CONTEXT
);
1060 ProcessContext(NULL
);
1067 alcMakeContextCurrent
1069 Makes the given Context the active Context
1071 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1073 ALCcontext
*ALContext
;
1074 ALboolean bReturn
= AL_TRUE
;
1076 SuspendContext(NULL
);
1078 // context must be a valid Context or NULL
1079 if ((IsContext(context
)) || (context
== NULL
))
1081 if ((ALContext
=alcGetCurrentContext()))
1083 SuspendContext(ALContext
);
1084 ALContext
->InUse
=AL_FALSE
;
1085 ProcessContext(ALContext
);
1088 if ((ALContext
=context
) && (ALContext
->Device
))
1090 SuspendContext(ALContext
);
1091 ALContext
->InUse
=AL_TRUE
;
1092 ProcessContext(ALContext
);
1097 SetALCError(ALC_INVALID_CONTEXT
);
1101 ProcessContext(NULL
);
1110 Open the Device specified.
1112 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1114 ALboolean bDeviceFound
= AL_FALSE
;
1120 if(deviceName
&& !deviceName
[0])
1123 device
= malloc(sizeof(ALCdevice
));
1128 //Initialise device structure
1129 memset(device
, 0, sizeof(ALCdevice
));
1132 device
->InUse
= AL_TRUE
;
1133 device
->IsCaptureDevice
= AL_FALSE
;
1136 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1137 if((ALint
)device
->Frequency
<= 0)
1138 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1140 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1142 device
->Format
= alGetEnumValue(fmt
);
1144 device
->Channels
= aluChannelsFromFormat(device
->Format
);
1145 if(!device
->Channels
)
1147 device
->Format
= AL_FORMAT_STEREO16
;
1148 device
->Channels
= 2;
1149 device
->FrameSize
= 4;
1152 device
->FrameSize
= aluBytesFromFormat(device
->Format
) *
1155 device
->UpdateFreq
= GetConfigValueInt(NULL
, "refresh", 8192);
1156 if((ALint
)device
->UpdateFreq
<= 0)
1157 device
->UpdateFreq
= 8192;
1159 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1160 if((ALint
)device
->MaxNoOfSources
<= 0)
1161 device
->MaxNoOfSources
= 256;
1163 // Find a playback device to open
1164 for(i
= 0;BackendList
[i
].Init
;i
++)
1166 device
->Funcs
= &BackendList
[i
].Funcs
;
1167 if(ALCdevice_OpenPlayback(device
, deviceName
))
1169 SuspendContext(NULL
);
1170 device
->next
= g_pDeviceList
;
1171 g_pDeviceList
= device
;
1173 ProcessContext(NULL
);
1175 bDeviceFound
= AL_TRUE
;
1182 // No suitable output device found
1195 Close the specified Device
1197 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1199 ALCboolean bReturn
= ALC_FALSE
;
1202 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1204 SuspendContext(NULL
);
1206 list
= &g_pDeviceList
;
1207 while(*list
!= pDevice
)
1208 list
= &(*list
)->next
;
1210 *list
= (*list
)->next
;
1213 ProcessContext(NULL
);
1215 if(pDevice
->Context
)
1216 alcDestroyContext(pDevice
->Context
);
1217 ALCdevice_ClosePlayback(pDevice
);
1219 //Release device structure
1220 memset(pDevice
, 0, sizeof(ALCdevice
));
1226 SetALCError(ALC_INVALID_DEVICE
);
1232 ALCvoid
ReleaseALC(ALCvoid
)
1237 if(g_ulContextCount
> 0)
1238 AL_PRINT("exit() %u device(s) and %u context(s) NOT deleted\n", g_ulDeviceCount
, g_ulContextCount
);
1241 while(g_pDeviceList
)
1243 Dev
= g_pDeviceList
;
1244 g_pDeviceList
= g_pDeviceList
->next
;
1245 if(Dev
->IsCaptureDevice
)
1246 alcCaptureCloseDevice(Dev
);
1248 alcCloseDevice(Dev
);
1252 ///////////////////////////////////////////////////////