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
34 #include "alExtension.h"
37 ///////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////
45 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
48 void (*Init
)(BackendFuncs
*);
52 { "alsa", alc_alsa_init
, EmptyFuncs
},
55 { "oss", alc_oss_init
, EmptyFuncs
},
58 { "dsound", alcDSoundInit
, EmptyFuncs
},
61 { "winmm", alcWinMMInit
, EmptyFuncs
},
64 { NULL
, NULL
, EmptyFuncs
}
68 ///////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////
72 // STRING and EXTENSIONS
74 typedef struct ALCextension_struct
80 typedef struct ALCfunction_struct
86 static ALCextension alcExtensions
[] = {
87 { "ALC_ENUMERATE_ALL_EXT", (ALvoid
*) NULL
},
88 { "ALC_ENUMERATION_EXT", (ALvoid
*) NULL
},
89 { "ALC_EXT_CAPTURE", (ALvoid
*) NULL
},
90 { NULL
, (ALvoid
*) NULL
}
93 static ALCfunction alcFunctions
[] = {
94 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
95 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
96 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
97 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
98 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
99 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
100 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
101 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
102 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
103 { "alcGetError", (ALvoid
*) alcGetError
},
104 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
105 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
106 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
107 { "alcGetString", (ALvoid
*) alcGetString
},
108 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
109 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
110 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
111 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
112 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
113 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
114 { NULL
, (ALvoid
*) NULL
}
117 static ALenums enumeration
[]={
119 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
120 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
121 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
124 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
125 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
126 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
127 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
128 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
129 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
130 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
131 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
132 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
133 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
134 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
135 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
136 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
137 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
138 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
139 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
140 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
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";
170 static ALCint alcMajorVersion
= 1;
171 static ALCint alcMinorVersion
= 1;
173 ///////////////////////////////////////////////////////
176 ///////////////////////////////////////////////////////
180 static ALCcontext
*g_pContextList
= NULL
;
181 static ALCuint g_ulContextCount
= 0;
184 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
186 ///////////////////////////////////////////////////////
189 ///////////////////////////////////////////////////////
190 // ALC Related helper functions
192 static void InitAL(void)
200 InitializeCriticalSection(&_alMutex
);
204 devs
= GetConfigValue(NULL
, "drivers", "");
209 const char *next
= devs
;
215 next
= strchr(devs
, ',');
217 if(!devs
[0] || devs
[0] == ',')
220 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
221 for(n
= i
;BackendList
[n
].Init
;n
++)
223 if(len
== strlen(BackendList
[n
].name
) &&
224 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
226 const char *name
= BackendList
[i
].name
;
227 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
229 BackendList
[i
].name
= BackendList
[n
].name
;
230 BackendList
[i
].Init
= BackendList
[n
].Init
;
232 BackendList
[n
].name
= name
;
233 BackendList
[n
].Init
= Init
;
240 BackendList
[i
].name
= NULL
;
241 BackendList
[i
].Init
= NULL
;
244 for(i
= 0;BackendList
[i
].Init
;i
++)
245 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
250 ALCchar
*AppendDeviceList(char *name
)
253 ALCchar
*ret
= alcDeviceList
+pos
;
254 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
, "%s", name
) + 1;
258 ALCchar
*AppendAllDeviceList(char *name
)
261 ALCchar
*ret
= alcAllDeviceList
+pos
;
262 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
, "%s", name
) + 1;
266 ALCchar
*AppendCaptureDeviceList(char *name
)
269 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
270 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
, "%s", name
) + 1;
277 Check pContext is a valid Context pointer
279 static ALCboolean
IsContext(ALCcontext
*pContext
)
281 ALCcontext
*pTempContext
;
283 pTempContext
= g_pContextList
;
284 while (pTempContext
&& pTempContext
!= pContext
)
285 pTempContext
= pTempContext
->next
;
287 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
294 Store latest ALC Error
296 ALCvoid
SetALCError(ALenum errorCode
)
298 g_eLastContextError
= errorCode
;
307 ALCvoid
SuspendContext(ALCcontext
*pContext
)
310 EnterCriticalSection(&_alMutex
);
319 ALCvoid
ProcessContext(ALCcontext
*pContext
)
322 LeaveCriticalSection(&_alMutex
);
329 Initialize Context variables
331 static ALvoid
InitContext(ALCcontext
*pContext
)
335 //Initialise listener
336 pContext
->Listener
.Gain
= 1.0f
;
337 pContext
->Listener
.Position
[0] = 0.0f
;
338 pContext
->Listener
.Position
[1] = 0.0f
;
339 pContext
->Listener
.Position
[2] = 0.0f
;
340 pContext
->Listener
.Velocity
[0] = 0.0f
;
341 pContext
->Listener
.Velocity
[1] = 0.0f
;
342 pContext
->Listener
.Velocity
[2] = 0.0f
;
343 pContext
->Listener
.Forward
[0] = 0.0f
;
344 pContext
->Listener
.Forward
[1] = 0.0f
;
345 pContext
->Listener
.Forward
[2] = -1.0f
;
346 pContext
->Listener
.Up
[0] = 0.0f
;
347 pContext
->Listener
.Up
[1] = 1.0f
;
348 pContext
->Listener
.Up
[2] = 0.0f
;
351 pContext
->LastError
= AL_NO_ERROR
;
352 pContext
->InUse
= AL_FALSE
;
355 pContext
->Frequency
= pContext
->Device
->Frequency
;
358 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
359 pContext
->DopplerFactor
= 1.0f
;
360 pContext
->DopplerVelocity
= 1.0f
;
361 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
363 pContext
->lNumStereoSources
= 1;
364 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
366 strcpy(pContext
->ExtensionList
, "AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET");
368 level
= GetConfigValueInt(NULL
, "cf_level", 0);
369 if(level
> 0 && level
<= 6)
371 pContext
->bs2b
= calloc(1, sizeof(*pContext
->bs2b
));
372 bs2b_set_srate(pContext
->bs2b
, pContext
->Frequency
);
373 bs2b_set_level(pContext
->bs2b
, level
);
381 Clean up Context, destroy any remaining Sources
383 static ALCvoid
ExitContext(ALCcontext
*pContext
)
387 ALsource
*ALTempSource
;
390 if (pContext
->SourceCount
>0)
391 AL_PRINT("alcDestroyContext() %d Source(s) NOT deleted\n", pContext
->SourceCount
);
394 // Free all the Sources still remaining
395 ALSource
= pContext
->Source
;
396 for (i
= 0; i
< pContext
->SourceCount
; i
++)
398 ALTempSource
= ALSource
->next
;
399 ALTHUNK_REMOVEENTRY(ALSource
->source
);
400 memset(ALSource
, 0, sizeof(ALsource
));
402 ALSource
= ALTempSource
;
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 DeviceFound
= ALC_TRUE
;
461 SetALCError(ALC_INVALID_VALUE
);
470 SetALCError(ALC_OUT_OF_MEMORY
);
475 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
477 ALCboolean bReturn
= ALC_FALSE
;
479 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
481 ALCdevice_CloseCapture(pDevice
);
487 SetALCError(ALC_INVALID_DEVICE
);
492 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
494 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
495 ALCdevice_StartCapture(pDevice
);
497 SetALCError(ALC_INVALID_DEVICE
);
500 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
502 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
503 ALCdevice_StopCapture(pDevice
);
505 SetALCError(ALC_INVALID_DEVICE
);
508 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
510 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
511 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
513 SetALCError(ALC_INVALID_DEVICE
);
519 Return last ALC generated error code
521 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
527 errorCode
= g_eLastContextError
;
528 g_eLastContextError
= ALC_NO_ERROR
;
538 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
540 // Not a lot happens here !
550 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
552 // Not a lot happens here !
560 Returns information about the Device, and error strings
562 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
564 const ALCchar
*value
= NULL
;
574 case ALC_INVALID_ENUM
:
575 value
= alcErrInvalidEnum
;
578 case ALC_INVALID_VALUE
:
579 value
= alcErrInvalidValue
;
582 case ALC_INVALID_DEVICE
:
583 value
= alcErrInvalidDevice
;
586 case ALC_INVALID_CONTEXT
:
587 value
= alcErrInvalidContext
;
590 case ALC_OUT_OF_MEMORY
:
591 value
= alcErrOutOfMemory
;
594 case ALC_DEFAULT_DEVICE_SPECIFIER
:
595 value
= alcDefaultDeviceSpecifier
;
598 case ALC_DEVICE_SPECIFIER
:
600 value
= pDevice
->szDeviceName
;
602 value
= alcDeviceList
;
605 case ALC_ALL_DEVICES_SPECIFIER
:
606 value
= alcAllDeviceList
;
609 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
610 value
= alcDefaultAllDeviceSpecifier
;
613 case ALC_CAPTURE_DEVICE_SPECIFIER
:
615 value
= pDevice
->szDeviceName
;
617 value
= alcCaptureDeviceList
;
620 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
621 value
= alcCaptureDefaultDeviceSpecifier
;
625 value
= alcExtensionList
;
629 SetALCError(ALC_INVALID_ENUM
);
640 Returns information about the Device and the version of Open AL
642 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
646 if ((device
)&&(device
->IsCaptureDevice
))
648 SuspendContext(NULL
);
653 case ALC_CAPTURE_SAMPLES
:
654 if ((size
) && (data
))
655 *data
= ALCdevice_AvailableSamples(device
);
657 SetALCError(ALC_INVALID_VALUE
);
661 SetALCError(ALC_INVALID_ENUM
);
665 ProcessContext(NULL
);
674 case ALC_MAJOR_VERSION
:
676 SetALCError(ALC_INVALID_VALUE
);
678 *data
= alcMajorVersion
;
681 case ALC_MINOR_VERSION
:
683 SetALCError(ALC_INVALID_VALUE
);
685 *data
= alcMinorVersion
;
688 case ALC_ATTRIBUTES_SIZE
:
690 SetALCError(ALC_INVALID_DEVICE
);
692 SetALCError(ALC_INVALID_VALUE
);
697 case ALC_ALL_ATTRIBUTES
:
699 SetALCError(ALC_INVALID_DEVICE
);
701 SetALCError(ALC_INVALID_VALUE
);
706 data
[i
++] = ALC_FREQUENCY
;
707 data
[i
++] = device
->Frequency
;
709 data
[i
++] = ALC_REFRESH
;
710 data
[i
++] = device
->Frequency
/ device
->UpdateFreq
;
712 data
[i
++] = ALC_SYNC
;
713 data
[i
++] = ALC_FALSE
;
715 SuspendContext(NULL
);
716 if(device
->Context
&& size
>= 11)
718 data
[i
++] = ALC_MONO_SOURCES
;
719 data
[i
++] = device
->Context
->lNumMonoSources
;
721 data
[i
++] = ALC_STEREO_SOURCES
;
722 data
[i
++] = device
->Context
->lNumStereoSources
;
724 ProcessContext(NULL
);
732 SetALCError(ALC_INVALID_DEVICE
);
734 SetALCError(ALC_INVALID_VALUE
);
736 *data
= device
->Frequency
;
741 SetALCError(ALC_INVALID_DEVICE
);
743 SetALCError(ALC_INVALID_VALUE
);
745 *data
= device
->Frequency
/ device
->UpdateFreq
;
750 SetALCError(ALC_INVALID_DEVICE
);
752 SetALCError(ALC_INVALID_VALUE
);
758 SetALCError(ALC_INVALID_ENUM
);
763 SetALCError(ALC_INVALID_VALUE
);
771 alcIsExtensionPresent
773 Determines if there is support for a particular extension
775 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
777 ALCboolean bResult
= ALC_FALSE
;
784 while(alcExtensions
[i
].extName
&&
785 strcasecmp(alcExtensions
[i
].extName
,extName
) != 0)
788 if (alcExtensions
[i
].extName
)
792 SetALCError(ALC_INVALID_VALUE
);
801 Retrieves the function address for a particular extension function
803 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
805 ALCvoid
*pFunction
= NULL
;
812 while(alcFunctions
[i
].funcName
&&
813 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
815 pFunction
= alcFunctions
[i
].address
;
818 SetALCError(ALC_INVALID_VALUE
);
827 Get the value for a particular ALC Enumerated Value
829 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
836 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
838 val
= enumeration
[i
].value
;
840 if(!enumeration
[i
].enumName
)
841 SetALCError(ALC_INVALID_VALUE
);
850 Create and attach a Context to a particular Device.
852 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
854 ALCcontext
*ALContext
= NULL
;
855 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
857 if ((device
)&&(!device
->IsCaptureDevice
))
859 // Reset Context Last Error code
860 g_eLastContextError
= ALC_NO_ERROR
;
862 // Current implementation only allows one Context per Device
865 ALContext
= calloc(1, sizeof(ALCcontext
));
868 SetALCError(ALC_OUT_OF_MEMORY
);
872 ALContext
->Device
= device
;
873 InitContext(ALContext
);
875 device
->Context
= ALContext
;
877 SuspendContext(NULL
);
879 ALContext
->next
= g_pContextList
;
880 g_pContextList
= ALContext
;
883 ProcessContext(NULL
);
885 // Check for Voice Count attributes
888 ulAttributeIndex
= 0;
889 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
891 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
893 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
895 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
896 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
898 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
899 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
903 ulAttributeIndex
+= 2;
909 SetALCError(ALC_INVALID_VALUE
);
914 SetALCError(ALC_INVALID_DEVICE
);
925 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
930 SuspendContext(NULL
);
932 if (IsContext(context
))
935 SuspendContext(context
);
937 context
->Device
->Context
= NULL
;
939 list
= &g_pContextList
;
940 while(*list
!= context
)
941 list
= &(*list
)->next
;
943 *list
= (*list
)->next
;
947 ProcessContext(context
);
949 ExitContext(context
);
951 // Free memory (MUST do this after ProcessContext)
952 memset(context
, 0, sizeof(ALCcontext
));
956 SetALCError(ALC_INVALID_CONTEXT
);
958 ProcessContext(NULL
);
965 Returns the currently active Context
967 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
969 ALCcontext
*pContext
= NULL
;
971 SuspendContext(NULL
);
973 pContext
= g_pContextList
;
974 while ((pContext
) && (!pContext
->InUse
))
975 pContext
= pContext
->next
;
977 ProcessContext(NULL
);
986 Returns the Device that a particular Context is attached to
988 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
990 ALCdevice
*pDevice
= NULL
;
992 SuspendContext(NULL
);
993 if (IsContext(pContext
))
994 pDevice
= pContext
->Device
;
996 SetALCError(ALC_INVALID_CONTEXT
);
997 ProcessContext(NULL
);
1004 alcMakeContextCurrent
1006 Makes the given Context the active Context
1008 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1010 ALCcontext
*ALContext
;
1011 ALboolean bReturn
= AL_TRUE
;
1013 SuspendContext(NULL
);
1015 // context must be a valid Context or NULL
1016 if ((IsContext(context
)) || (context
== NULL
))
1018 if ((ALContext
=alcGetCurrentContext()))
1020 SuspendContext(ALContext
);
1021 ALContext
->InUse
=AL_FALSE
;
1022 ProcessContext(ALContext
);
1025 if ((ALContext
=context
) && (ALContext
->Device
))
1027 SuspendContext(ALContext
);
1028 ALContext
->InUse
=AL_TRUE
;
1029 ProcessContext(ALContext
);
1034 SetALCError(ALC_INVALID_CONTEXT
);
1038 ProcessContext(NULL
);
1047 Open the Device specified.
1049 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1051 ALboolean bDeviceFound
= AL_FALSE
;
1057 if(deviceName
&& !deviceName
[0])
1060 device
= malloc(sizeof(ALCdevice
));
1065 //Initialise device structure
1066 memset(device
, 0, sizeof(ALCdevice
));
1069 device
->InUse
= AL_TRUE
;
1070 device
->IsCaptureDevice
= AL_FALSE
;
1073 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1074 if((ALint
)device
->Frequency
<= 0)
1075 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1077 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1079 device
->Format
= alGetEnumValue(fmt
);
1081 device
->Channels
= aluChannelsFromFormat(device
->Format
);
1082 if(!device
->Channels
)
1084 device
->Format
= AL_FORMAT_STEREO16
;
1085 device
->Channels
= 2;
1086 device
->FrameSize
= 4;
1089 device
->FrameSize
= aluBytesFromFormat(device
->Format
) *
1092 device
->UpdateFreq
= GetConfigValueInt(NULL
, "refresh", 0);
1093 if((ALint
)device
->UpdateFreq
<= 0)
1094 device
->UpdateFreq
= 8192 * device
->Frequency
/ 22050;
1096 // Find a playback device to open
1097 for(i
= 0;BackendList
[i
].Init
;i
++)
1099 device
->Funcs
= &BackendList
[i
].Funcs
;
1100 if(ALCdevice_OpenPlayback(device
, deviceName
))
1102 bDeviceFound
= AL_TRUE
;
1109 // No suitable output device found
1122 Close the specified Device
1124 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1126 ALCboolean bReturn
= ALC_FALSE
;
1128 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1130 ALCdevice_ClosePlayback(pDevice
);
1132 //Release device structure
1133 memset(pDevice
, 0, sizeof(ALCdevice
));
1139 SetALCError(ALC_INVALID_DEVICE
);
1143 ///////////////////////////////////////////////////////