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
35 #include "alExtension.h"
36 #include "alAuxEffectSlot.h"
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 { "solaris", alc_solaris_init
, EmptyFuncs
},
57 { "dsound", alcDSoundInit
, EmptyFuncs
},
60 { "winmm", alcWinMMInit
, EmptyFuncs
},
63 { "port", alc_pa_init
, EmptyFuncs
},
65 #ifdef HAVE_PULSEAUDIO
66 { "pulse", alc_pulse_init
, EmptyFuncs
},
69 { "wave", alc_wave_init
, EmptyFuncs
},
71 { NULL
, NULL
, EmptyFuncs
}
75 ///////////////////////////////////////////////////////
77 #define ALC_EFX_MAJOR_VERSION 0x20001
78 #define ALC_EFX_MINOR_VERSION 0x20002
79 #define ALC_MAX_AUXILIARY_SENDS 0x20003
81 ///////////////////////////////////////////////////////
82 // STRING and EXTENSIONS
84 typedef struct ALCfunction_struct
90 static ALCfunction alcFunctions
[] = {
91 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
92 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
93 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
94 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
95 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
96 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
97 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
98 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
99 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
100 { "alcGetError", (ALvoid
*) alcGetError
},
101 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
102 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
103 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
104 { "alcGetString", (ALvoid
*) alcGetString
},
105 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
106 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
107 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
108 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
109 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
110 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
111 { NULL
, (ALvoid
*) NULL
}
114 static ALenums enumeration
[]={
116 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
117 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
118 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
121 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
122 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
123 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
124 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
125 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
126 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
127 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
128 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
129 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
130 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
131 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
132 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
133 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
134 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
135 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
136 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
137 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
140 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
141 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
142 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
145 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
146 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
147 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
148 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
149 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
150 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
151 { (ALchar
*)NULL
, (ALenum
)0 }
154 static const ALCchar alcNoError
[] = "No Error";
155 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
156 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
157 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
158 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
159 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
162 static ALCchar alcDeviceList
[2048];
163 static ALCchar alcAllDeviceList
[2048];
164 static ALCchar alcCaptureDeviceList
[2048];
165 // Default is always the first in the list
166 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
167 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
168 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
171 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
172 static ALCint alcMajorVersion
= 1;
173 static ALCint alcMinorVersion
= 1;
175 static ALCint alcEFXMajorVersion
= 1;
176 static ALCint alcEFXMinorVersion
= 0;
178 ///////////////////////////////////////////////////////
181 ///////////////////////////////////////////////////////
184 static ALCdevice
*g_pDeviceList
= NULL
;
185 static ALCuint g_ulDeviceCount
= 0;
187 static CRITICAL_SECTION g_csMutex
;
190 static ALCcontext
*g_pContextList
= NULL
;
191 static ALCuint g_ulContextCount
= 0;
194 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
196 static ALboolean init_done
= AL_FALSE
;
198 ///////////////////////////////////////////////////////
201 ///////////////////////////////////////////////////////
202 // ALC Related helper functions
204 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
208 // Perform actions based on the reason for calling.
209 switch(ul_reason_for_call
)
211 case DLL_PROCESS_ATTACH
:
212 DisableThreadLibraryCalls(hModule
);
215 case DLL_PROCESS_DETACH
:
224 DeleteCriticalSection(&g_csMutex
);
230 #ifdef HAVE_GCC_DESTRUCTOR
231 static void my_deinit() __attribute__((destructor
));
232 static void my_deinit()
234 static ALenum once
= AL_FALSE
;
235 if(once
|| !init_done
) return;
244 DeleteCriticalSection(&g_csMutex
);
249 static void InitAL(void)
254 const char *devs
, *str
;
258 InitializeCriticalSection(&g_csMutex
);
262 devs
= GetConfigValue(NULL
, "drivers", "");
267 const char *next
= devs
;
273 next
= strchr(devs
, ',');
275 if(!devs
[0] || devs
[0] == ',')
278 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
279 for(n
= i
;BackendList
[n
].Init
;n
++)
281 if(len
== strlen(BackendList
[n
].name
) &&
282 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
284 const char *name
= BackendList
[i
].name
;
285 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
287 BackendList
[i
].name
= BackendList
[n
].name
;
288 BackendList
[i
].Init
= BackendList
[n
].Init
;
290 BackendList
[n
].name
= name
;
291 BackendList
[n
].Init
= Init
;
298 BackendList
[i
].name
= NULL
;
299 BackendList
[i
].Init
= NULL
;
302 for(i
= 0;BackendList
[i
].Init
;i
++)
303 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
305 str
= GetConfigValue(NULL
, "stereodup", "false");
306 DuplicateStereo
= (strcasecmp(str
, "true") == 0 ||
307 strcasecmp(str
, "yes") == 0 ||
308 strcasecmp(str
, "on") == 0 ||
311 str
= GetConfigValue(NULL
, "excludefx", "");
318 { "eaxreverb", EAXREVERB
},
319 { "reverb", REVERB
},
325 const char *next
= str
;
329 next
= strchr(str
, ',');
331 if(!str
[0] || next
== str
)
334 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
335 for(n
= 0;EffectList
[n
].name
;n
++)
337 if(len
== strlen(EffectList
[n
].name
) &&
338 strncmp(EffectList
[n
].name
, str
, len
) == 0)
339 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
346 ALCchar
*AppendDeviceList(char *name
)
349 ALCchar
*ret
= alcDeviceList
+pos
;
350 if(pos
>= sizeof(alcDeviceList
))
352 AL_PRINT("Not enough room to add %s!\n", name
);
353 return alcDeviceList
+ sizeof(alcDeviceList
) - 1;
355 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
-1, "%s", name
) + 1;
359 ALCchar
*AppendAllDeviceList(char *name
)
362 ALCchar
*ret
= alcAllDeviceList
+pos
;
363 if(pos
>= sizeof(alcAllDeviceList
))
365 AL_PRINT("Not enough room to add %s!\n", name
);
366 return alcAllDeviceList
+ sizeof(alcAllDeviceList
) - 1;
368 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
-1, "%s", name
) + 1;
372 ALCchar
*AppendCaptureDeviceList(char *name
)
375 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
376 if(pos
>= sizeof(alcCaptureDeviceList
))
378 AL_PRINT("Not enough room to add %s!\n", name
);
379 return alcCaptureDeviceList
+ sizeof(alcCaptureDeviceList
) - 1;
381 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
-1, "%s", name
) + 1;
388 Check pContext is a valid Context pointer
390 static ALCboolean
IsContext(ALCcontext
*pContext
)
392 ALCcontext
*pTempContext
;
394 pTempContext
= g_pContextList
;
395 while (pTempContext
&& pTempContext
!= pContext
)
396 pTempContext
= pTempContext
->next
;
398 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
405 Store latest ALC Error
407 ALCvoid
SetALCError(ALenum errorCode
)
409 g_eLastContextError
= errorCode
;
418 ALCvoid
SuspendContext(ALCcontext
*pContext
)
421 EnterCriticalSection(&g_csMutex
);
430 ALCvoid
ProcessContext(ALCcontext
*pContext
)
433 LeaveCriticalSection(&g_csMutex
);
440 Initialize Context variables
442 static ALvoid
InitContext(ALCcontext
*pContext
)
446 //Initialise listener
447 pContext
->Listener
.Gain
= 1.0f
;
448 pContext
->Listener
.MetersPerUnit
= 1.0f
;
449 pContext
->Listener
.Position
[0] = 0.0f
;
450 pContext
->Listener
.Position
[1] = 0.0f
;
451 pContext
->Listener
.Position
[2] = 0.0f
;
452 pContext
->Listener
.Velocity
[0] = 0.0f
;
453 pContext
->Listener
.Velocity
[1] = 0.0f
;
454 pContext
->Listener
.Velocity
[2] = 0.0f
;
455 pContext
->Listener
.Forward
[0] = 0.0f
;
456 pContext
->Listener
.Forward
[1] = 0.0f
;
457 pContext
->Listener
.Forward
[2] = -1.0f
;
458 pContext
->Listener
.Up
[0] = 0.0f
;
459 pContext
->Listener
.Up
[1] = 1.0f
;
460 pContext
->Listener
.Up
[2] = 0.0f
;
463 pContext
->LastError
= AL_NO_ERROR
;
464 pContext
->InUse
= AL_FALSE
;
467 pContext
->Frequency
= pContext
->Device
->Frequency
;
470 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
471 pContext
->DopplerFactor
= 1.0f
;
472 pContext
->DopplerVelocity
= 1.0f
;
473 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
475 pContext
->lNumStereoSources
= 1;
476 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
478 pContext
->NumSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
479 if(pContext
->NumSends
> MAX_SENDS
)
480 pContext
->NumSends
= MAX_SENDS
;
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
);
819 else if(device
&& device
->Context
)
820 *data
= device
->Context
->NumSends
;
825 case ALC_ATTRIBUTES_SIZE
:
827 SetALCError(ALC_INVALID_DEVICE
);
829 SetALCError(ALC_INVALID_VALUE
);
834 case ALC_ALL_ATTRIBUTES
:
836 SetALCError(ALC_INVALID_DEVICE
);
838 SetALCError(ALC_INVALID_VALUE
);
843 data
[i
++] = ALC_FREQUENCY
;
844 data
[i
++] = device
->Frequency
;
846 data
[i
++] = ALC_REFRESH
;
847 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
849 data
[i
++] = ALC_SYNC
;
850 data
[i
++] = ALC_FALSE
;
852 SuspendContext(NULL
);
853 if(device
->Context
&& size
>= 12)
855 data
[i
++] = ALC_MONO_SOURCES
;
856 data
[i
++] = device
->Context
->lNumMonoSources
;
858 data
[i
++] = ALC_STEREO_SOURCES
;
859 data
[i
++] = device
->Context
->lNumStereoSources
;
861 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
862 data
[i
++] = device
->Context
->NumSends
;
864 ProcessContext(NULL
);
872 SetALCError(ALC_INVALID_DEVICE
);
874 SetALCError(ALC_INVALID_VALUE
);
876 *data
= device
->Frequency
;
881 SetALCError(ALC_INVALID_DEVICE
);
883 SetALCError(ALC_INVALID_VALUE
);
885 *data
= device
->Frequency
/ device
->UpdateSize
;
890 SetALCError(ALC_INVALID_DEVICE
);
892 SetALCError(ALC_INVALID_VALUE
);
897 case ALC_MONO_SOURCES
:
898 if(!device
|| !device
->Context
)
899 SetALCError(ALC_INVALID_DEVICE
);
901 SetALCError(ALC_INVALID_VALUE
);
903 *data
= device
->Context
->lNumMonoSources
;
906 case ALC_STEREO_SOURCES
:
907 if(!device
|| !device
->Context
)
908 SetALCError(ALC_INVALID_DEVICE
);
910 SetALCError(ALC_INVALID_VALUE
);
912 *data
= device
->Context
->lNumStereoSources
;
916 SetALCError(ALC_INVALID_ENUM
);
921 SetALCError(ALC_INVALID_VALUE
);
929 alcIsExtensionPresent
931 Determines if there is support for a particular extension
933 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
935 ALCboolean bResult
= ALC_FALSE
;
944 len
= strlen(extName
);
945 ptr
= alcExtensionList
;
948 if(strncasecmp(ptr
, extName
, len
) == 0 &&
949 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
954 if((ptr
=strchr(ptr
, ' ')) != NULL
)
958 } while(isspace(*ptr
));
963 SetALCError(ALC_INVALID_VALUE
);
972 Retrieves the function address for a particular extension function
974 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
976 ALCvoid
*pFunction
= NULL
;
983 while(alcFunctions
[i
].funcName
&&
984 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
986 pFunction
= alcFunctions
[i
].address
;
989 SetALCError(ALC_INVALID_VALUE
);
998 Get the value for a particular ALC Enumerated Value
1000 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1007 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1009 val
= enumeration
[i
].value
;
1011 if(!enumeration
[i
].enumName
)
1012 SetALCError(ALC_INVALID_VALUE
);
1021 Create and attach a Context to a particular Device.
1023 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1025 ALCcontext
*ALContext
= NULL
;
1026 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
1027 ALuint RequestedSends
;
1029 if ((device
)&&(!device
->IsCaptureDevice
))
1031 // Reset Context Last Error code
1032 g_eLastContextError
= ALC_NO_ERROR
;
1034 // Current implementation only allows one Context per Device
1035 if(!device
->Context
)
1037 ALContext
= calloc(1, sizeof(ALCcontext
));
1040 SetALCError(ALC_OUT_OF_MEMORY
);
1044 ALContext
->Device
= device
;
1045 InitContext(ALContext
);
1047 device
->Context
= ALContext
;
1049 SuspendContext(NULL
);
1051 ALContext
->next
= g_pContextList
;
1052 g_pContextList
= ALContext
;
1055 ProcessContext(NULL
);
1057 // Check for attributes
1060 ulAttributeIndex
= 0;
1061 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
1063 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
1065 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
1067 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
1068 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
1070 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
1071 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
1074 if(attrList
[ulAttributeIndex
] == ALC_MAX_AUXILIARY_SENDS
)
1076 RequestedSends
= attrList
[ulAttributeIndex
+ 1];
1078 if(RequestedSends
> ALContext
->NumSends
)
1079 RequestedSends
= ALContext
->NumSends
;
1081 ALContext
->NumSends
= RequestedSends
;
1084 ulAttributeIndex
+= 2;
1090 SetALCError(ALC_INVALID_VALUE
);
1095 SetALCError(ALC_INVALID_DEVICE
);
1106 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1112 // Lock context list
1113 SuspendContext(NULL
);
1115 if (IsContext(context
))
1118 SuspendContext(context
);
1120 ReleaseALSources(context
);
1121 ReleaseALAuxiliaryEffectSlots(context
);
1123 context
->Device
->Context
= NULL
;
1125 list
= &g_pContextList
;
1126 while(*list
!= context
)
1127 list
= &(*list
)->next
;
1129 *list
= (*list
)->next
;
1133 ProcessContext(context
);
1135 ExitContext(context
);
1137 // Free memory (MUST do this after ProcessContext)
1138 memset(context
, 0, sizeof(ALCcontext
));
1142 SetALCError(ALC_INVALID_CONTEXT
);
1144 ProcessContext(NULL
);
1149 alcGetCurrentContext
1151 Returns the currently active Context
1153 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1155 ALCcontext
*pContext
= NULL
;
1159 SuspendContext(NULL
);
1161 pContext
= g_pContextList
;
1162 while ((pContext
) && (!pContext
->InUse
))
1163 pContext
= pContext
->next
;
1165 ProcessContext(NULL
);
1172 alcGetContextsDevice
1174 Returns the Device that a particular Context is attached to
1176 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1178 ALCdevice
*pDevice
= NULL
;
1182 SuspendContext(NULL
);
1183 if (IsContext(pContext
))
1184 pDevice
= pContext
->Device
;
1186 SetALCError(ALC_INVALID_CONTEXT
);
1187 ProcessContext(NULL
);
1194 alcMakeContextCurrent
1196 Makes the given Context the active Context
1198 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1200 ALCcontext
*ALContext
;
1201 ALboolean bReturn
= AL_TRUE
;
1205 SuspendContext(NULL
);
1207 // context must be a valid Context or NULL
1208 if ((IsContext(context
)) || (context
== NULL
))
1210 if ((ALContext
=alcGetCurrentContext()))
1212 SuspendContext(ALContext
);
1213 ALContext
->InUse
=AL_FALSE
;
1214 ProcessContext(ALContext
);
1217 if ((ALContext
=context
) && (ALContext
->Device
))
1219 SuspendContext(ALContext
);
1220 ALContext
->InUse
=AL_TRUE
;
1221 ProcessContext(ALContext
);
1226 SetALCError(ALC_INVALID_CONTEXT
);
1230 ProcessContext(NULL
);
1239 Open the Device specified.
1241 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1243 ALboolean bDeviceFound
= AL_FALSE
;
1249 if(deviceName
&& !deviceName
[0])
1252 device
= malloc(sizeof(ALCdevice
));
1257 //Initialise device structure
1258 memset(device
, 0, sizeof(ALCdevice
));
1261 device
->IsCaptureDevice
= AL_FALSE
;
1264 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1265 if((ALint
)device
->Frequency
<= 0)
1266 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1268 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1270 device
->Format
= alGetEnumValue(fmt
);
1272 if(!aluChannelsFromFormat(device
->Format
))
1273 device
->Format
= AL_FORMAT_STEREO16
;
1275 device
->UpdateSize
= GetConfigValueInt(NULL
, "refresh", 4096);
1276 if((ALint
)device
->UpdateSize
<= 0)
1277 device
->UpdateSize
= 4096;
1279 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1280 if((ALint
)device
->MaxNoOfSources
<= 0)
1281 device
->MaxNoOfSources
= 256;
1283 device
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
1284 if((ALint
)device
->AuxiliaryEffectSlotMax
<= 0)
1285 device
->AuxiliaryEffectSlotMax
= 4;
1287 // Find a playback device to open
1288 SuspendContext(NULL
);
1289 for(i
= 0;BackendList
[i
].Init
;i
++)
1291 device
->Funcs
= &BackendList
[i
].Funcs
;
1292 if(ALCdevice_OpenPlayback(device
, deviceName
))
1294 device
->next
= g_pDeviceList
;
1295 g_pDeviceList
= device
;
1298 bDeviceFound
= AL_TRUE
;
1302 ProcessContext(NULL
);
1306 // No suitable output device found
1307 SetALCError(ALC_INVALID_VALUE
);
1313 SetALCError(ALC_OUT_OF_MEMORY
);
1322 Close the specified Device
1324 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1326 ALCboolean bReturn
= ALC_FALSE
;
1329 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1331 SuspendContext(NULL
);
1333 list
= &g_pDeviceList
;
1334 while(*list
!= pDevice
)
1335 list
= &(*list
)->next
;
1337 *list
= (*list
)->next
;
1340 ProcessContext(NULL
);
1342 if(pDevice
->Context
)
1345 AL_PRINT("alcCloseDevice(): destroying 1 Context\n");
1347 alcDestroyContext(pDevice
->Context
);
1349 ALCdevice_ClosePlayback(pDevice
);
1351 //Release device structure
1352 memset(pDevice
, 0, sizeof(ALCdevice
));
1358 SetALCError(ALC_INVALID_DEVICE
);
1364 ALCvoid
ReleaseALC(ALCvoid
)
1367 if(g_ulDeviceCount
> 0)
1368 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1371 while(g_pDeviceList
)
1373 if(g_pDeviceList
->IsCaptureDevice
)
1374 alcCaptureCloseDevice(g_pDeviceList
);
1376 alcCloseDevice(g_pDeviceList
);
1380 ///////////////////////////////////////////////////////