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
37 #include "alExtension.h"
38 #include "alAuxEffectSlot.h"
42 ///////////////////////////////////////////////////////
47 ///////////////////////////////////////////////////////
50 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
53 void (*Init
)(BackendFuncs
*);
57 { "alsa", alc_alsa_init
, EmptyFuncs
},
60 { "oss", alc_oss_init
, EmptyFuncs
},
63 { "solaris", alc_solaris_init
, EmptyFuncs
},
66 { "dsound", alcDSoundInit
, EmptyFuncs
},
69 { "winmm", alcWinMMInit
, EmptyFuncs
},
72 { "port", alc_pa_init
, EmptyFuncs
},
75 { "wave", alc_wave_init
, EmptyFuncs
},
77 { NULL
, NULL
, EmptyFuncs
}
81 ///////////////////////////////////////////////////////
83 #define ALC_EFX_MAJOR_VERSION 0x20001
84 #define ALC_EFX_MINOR_VERSION 0x20002
85 #define ALC_MAX_AUXILIARY_SENDS 0x20003
87 ///////////////////////////////////////////////////////
88 // STRING and EXTENSIONS
90 typedef struct ALCfunction_struct
96 static ALCfunction alcFunctions
[] = {
97 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
98 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
99 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
100 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
101 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
102 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
103 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
104 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
105 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
106 { "alcGetError", (ALvoid
*) alcGetError
},
107 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
108 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
109 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
110 { "alcGetString", (ALvoid
*) alcGetString
},
111 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
112 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
113 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
114 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
115 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
116 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
117 { NULL
, (ALvoid
*) NULL
}
120 static ALenums enumeration
[]={
122 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
123 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
124 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
127 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
128 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
129 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
130 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
131 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
132 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
133 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
134 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
135 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
136 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
137 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
138 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
139 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
140 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
141 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
142 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
143 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
146 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
147 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
148 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
151 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
152 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
153 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
154 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
155 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
156 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
157 { (ALchar
*)NULL
, (ALenum
)0 }
160 static const ALCchar alcNoError
[] = "No Error";
161 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
162 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
163 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
164 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
165 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
168 static ALCchar alcDeviceList
[2048];
169 static ALCchar alcAllDeviceList
[2048];
170 static ALCchar alcCaptureDeviceList
[2048];
171 // Default is always the first in the list
172 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
173 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
174 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
177 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
178 static ALCint alcMajorVersion
= 1;
179 static ALCint alcMinorVersion
= 1;
181 static ALCint alcEFXMajorVersion
= 1;
182 static ALCint alcEFXMinorVersion
= 0;
184 ///////////////////////////////////////////////////////
187 ///////////////////////////////////////////////////////
190 static ALCdevice
*g_pDeviceList
= NULL
;
191 static ALCuint g_ulDeviceCount
= 0;
193 static CRITICAL_SECTION g_csMutex
;
196 static ALCcontext
*g_pContextList
= NULL
;
197 static ALCuint g_ulContextCount
= 0;
200 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
202 static ALboolean init_done
= AL_FALSE
;
204 ///////////////////////////////////////////////////////
207 ///////////////////////////////////////////////////////
208 // ALC Related helper functions
210 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
214 // Perform actions based on the reason for calling.
215 switch(ul_reason_for_call
)
217 case DLL_PROCESS_ATTACH
:
218 DisableThreadLibraryCalls(hModule
);
221 case DLL_PROCESS_DETACH
:
230 DeleteCriticalSection(&g_csMutex
);
236 #ifdef HAVE_GCC_DESTRUCTOR
237 static void my_deinit() __attribute__((destructor
));
238 static void my_deinit()
240 static ALenum once
= AL_FALSE
;
241 if(once
|| !init_done
) return;
250 DeleteCriticalSection(&g_csMutex
);
255 static void InitAL(void)
260 const char *devs
, *str
;
264 InitializeCriticalSection(&g_csMutex
);
268 devs
= GetConfigValue(NULL
, "drivers", "");
273 const char *next
= devs
;
279 next
= strchr(devs
, ',');
281 if(!devs
[0] || devs
[0] == ',')
284 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
285 for(n
= i
;BackendList
[n
].Init
;n
++)
287 if(len
== strlen(BackendList
[n
].name
) &&
288 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
290 const char *name
= BackendList
[i
].name
;
291 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
293 BackendList
[i
].name
= BackendList
[n
].name
;
294 BackendList
[i
].Init
= BackendList
[n
].Init
;
296 BackendList
[n
].name
= name
;
297 BackendList
[n
].Init
= Init
;
304 BackendList
[i
].name
= NULL
;
305 BackendList
[i
].Init
= NULL
;
308 for(i
= 0;BackendList
[i
].Init
;i
++)
309 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
311 str
= GetConfigValue(NULL
, "stereodup", "false");
312 DuplicateStereo
= (strcasecmp(str
, "true") == 0 ||
313 strcasecmp(str
, "yes") == 0 ||
314 strcasecmp(str
, "on") == 0 ||
317 str
= GetConfigValue(NULL
, "excludefx", "");
324 { "reverb", REVERB
},
329 const char *next
= str
;
333 next
= strchr(str
, ',');
335 if(!str
[0] || next
== str
)
338 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
339 for(n
= 0;EffectList
[n
].name
;n
++)
341 if(len
== strlen(EffectList
[n
].name
) &&
342 strncmp(EffectList
[n
].name
, str
, len
) == 0)
343 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
350 ALCchar
*AppendDeviceList(char *name
)
353 ALCchar
*ret
= alcDeviceList
+pos
;
354 if(pos
>= sizeof(alcDeviceList
))
356 AL_PRINT("Not enough room to add %s!\n", name
);
357 return alcDeviceList
+ sizeof(alcDeviceList
) - 1;
359 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
-1, "%s", name
) + 1;
363 ALCchar
*AppendAllDeviceList(char *name
)
366 ALCchar
*ret
= alcAllDeviceList
+pos
;
367 if(pos
>= sizeof(alcAllDeviceList
))
369 AL_PRINT("Not enough room to add %s!\n", name
);
370 return alcAllDeviceList
+ sizeof(alcAllDeviceList
) - 1;
372 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
-1, "%s", name
) + 1;
376 ALCchar
*AppendCaptureDeviceList(char *name
)
379 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
380 if(pos
>= sizeof(alcCaptureDeviceList
))
382 AL_PRINT("Not enough room to add %s!\n", name
);
383 return alcCaptureDeviceList
+ sizeof(alcCaptureDeviceList
) - 1;
385 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
-1, "%s", name
) + 1;
392 Check pContext is a valid Context pointer
394 static ALCboolean
IsContext(ALCcontext
*pContext
)
396 ALCcontext
*pTempContext
;
398 pTempContext
= g_pContextList
;
399 while (pTempContext
&& pTempContext
!= pContext
)
400 pTempContext
= pTempContext
->next
;
402 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
409 Store latest ALC Error
411 ALCvoid
SetALCError(ALenum errorCode
)
413 g_eLastContextError
= errorCode
;
422 ALCvoid
SuspendContext(ALCcontext
*pContext
)
425 EnterCriticalSection(&g_csMutex
);
434 ALCvoid
ProcessContext(ALCcontext
*pContext
)
437 LeaveCriticalSection(&g_csMutex
);
444 Initialize Context variables
446 static ALvoid
InitContext(ALCcontext
*pContext
)
450 //Initialise listener
451 pContext
->Listener
.Gain
= 1.0f
;
452 pContext
->Listener
.MetersPerUnit
= 1.0f
;
453 pContext
->Listener
.Position
[0] = 0.0f
;
454 pContext
->Listener
.Position
[1] = 0.0f
;
455 pContext
->Listener
.Position
[2] = 0.0f
;
456 pContext
->Listener
.Velocity
[0] = 0.0f
;
457 pContext
->Listener
.Velocity
[1] = 0.0f
;
458 pContext
->Listener
.Velocity
[2] = 0.0f
;
459 pContext
->Listener
.Forward
[0] = 0.0f
;
460 pContext
->Listener
.Forward
[1] = 0.0f
;
461 pContext
->Listener
.Forward
[2] = -1.0f
;
462 pContext
->Listener
.Up
[0] = 0.0f
;
463 pContext
->Listener
.Up
[1] = 1.0f
;
464 pContext
->Listener
.Up
[2] = 0.0f
;
467 pContext
->LastError
= AL_NO_ERROR
;
468 pContext
->InUse
= AL_FALSE
;
471 pContext
->Frequency
= pContext
->Device
->Frequency
;
474 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
475 pContext
->DopplerFactor
= 1.0f
;
476 pContext
->DopplerVelocity
= 1.0f
;
477 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
479 pContext
->lNumStereoSources
= 1;
480 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
482 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";
484 level
= GetConfigValueInt(NULL
, "cf_level", 0);
485 if(level
> 0 && level
<= 6)
487 pContext
->bs2b
= calloc(1, sizeof(*pContext
->bs2b
));
488 bs2b_set_srate(pContext
->bs2b
, pContext
->Frequency
);
489 bs2b_set_level(pContext
->bs2b
, level
);
492 aluInitPanning(pContext
);
499 Clean up Context, destroy any remaining Sources
501 static ALCvoid
ExitContext(ALCcontext
*pContext
)
504 pContext
->LastError
= AL_NO_ERROR
;
505 pContext
->InUse
= AL_FALSE
;
507 free(pContext
->bs2b
);
508 pContext
->bs2b
= NULL
;
511 ///////////////////////////////////////////////////////
514 ///////////////////////////////////////////////////////
515 // ALC Functions calls
518 // This should probably move to another c file but for now ...
519 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
521 ALCboolean DeviceFound
= ALC_FALSE
;
522 ALCdevice
*pDevice
= NULL
;
529 SetALCError(ALC_INVALID_VALUE
);
533 if(deviceName
&& !deviceName
[0])
536 pDevice
= malloc(sizeof(ALCdevice
));
539 //Initialise device structure
540 memset(pDevice
, 0, sizeof(ALCdevice
));
543 pDevice
->IsCaptureDevice
= AL_TRUE
;
545 pDevice
->Frequency
= frequency
;
546 pDevice
->Format
= format
;
548 for(i
= 0;BackendList
[i
].Init
;i
++)
550 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
551 if(ALCdevice_OpenCapture(pDevice
, deviceName
, frequency
, format
, SampleSize
))
553 SuspendContext(NULL
);
554 pDevice
->next
= g_pDeviceList
;
555 g_pDeviceList
= pDevice
;
557 ProcessContext(NULL
);
559 DeviceFound
= ALC_TRUE
;
566 SetALCError(ALC_INVALID_VALUE
);
572 SetALCError(ALC_OUT_OF_MEMORY
);
577 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
579 ALCboolean bReturn
= ALC_FALSE
;
582 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
584 SuspendContext(NULL
);
586 list
= &g_pDeviceList
;
587 while(*list
!= pDevice
)
588 list
= &(*list
)->next
;
590 *list
= (*list
)->next
;
593 ProcessContext(NULL
);
595 ALCdevice_CloseCapture(pDevice
);
601 SetALCError(ALC_INVALID_DEVICE
);
606 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
608 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
609 ALCdevice_StartCapture(pDevice
);
611 SetALCError(ALC_INVALID_DEVICE
);
614 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
616 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
617 ALCdevice_StopCapture(pDevice
);
619 SetALCError(ALC_INVALID_DEVICE
);
622 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
624 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
625 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
627 SetALCError(ALC_INVALID_DEVICE
);
633 Return last ALC generated error code
635 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
641 errorCode
= g_eLastContextError
;
642 g_eLastContextError
= ALC_NO_ERROR
;
652 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
654 // Not a lot happens here !
664 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
666 // Not a lot happens here !
674 Returns information about the Device, and error strings
676 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
678 const ALCchar
*value
= NULL
;
688 case ALC_INVALID_ENUM
:
689 value
= alcErrInvalidEnum
;
692 case ALC_INVALID_VALUE
:
693 value
= alcErrInvalidValue
;
696 case ALC_INVALID_DEVICE
:
697 value
= alcErrInvalidDevice
;
700 case ALC_INVALID_CONTEXT
:
701 value
= alcErrInvalidContext
;
704 case ALC_OUT_OF_MEMORY
:
705 value
= alcErrOutOfMemory
;
708 case ALC_DEFAULT_DEVICE_SPECIFIER
:
709 value
= alcDefaultDeviceSpecifier
;
712 case ALC_DEVICE_SPECIFIER
:
714 value
= pDevice
->szDeviceName
;
716 value
= alcDeviceList
;
719 case ALC_ALL_DEVICES_SPECIFIER
:
720 value
= alcAllDeviceList
;
723 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
724 value
= alcDefaultAllDeviceSpecifier
;
727 case ALC_CAPTURE_DEVICE_SPECIFIER
:
729 value
= pDevice
->szDeviceName
;
731 value
= alcCaptureDeviceList
;
734 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
735 value
= alcCaptureDefaultDeviceSpecifier
;
739 value
= alcExtensionList
;
743 SetALCError(ALC_INVALID_ENUM
);
754 Returns information about the Device and the version of Open AL
756 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
760 if ((device
)&&(device
->IsCaptureDevice
))
762 SuspendContext(NULL
);
767 case ALC_CAPTURE_SAMPLES
:
768 if ((size
) && (data
))
769 *data
= ALCdevice_AvailableSamples(device
);
771 SetALCError(ALC_INVALID_VALUE
);
775 SetALCError(ALC_INVALID_ENUM
);
779 ProcessContext(NULL
);
788 case ALC_MAJOR_VERSION
:
790 SetALCError(ALC_INVALID_VALUE
);
792 *data
= alcMajorVersion
;
795 case ALC_MINOR_VERSION
:
797 SetALCError(ALC_INVALID_VALUE
);
799 *data
= alcMinorVersion
;
802 case ALC_EFX_MAJOR_VERSION
:
804 SetALCError(ALC_INVALID_VALUE
);
806 *data
= alcEFXMajorVersion
;
809 case ALC_EFX_MINOR_VERSION
:
811 SetALCError(ALC_INVALID_VALUE
);
813 *data
= alcEFXMinorVersion
;
816 case ALC_MAX_AUXILIARY_SENDS
:
818 SetALCError(ALC_INVALID_VALUE
);
823 case ALC_ATTRIBUTES_SIZE
:
825 SetALCError(ALC_INVALID_DEVICE
);
827 SetALCError(ALC_INVALID_VALUE
);
832 case ALC_ALL_ATTRIBUTES
:
834 SetALCError(ALC_INVALID_DEVICE
);
836 SetALCError(ALC_INVALID_VALUE
);
841 data
[i
++] = ALC_FREQUENCY
;
842 data
[i
++] = device
->Frequency
;
844 data
[i
++] = ALC_REFRESH
;
845 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
847 data
[i
++] = ALC_SYNC
;
848 data
[i
++] = ALC_FALSE
;
850 SuspendContext(NULL
);
851 if(device
->Context
&& size
>= 12)
853 data
[i
++] = ALC_MONO_SOURCES
;
854 data
[i
++] = device
->Context
->lNumMonoSources
;
856 data
[i
++] = ALC_STEREO_SOURCES
;
857 data
[i
++] = device
->Context
->lNumStereoSources
;
859 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
860 data
[i
++] = MAX_SENDS
;
862 ProcessContext(NULL
);
870 SetALCError(ALC_INVALID_DEVICE
);
872 SetALCError(ALC_INVALID_VALUE
);
874 *data
= device
->Frequency
;
879 SetALCError(ALC_INVALID_DEVICE
);
881 SetALCError(ALC_INVALID_VALUE
);
883 *data
= device
->Frequency
/ device
->UpdateSize
;
888 SetALCError(ALC_INVALID_DEVICE
);
890 SetALCError(ALC_INVALID_VALUE
);
895 case ALC_MONO_SOURCES
:
896 if(!device
|| !device
->Context
)
897 SetALCError(ALC_INVALID_DEVICE
);
899 SetALCError(ALC_INVALID_VALUE
);
901 *data
= device
->Context
->lNumMonoSources
;
904 case ALC_STEREO_SOURCES
:
905 if(!device
|| !device
->Context
)
906 SetALCError(ALC_INVALID_DEVICE
);
908 SetALCError(ALC_INVALID_VALUE
);
910 *data
= device
->Context
->lNumStereoSources
;
914 SetALCError(ALC_INVALID_ENUM
);
919 SetALCError(ALC_INVALID_VALUE
);
927 alcIsExtensionPresent
929 Determines if there is support for a particular extension
931 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
933 ALCboolean bResult
= ALC_FALSE
;
942 len
= strlen(extName
);
943 ptr
= alcExtensionList
;
946 if(strncasecmp(ptr
, extName
, len
) == 0 &&
947 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
952 if((ptr
=strchr(ptr
, ' ')) != NULL
)
956 } while(isspace(*ptr
));
961 SetALCError(ALC_INVALID_VALUE
);
970 Retrieves the function address for a particular extension function
972 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
974 ALCvoid
*pFunction
= NULL
;
981 while(alcFunctions
[i
].funcName
&&
982 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
984 pFunction
= alcFunctions
[i
].address
;
987 SetALCError(ALC_INVALID_VALUE
);
996 Get the value for a particular ALC Enumerated Value
998 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1005 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1007 val
= enumeration
[i
].value
;
1009 if(!enumeration
[i
].enumName
)
1010 SetALCError(ALC_INVALID_VALUE
);
1019 Create and attach a Context to a particular Device.
1021 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1023 ALCcontext
*ALContext
= NULL
;
1024 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
1026 if ((device
)&&(!device
->IsCaptureDevice
))
1028 // Reset Context Last Error code
1029 g_eLastContextError
= ALC_NO_ERROR
;
1031 // Current implementation only allows one Context per Device
1032 if(!device
->Context
)
1034 ALContext
= calloc(1, sizeof(ALCcontext
));
1037 SetALCError(ALC_OUT_OF_MEMORY
);
1041 ALContext
->Device
= device
;
1042 InitContext(ALContext
);
1044 device
->Context
= ALContext
;
1046 SuspendContext(NULL
);
1048 ALContext
->next
= g_pContextList
;
1049 g_pContextList
= ALContext
;
1052 ProcessContext(NULL
);
1054 // Check for Voice Count attributes
1057 ulAttributeIndex
= 0;
1058 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
1060 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
1062 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
1064 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
1065 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
1067 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
1068 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
1072 ulAttributeIndex
+= 2;
1078 SetALCError(ALC_INVALID_VALUE
);
1083 SetALCError(ALC_INVALID_DEVICE
);
1094 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1100 // Lock context list
1101 SuspendContext(NULL
);
1103 if (IsContext(context
))
1106 SuspendContext(context
);
1108 ReleaseALSources(context
);
1109 ReleaseALAuxiliaryEffectSlots(context
);
1111 context
->Device
->Context
= NULL
;
1113 list
= &g_pContextList
;
1114 while(*list
!= context
)
1115 list
= &(*list
)->next
;
1117 *list
= (*list
)->next
;
1121 ProcessContext(context
);
1123 ExitContext(context
);
1125 // Free memory (MUST do this after ProcessContext)
1126 memset(context
, 0, sizeof(ALCcontext
));
1130 SetALCError(ALC_INVALID_CONTEXT
);
1132 ProcessContext(NULL
);
1137 alcGetCurrentContext
1139 Returns the currently active Context
1141 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1143 ALCcontext
*pContext
= NULL
;
1147 SuspendContext(NULL
);
1149 pContext
= g_pContextList
;
1150 while ((pContext
) && (!pContext
->InUse
))
1151 pContext
= pContext
->next
;
1153 ProcessContext(NULL
);
1160 alcGetContextsDevice
1162 Returns the Device that a particular Context is attached to
1164 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1166 ALCdevice
*pDevice
= NULL
;
1170 SuspendContext(NULL
);
1171 if (IsContext(pContext
))
1172 pDevice
= pContext
->Device
;
1174 SetALCError(ALC_INVALID_CONTEXT
);
1175 ProcessContext(NULL
);
1182 alcMakeContextCurrent
1184 Makes the given Context the active Context
1186 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1188 ALCcontext
*ALContext
;
1189 ALboolean bReturn
= AL_TRUE
;
1193 SuspendContext(NULL
);
1195 // context must be a valid Context or NULL
1196 if ((IsContext(context
)) || (context
== NULL
))
1198 if ((ALContext
=alcGetCurrentContext()))
1200 SuspendContext(ALContext
);
1201 ALContext
->InUse
=AL_FALSE
;
1202 ProcessContext(ALContext
);
1205 if ((ALContext
=context
) && (ALContext
->Device
))
1207 SuspendContext(ALContext
);
1208 ALContext
->InUse
=AL_TRUE
;
1209 ProcessContext(ALContext
);
1214 SetALCError(ALC_INVALID_CONTEXT
);
1218 ProcessContext(NULL
);
1227 Open the Device specified.
1229 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1231 ALboolean bDeviceFound
= AL_FALSE
;
1237 if(deviceName
&& !deviceName
[0])
1240 device
= malloc(sizeof(ALCdevice
));
1245 //Initialise device structure
1246 memset(device
, 0, sizeof(ALCdevice
));
1249 device
->IsCaptureDevice
= AL_FALSE
;
1252 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1253 if((ALint
)device
->Frequency
<= 0)
1254 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1256 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1258 device
->Format
= alGetEnumValue(fmt
);
1260 if(!aluChannelsFromFormat(device
->Format
))
1261 device
->Format
= AL_FORMAT_STEREO16
;
1263 device
->UpdateSize
= GetConfigValueInt(NULL
, "refresh", 4096);
1264 if((ALint
)device
->UpdateSize
<= 0)
1265 device
->UpdateSize
= 4096;
1267 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1268 if((ALint
)device
->MaxNoOfSources
<= 0)
1269 device
->MaxNoOfSources
= 256;
1271 // Find a playback device to open
1272 SuspendContext(NULL
);
1273 for(i
= 0;BackendList
[i
].Init
;i
++)
1275 device
->Funcs
= &BackendList
[i
].Funcs
;
1276 if(ALCdevice_OpenPlayback(device
, deviceName
))
1278 device
->next
= g_pDeviceList
;
1279 g_pDeviceList
= device
;
1282 bDeviceFound
= AL_TRUE
;
1286 ProcessContext(NULL
);
1290 // No suitable output device found
1291 SetALCError(ALC_INVALID_VALUE
);
1297 SetALCError(ALC_OUT_OF_MEMORY
);
1306 Close the specified Device
1308 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1310 ALCboolean bReturn
= ALC_FALSE
;
1313 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1315 SuspendContext(NULL
);
1317 list
= &g_pDeviceList
;
1318 while(*list
!= pDevice
)
1319 list
= &(*list
)->next
;
1321 *list
= (*list
)->next
;
1324 ProcessContext(NULL
);
1326 if(pDevice
->Context
)
1329 AL_PRINT("alcCloseDevice(): destroying 1 Context\n");
1331 alcDestroyContext(pDevice
->Context
);
1333 ALCdevice_ClosePlayback(pDevice
);
1335 //Release device structure
1336 memset(pDevice
, 0, sizeof(ALCdevice
));
1342 SetALCError(ALC_INVALID_DEVICE
);
1348 ALCvoid
ReleaseALC(ALCvoid
)
1351 if(g_ulDeviceCount
> 0)
1352 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1355 while(g_pDeviceList
)
1357 if(g_pDeviceList
->IsCaptureDevice
)
1358 alcCaptureCloseDevice(g_pDeviceList
);
1360 alcCloseDevice(g_pDeviceList
);
1364 ///////////////////////////////////////////////////////