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
33 ///////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////
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 { "dsound", alcDSoundInit
, EmptyFuncs
},
57 { "winmm", alcWinMMInit
, EmptyFuncs
},
60 { NULL
, NULL
, EmptyFuncs
}
64 ///////////////////////////////////////////////////////
67 ///////////////////////////////////////////////////////
68 // STRING and EXTENSIONS
70 typedef struct ALCextension_struct
76 typedef struct ALCfunction_struct
82 static ALCextension alcExtensions
[] = {
83 { "ALC_ENUMERATE_ALL_EXT", (ALvoid
*) NULL
},
84 { "ALC_ENUMERATION_EXT", (ALvoid
*) NULL
},
85 { "ALC_EXT_CAPTURE", (ALvoid
*) NULL
},
86 { NULL
, (ALvoid
*) NULL
}
89 static ALCfunction alcFunctions
[] = {
90 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
91 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
92 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
93 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
94 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
95 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
96 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
97 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
98 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
99 { "alcGetError", (ALvoid
*) alcGetError
},
100 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
101 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
102 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
103 { "alcGetString", (ALvoid
*) alcGetString
},
104 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
105 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
106 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
107 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
108 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
109 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
110 { NULL
, (ALvoid
*) NULL
}
113 static ALenums enumeration
[]={
115 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
116 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
117 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
120 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
121 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
122 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
123 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
124 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
125 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
126 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
127 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
128 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
129 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
130 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
131 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
132 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
133 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
134 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
135 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
136 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
139 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
140 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
141 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
142 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
143 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
144 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
145 { (ALchar
*)NULL
, (ALenum
)0 }
148 static const ALCchar alcNoError
[] = "No Error";
149 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
150 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
151 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
152 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
153 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
156 static ALCchar alcDeviceList
[2048];
157 static ALCchar alcAllDeviceList
[2048];
158 static ALCchar alcCaptureDeviceList
[2048];
159 // Default is always the first in the list
160 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
161 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
162 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
165 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE";
166 static ALCint alcMajorVersion
= 1;
167 static ALCint alcMinorVersion
= 1;
169 ///////////////////////////////////////////////////////
172 ///////////////////////////////////////////////////////
176 static ALCcontext
*g_pContextList
= NULL
;
177 static ALCuint g_ulContextCount
= 0;
180 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
182 ///////////////////////////////////////////////////////
185 ///////////////////////////////////////////////////////
186 // ALC Related helper functions
188 static void InitAL(void)
196 InitializeCriticalSection(&_alMutex
);
200 devs
= GetConfigValue(NULL
, "drivers", "");
205 const char *next
= devs
;
211 next
= strchr(devs
, ',');
213 if(!devs
[0] || devs
[0] == ',')
216 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
217 for(n
= i
;BackendList
[n
].Init
;n
++)
219 if(len
== strlen(BackendList
[n
].name
) &&
220 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
222 const char *name
= BackendList
[i
].name
;
223 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
225 BackendList
[i
].name
= BackendList
[n
].name
;
226 BackendList
[i
].Init
= BackendList
[n
].Init
;
228 BackendList
[n
].name
= name
;
229 BackendList
[n
].Init
= Init
;
236 BackendList
[i
].name
= NULL
;
237 BackendList
[i
].Init
= NULL
;
240 for(i
= 0;BackendList
[i
].Init
;i
++)
241 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
246 ALCchar
*AppendDeviceList(char *name
)
249 ALCchar
*ret
= alcDeviceList
+pos
;
250 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
, "%s", name
) + 1;
254 ALCchar
*AppendAllDeviceList(char *name
)
257 ALCchar
*ret
= alcAllDeviceList
+pos
;
258 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
, "%s", name
) + 1;
262 ALCchar
*AppendCaptureDeviceList(char *name
)
265 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
266 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
, "%s", name
) + 1;
273 Check pContext is a valid Context pointer
275 static ALCboolean
IsContext(ALCcontext
*pContext
)
277 ALCcontext
*pTempContext
;
279 pTempContext
= g_pContextList
;
280 while (pTempContext
&& pTempContext
!= pContext
)
281 pTempContext
= pTempContext
->next
;
283 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
290 Store latest ALC Error
292 ALCvoid
SetALCError(ALenum errorCode
)
294 g_eLastContextError
= errorCode
;
303 ALCvoid
SuspendContext(ALCcontext
*pContext
)
306 EnterCriticalSection(&_alMutex
);
315 ALCvoid
ProcessContext(ALCcontext
*pContext
)
318 LeaveCriticalSection(&_alMutex
);
325 Initialize Context variables
327 static ALvoid
InitContext(ALCcontext
*pContext
)
329 //Initialise listener
330 pContext
->Listener
.Gain
= 1.0f
;
331 pContext
->Listener
.Position
[0] = 0.0f
;
332 pContext
->Listener
.Position
[1] = 0.0f
;
333 pContext
->Listener
.Position
[2] = 0.0f
;
334 pContext
->Listener
.Velocity
[0] = 0.0f
;
335 pContext
->Listener
.Velocity
[1] = 0.0f
;
336 pContext
->Listener
.Velocity
[2] = 0.0f
;
337 pContext
->Listener
.Forward
[0] = 0.0f
;
338 pContext
->Listener
.Forward
[1] = 0.0f
;
339 pContext
->Listener
.Forward
[2] = -1.0f
;
340 pContext
->Listener
.Up
[0] = 0.0f
;
341 pContext
->Listener
.Up
[1] = 1.0f
;
342 pContext
->Listener
.Up
[2] = 0.0f
;
345 pContext
->LastError
= AL_NO_ERROR
;
346 pContext
->InUse
= AL_FALSE
;
349 pContext
->Frequency
= pContext
->Device
->Frequency
;
352 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
353 pContext
->DopplerFactor
= 1.0f
;
354 pContext
->DopplerVelocity
= 1.0f
;
355 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
357 pContext
->lNumStereoSources
= 1;
358 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
360 strcpy(pContext
->ExtensionList
, "AL_EXT_EXPONENT_DISTANCE AL_EXT_LINEAR_DISTANCE AL_EXT_OFFSET");
367 Clean up Context, destroy any remaining Sources
369 static ALCvoid
ExitContext(ALCcontext
*pContext
)
373 ALsource
*ALTempSource
;
376 if (pContext
->SourceCount
>0)
377 AL_PRINT("alcDestroyContext() %d Source(s) NOT deleted\n", pContext
->SourceCount
);
380 // Free all the Sources still remaining
381 ALSource
= pContext
->Source
;
382 for (i
= 0; i
< pContext
->SourceCount
; i
++)
384 ALTempSource
= ALSource
->next
;
385 ALTHUNK_REMOVEENTRY(ALSource
->source
);
386 memset(ALSource
, 0, sizeof(ALsource
));
388 ALSource
= ALTempSource
;
392 pContext
->LastError
= AL_NO_ERROR
;
393 pContext
->InUse
= AL_FALSE
;
396 ///////////////////////////////////////////////////////
399 ///////////////////////////////////////////////////////
400 // ALC Functions calls
403 // This should probably move to another c file but for now ...
404 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
406 ALCboolean DeviceFound
= ALC_FALSE
;
407 ALCdevice
*pDevice
= NULL
;
412 if(deviceName
&& !deviceName
[0])
415 pDevice
= malloc(sizeof(ALCdevice
));
420 //Initialise device structure
421 memset(pDevice
, 0, sizeof(ALCdevice
));
424 pDevice
->InUse
= AL_TRUE
;
425 pDevice
->IsCaptureDevice
= AL_TRUE
;
427 pDevice
->Frequency
= frequency
;
428 pDevice
->Format
= format
;
429 pDevice
->Channels
= aluChannelsFromFormat(format
);
430 pDevice
->FrameSize
= aluBytesFromFormat(format
) *
433 for(i
= 0;BackendList
[i
].Init
;i
++)
435 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
436 if(ALCdevice_OpenCapture(pDevice
, deviceName
, frequency
, format
, SampleSize
))
438 DeviceFound
= ALC_TRUE
;
444 SetALCError(ALC_INVALID_VALUE
);
453 SetALCError(ALC_OUT_OF_MEMORY
);
458 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
460 ALCboolean bReturn
= ALC_FALSE
;
462 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
464 ALCdevice_CloseCapture(pDevice
);
470 SetALCError(ALC_INVALID_DEVICE
);
475 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
477 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
478 ALCdevice_StartCapture(pDevice
);
480 SetALCError(ALC_INVALID_DEVICE
);
483 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
485 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
486 ALCdevice_StopCapture(pDevice
);
488 SetALCError(ALC_INVALID_DEVICE
);
491 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
493 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
494 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
496 SetALCError(ALC_INVALID_DEVICE
);
502 Return last ALC generated error code
504 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
510 errorCode
= g_eLastContextError
;
511 g_eLastContextError
= ALC_NO_ERROR
;
521 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
523 // Not a lot happens here !
533 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
535 // Not a lot happens here !
543 Returns information about the Device, and error strings
545 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
547 const ALCchar
*value
= NULL
;
557 case ALC_INVALID_ENUM
:
558 value
= alcErrInvalidEnum
;
561 case ALC_INVALID_VALUE
:
562 value
= alcErrInvalidValue
;
565 case ALC_INVALID_DEVICE
:
566 value
= alcErrInvalidDevice
;
569 case ALC_INVALID_CONTEXT
:
570 value
= alcErrInvalidContext
;
573 case ALC_OUT_OF_MEMORY
:
574 value
= alcErrOutOfMemory
;
577 case ALC_DEFAULT_DEVICE_SPECIFIER
:
578 value
= alcDefaultDeviceSpecifier
;
581 case ALC_DEVICE_SPECIFIER
:
583 value
= pDevice
->szDeviceName
;
585 value
= alcDeviceList
;
588 case ALC_ALL_DEVICES_SPECIFIER
:
589 value
= alcAllDeviceList
;
592 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
593 value
= alcDefaultAllDeviceSpecifier
;
596 case ALC_CAPTURE_DEVICE_SPECIFIER
:
598 value
= pDevice
->szDeviceName
;
600 value
= alcCaptureDeviceList
;
603 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
604 value
= alcCaptureDefaultDeviceSpecifier
;
608 value
= alcExtensionList
;
612 SetALCError(ALC_INVALID_ENUM
);
623 Returns information about the Device and the version of Open AL
625 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
629 if ((device
)&&(device
->IsCaptureDevice
))
631 SuspendContext(NULL
);
636 case ALC_CAPTURE_SAMPLES
:
637 if ((size
) && (data
))
638 *data
= ALCdevice_AvailableSamples(device
);
640 SetALCError(ALC_INVALID_VALUE
);
644 SetALCError(ALC_INVALID_ENUM
);
648 ProcessContext(NULL
);
657 case ALC_MAJOR_VERSION
:
659 SetALCError(ALC_INVALID_VALUE
);
661 *data
= alcMajorVersion
;
664 case ALC_MINOR_VERSION
:
666 SetALCError(ALC_INVALID_VALUE
);
668 *data
= alcMinorVersion
;
671 case ALC_ATTRIBUTES_SIZE
:
673 SetALCError(ALC_INVALID_DEVICE
);
675 SetALCError(ALC_INVALID_VALUE
);
680 case ALC_ALL_ATTRIBUTES
:
682 SetALCError(ALC_INVALID_DEVICE
);
684 SetALCError(ALC_INVALID_VALUE
);
689 data
[i
++] = ALC_FREQUENCY
;
690 data
[i
++] = device
->Frequency
;
692 data
[i
++] = ALC_REFRESH
;
693 data
[i
++] = device
->UpdateFreq
;
695 data
[i
++] = ALC_SYNC
;
696 data
[i
++] = ALC_FALSE
;
698 SuspendContext(NULL
);
699 if(device
->Context
&& size
>= 11)
701 data
[i
++] = ALC_MONO_SOURCES
;
702 data
[i
++] = device
->Context
->lNumMonoSources
;
704 data
[i
++] = ALC_STEREO_SOURCES
;
705 data
[i
++] = device
->Context
->lNumStereoSources
;
707 ProcessContext(NULL
);
715 SetALCError(ALC_INVALID_DEVICE
);
717 SetALCError(ALC_INVALID_VALUE
);
719 *data
= device
->Frequency
;
724 SetALCError(ALC_INVALID_DEVICE
);
726 SetALCError(ALC_INVALID_VALUE
);
728 *data
= device
->UpdateFreq
;
733 SetALCError(ALC_INVALID_DEVICE
);
735 SetALCError(ALC_INVALID_VALUE
);
741 SetALCError(ALC_INVALID_ENUM
);
746 SetALCError(ALC_INVALID_VALUE
);
754 alcIsExtensionPresent
756 Determines if there is support for a particular extension
758 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
760 ALCboolean bResult
= ALC_FALSE
;
767 while(alcExtensions
[i
].extName
&&
768 strcasecmp(alcExtensions
[i
].extName
,extName
) != 0)
771 if (alcExtensions
[i
].extName
)
775 SetALCError(ALC_INVALID_VALUE
);
784 Retrieves the function address for a particular extension function
786 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
788 ALCvoid
*pFunction
= NULL
;
795 while(alcFunctions
[i
].funcName
&&
796 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
798 pFunction
= alcFunctions
[i
].address
;
801 SetALCError(ALC_INVALID_VALUE
);
810 Get the value for a particular ALC Enumerated Value
812 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
819 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
821 val
= enumeration
[i
].value
;
823 if(!enumeration
[i
].enumName
)
824 SetALCError(ALC_INVALID_VALUE
);
833 Create and attach a Context to a particular Device.
835 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
837 ALCcontext
*ALContext
= NULL
;
838 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
840 if ((device
)&&(!device
->IsCaptureDevice
))
842 // Reset Context Last Error code
843 g_eLastContextError
= ALC_NO_ERROR
;
845 // Current implementation only allows one Context per Device
848 ALContext
= calloc(1, sizeof(ALCcontext
));
851 SetALCError(ALC_OUT_OF_MEMORY
);
855 ALContext
->Device
= device
;
856 InitContext(ALContext
);
858 device
->Context
= ALContext
;
860 SuspendContext(NULL
);
862 ALContext
->next
= g_pContextList
;
863 g_pContextList
= ALContext
;
866 ProcessContext(NULL
);
868 // Check for Voice Count attributes
871 ulAttributeIndex
= 0;
872 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
874 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
876 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
878 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
879 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
881 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
882 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
886 ulAttributeIndex
+= 2;
892 SetALCError(ALC_INVALID_VALUE
);
897 SetALCError(ALC_INVALID_DEVICE
);
908 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
913 SuspendContext(NULL
);
915 if (IsContext(context
))
918 SuspendContext(context
);
920 context
->Device
->Context
= NULL
;
922 list
= &g_pContextList
;
923 while(*list
!= context
)
924 list
= &(*list
)->next
;
926 *list
= (*list
)->next
;
930 ProcessContext(context
);
932 ExitContext(context
);
934 // Free memory (MUST do this after ProcessContext)
935 memset(context
, 0, sizeof(ALCcontext
));
939 SetALCError(ALC_INVALID_CONTEXT
);
941 ProcessContext(NULL
);
948 Returns the currently active Context
950 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
952 ALCcontext
*pContext
= NULL
;
954 SuspendContext(NULL
);
956 pContext
= g_pContextList
;
957 while ((pContext
) && (!pContext
->InUse
))
958 pContext
= pContext
->next
;
960 ProcessContext(NULL
);
969 Returns the Device that a particular Context is attached to
971 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
973 ALCdevice
*pDevice
= NULL
;
975 SuspendContext(NULL
);
976 if (IsContext(pContext
))
977 pDevice
= pContext
->Device
;
979 SetALCError(ALC_INVALID_CONTEXT
);
980 ProcessContext(NULL
);
987 alcMakeContextCurrent
989 Makes the given Context the active Context
991 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
993 ALCcontext
*ALContext
;
994 ALboolean bReturn
= AL_TRUE
;
996 SuspendContext(NULL
);
998 // context must be a valid Context or NULL
999 if ((IsContext(context
)) || (context
== NULL
))
1001 if ((ALContext
=alcGetCurrentContext()))
1003 SuspendContext(ALContext
);
1004 ALContext
->InUse
=AL_FALSE
;
1005 ProcessContext(ALContext
);
1008 if ((ALContext
=context
) && (ALContext
->Device
))
1010 SuspendContext(ALContext
);
1011 ALContext
->InUse
=AL_TRUE
;
1012 ProcessContext(ALContext
);
1017 SetALCError(ALC_INVALID_CONTEXT
);
1021 ProcessContext(NULL
);
1030 Open the Device specified.
1032 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1034 ALboolean bDeviceFound
= AL_FALSE
;
1040 if(deviceName
&& !deviceName
[0])
1043 device
= malloc(sizeof(ALCdevice
));
1048 //Initialise device structure
1049 memset(device
, 0, sizeof(ALCdevice
));
1052 device
->InUse
= AL_TRUE
;
1053 device
->IsCaptureDevice
= AL_FALSE
;
1056 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1057 if((ALint
)device
->Frequency
<= 0)
1058 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1060 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1062 device
->Format
= alGetEnumValue(fmt
);
1064 device
->Channels
= aluChannelsFromFormat(device
->Format
);
1065 if(!device
->Channels
)
1067 device
->Format
= AL_FORMAT_STEREO16
;
1068 device
->Channels
= 2;
1069 device
->FrameSize
= 4;
1072 device
->FrameSize
= aluBytesFromFormat(device
->Format
) *
1075 device
->UpdateFreq
= GetConfigValueInt(NULL
, "refresh", 0);
1076 if((ALint
)device
->UpdateFreq
<= 0)
1077 device
->UpdateFreq
= 8192 * device
->Frequency
/ 22050;
1079 // Find a playback device to open
1080 for(i
= 0;BackendList
[i
].Init
;i
++)
1082 device
->Funcs
= &BackendList
[i
].Funcs
;
1083 if(ALCdevice_OpenPlayback(device
, deviceName
))
1085 bDeviceFound
= AL_TRUE
;
1092 // No suitable output device found
1105 Close the specified Device
1107 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1109 ALCboolean bReturn
= ALC_FALSE
;
1111 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1113 ALCdevice_ClosePlayback(pDevice
);
1115 //Release device structure
1116 memset(pDevice
, 0, sizeof(ALCdevice
));
1122 SetALCError(ALC_INVALID_DEVICE
);
1126 ///////////////////////////////////////////////////////