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"
40 ///////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////
48 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
51 void (*Init
)(BackendFuncs
*);
55 { "alsa", alc_alsa_init
, EmptyFuncs
},
58 { "oss", alc_oss_init
, EmptyFuncs
},
61 { "solaris", alc_solaris_init
, EmptyFuncs
},
64 { "dsound", alcDSoundInit
, EmptyFuncs
},
67 { "winmm", alcWinMMInit
, EmptyFuncs
},
70 { "port", alc_pa_init
, EmptyFuncs
},
72 #ifdef HAVE_PULSEAUDIO
73 { "pulse", alc_pulse_init
, EmptyFuncs
},
76 { "wave", alc_wave_init
, EmptyFuncs
},
78 { NULL
, NULL
, EmptyFuncs
}
82 ///////////////////////////////////////////////////////
84 #define ALC_EFX_MAJOR_VERSION 0x20001
85 #define ALC_EFX_MINOR_VERSION 0x20002
86 #define ALC_MAX_AUXILIARY_SENDS 0x20003
88 ///////////////////////////////////////////////////////
89 // STRING and EXTENSIONS
91 typedef struct ALCfunction_struct
97 static ALCfunction alcFunctions
[] = {
98 { "alcCreateContext", (ALvoid
*) alcCreateContext
},
99 { "alcMakeContextCurrent", (ALvoid
*) alcMakeContextCurrent
},
100 { "alcProcessContext", (ALvoid
*) alcProcessContext
},
101 { "alcSuspendContext", (ALvoid
*) alcSuspendContext
},
102 { "alcDestroyContext", (ALvoid
*) alcDestroyContext
},
103 { "alcGetCurrentContext", (ALvoid
*) alcGetCurrentContext
},
104 { "alcGetContextsDevice", (ALvoid
*) alcGetContextsDevice
},
105 { "alcOpenDevice", (ALvoid
*) alcOpenDevice
},
106 { "alcCloseDevice", (ALvoid
*) alcCloseDevice
},
107 { "alcGetError", (ALvoid
*) alcGetError
},
108 { "alcIsExtensionPresent", (ALvoid
*) alcIsExtensionPresent
},
109 { "alcGetProcAddress", (ALvoid
*) alcGetProcAddress
},
110 { "alcGetEnumValue", (ALvoid
*) alcGetEnumValue
},
111 { "alcGetString", (ALvoid
*) alcGetString
},
112 { "alcGetIntegerv", (ALvoid
*) alcGetIntegerv
},
113 { "alcCaptureOpenDevice", (ALvoid
*) alcCaptureOpenDevice
},
114 { "alcCaptureCloseDevice", (ALvoid
*) alcCaptureCloseDevice
},
115 { "alcCaptureStart", (ALvoid
*) alcCaptureStart
},
116 { "alcCaptureStop", (ALvoid
*) alcCaptureStop
},
117 { "alcCaptureSamples", (ALvoid
*) alcCaptureSamples
},
118 { NULL
, (ALvoid
*) NULL
}
121 static ALenums enumeration
[]={
123 { (ALchar
*)"ALC_INVALID", ALC_INVALID
},
124 { (ALchar
*)"ALC_FALSE", ALC_FALSE
},
125 { (ALchar
*)"ALC_TRUE", ALC_TRUE
},
128 { (ALchar
*)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION
},
129 { (ALchar
*)"ALC_MINOR_VERSION", ALC_MINOR_VERSION
},
130 { (ALchar
*)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE
},
131 { (ALchar
*)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES
},
132 { (ALchar
*)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER
},
133 { (ALchar
*)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER
},
134 { (ALchar
*)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER
},
135 { (ALchar
*)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER
},
136 { (ALchar
*)"ALC_EXTENSIONS", ALC_EXTENSIONS
},
137 { (ALchar
*)"ALC_FREQUENCY", ALC_FREQUENCY
},
138 { (ALchar
*)"ALC_REFRESH", ALC_REFRESH
},
139 { (ALchar
*)"ALC_SYNC", ALC_SYNC
},
140 { (ALchar
*)"ALC_MONO_SOURCES", ALC_MONO_SOURCES
},
141 { (ALchar
*)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES
},
142 { (ALchar
*)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER
},
143 { (ALchar
*)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
},
144 { (ALchar
*)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES
},
147 { (ALchar
*)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION
},
148 { (ALchar
*)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION
},
149 { (ALchar
*)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS
},
152 { (ALchar
*)"ALC_NO_ERROR", ALC_NO_ERROR
},
153 { (ALchar
*)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE
},
154 { (ALchar
*)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT
},
155 { (ALchar
*)"ALC_INVALID_ENUM", ALC_INVALID_ENUM
},
156 { (ALchar
*)"ALC_INVALID_VALUE", ALC_INVALID_VALUE
},
157 { (ALchar
*)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY
},
158 { (ALchar
*)NULL
, (ALenum
)0 }
161 static const ALCchar alcNoError
[] = "No Error";
162 static const ALCchar alcErrInvalidDevice
[] = "Invalid Device";
163 static const ALCchar alcErrInvalidContext
[] = "Invalid Context";
164 static const ALCchar alcErrInvalidEnum
[] = "Invalid Enum";
165 static const ALCchar alcErrInvalidValue
[] = "Invalid Value";
166 static const ALCchar alcErrOutOfMemory
[] = "Out of Memory";
169 static ALCchar alcDeviceList
[2048];
170 static ALCchar alcAllDeviceList
[2048];
171 static ALCchar alcCaptureDeviceList
[2048];
172 // Default is always the first in the list
173 static ALCchar
*alcDefaultDeviceSpecifier
= alcDeviceList
;
174 static ALCchar
*alcDefaultAllDeviceSpecifier
= alcAllDeviceList
;
175 static ALCchar
*alcCaptureDefaultDeviceSpecifier
= alcCaptureDeviceList
;
178 static ALCchar alcExtensionList
[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX";
179 static ALCint alcMajorVersion
= 1;
180 static ALCint alcMinorVersion
= 1;
182 static ALCint alcEFXMajorVersion
= 1;
183 static ALCint alcEFXMinorVersion
= 0;
185 ///////////////////////////////////////////////////////
188 ///////////////////////////////////////////////////////
191 static ALCdevice
*g_pDeviceList
= NULL
;
192 static ALCuint g_ulDeviceCount
= 0;
194 static CRITICAL_SECTION g_csMutex
;
197 static ALCcontext
*g_pContextList
= NULL
;
198 static ALCuint g_ulContextCount
= 0;
201 static ALCenum g_eLastContextError
= ALC_NO_ERROR
;
203 static ALboolean init_done
= AL_FALSE
;
205 ///////////////////////////////////////////////////////
208 ///////////////////////////////////////////////////////
209 // ALC Related helper functions
211 BOOL APIENTRY
DllMain(HANDLE hModule
,DWORD ul_reason_for_call
,LPVOID lpReserved
)
215 // Perform actions based on the reason for calling.
216 switch(ul_reason_for_call
)
218 case DLL_PROCESS_ATTACH
:
219 DisableThreadLibraryCalls(hModule
);
222 case DLL_PROCESS_DETACH
:
231 DeleteCriticalSection(&g_csMutex
);
237 #ifdef HAVE_GCC_DESTRUCTOR
238 static void my_deinit() __attribute__((destructor
));
239 static void my_deinit()
241 static ALenum once
= AL_FALSE
;
242 if(once
|| !init_done
) return;
251 DeleteCriticalSection(&g_csMutex
);
256 static void InitAL(void)
261 const char *devs
, *str
;
265 InitializeCriticalSection(&g_csMutex
);
269 devs
= GetConfigValue(NULL
, "drivers", "");
274 const char *next
= devs
;
280 next
= strchr(devs
, ',');
282 if(!devs
[0] || devs
[0] == ',')
285 len
= (next
? ((size_t)(next
-devs
)) : strlen(devs
));
286 for(n
= i
;BackendList
[n
].Init
;n
++)
288 if(len
== strlen(BackendList
[n
].name
) &&
289 strncmp(BackendList
[n
].name
, devs
, len
) == 0)
291 const char *name
= BackendList
[i
].name
;
292 void (*Init
)(BackendFuncs
*) = BackendList
[i
].Init
;
294 BackendList
[i
].name
= BackendList
[n
].name
;
295 BackendList
[i
].Init
= BackendList
[n
].Init
;
297 BackendList
[n
].name
= name
;
298 BackendList
[n
].Init
= Init
;
305 BackendList
[i
].name
= NULL
;
306 BackendList
[i
].Init
= NULL
;
309 for(i
= 0;BackendList
[i
].Init
;i
++)
310 BackendList
[i
].Init(&BackendList
[i
].Funcs
);
312 str
= GetConfigValue(NULL
, "stereodup", "false");
313 DuplicateStereo
= (strcasecmp(str
, "true") == 0 ||
314 strcasecmp(str
, "yes") == 0 ||
315 strcasecmp(str
, "on") == 0 ||
318 str
= GetConfigValue(NULL
, "excludefx", "");
325 { "reverb", REVERB
},
331 const char *next
= str
;
335 next
= strchr(str
, ',');
337 if(!str
[0] || next
== str
)
340 len
= (next
? ((size_t)(next
-str
)) : strlen(str
));
341 for(n
= 0;EffectList
[n
].name
;n
++)
343 if(len
== strlen(EffectList
[n
].name
) &&
344 strncmp(EffectList
[n
].name
, str
, len
) == 0)
345 DisabledEffects
[EffectList
[n
].type
] = AL_TRUE
;
352 ALCchar
*AppendDeviceList(char *name
)
355 ALCchar
*ret
= alcDeviceList
+pos
;
356 if(pos
>= sizeof(alcDeviceList
))
358 AL_PRINT("Not enough room to add %s!\n", name
);
359 return alcDeviceList
+ sizeof(alcDeviceList
) - 1;
361 pos
+= snprintf(alcDeviceList
+pos
, sizeof(alcDeviceList
)-pos
-1, "%s", name
) + 1;
365 ALCchar
*AppendAllDeviceList(char *name
)
368 ALCchar
*ret
= alcAllDeviceList
+pos
;
369 if(pos
>= sizeof(alcAllDeviceList
))
371 AL_PRINT("Not enough room to add %s!\n", name
);
372 return alcAllDeviceList
+ sizeof(alcAllDeviceList
) - 1;
374 pos
+= snprintf(alcAllDeviceList
+pos
, sizeof(alcAllDeviceList
)-pos
-1, "%s", name
) + 1;
378 ALCchar
*AppendCaptureDeviceList(char *name
)
381 ALCchar
*ret
= alcCaptureDeviceList
+pos
;
382 if(pos
>= sizeof(alcCaptureDeviceList
))
384 AL_PRINT("Not enough room to add %s!\n", name
);
385 return alcCaptureDeviceList
+ sizeof(alcCaptureDeviceList
) - 1;
387 pos
+= snprintf(alcCaptureDeviceList
+pos
, sizeof(alcCaptureDeviceList
)-pos
-1, "%s", name
) + 1;
394 Check pContext is a valid Context pointer
396 static ALCboolean
IsContext(ALCcontext
*pContext
)
398 ALCcontext
*pTempContext
;
400 pTempContext
= g_pContextList
;
401 while (pTempContext
&& pTempContext
!= pContext
)
402 pTempContext
= pTempContext
->next
;
404 return (pTempContext
? ALC_TRUE
: ALC_FALSE
);
411 Store latest ALC Error
413 ALCvoid
SetALCError(ALenum errorCode
)
415 g_eLastContextError
= errorCode
;
424 ALCvoid
SuspendContext(ALCcontext
*pContext
)
427 EnterCriticalSection(&g_csMutex
);
436 ALCvoid
ProcessContext(ALCcontext
*pContext
)
439 LeaveCriticalSection(&g_csMutex
);
446 Initialize Context variables
448 static ALvoid
InitContext(ALCcontext
*pContext
)
452 //Initialise listener
453 pContext
->Listener
.Gain
= 1.0f
;
454 pContext
->Listener
.MetersPerUnit
= 1.0f
;
455 pContext
->Listener
.Position
[0] = 0.0f
;
456 pContext
->Listener
.Position
[1] = 0.0f
;
457 pContext
->Listener
.Position
[2] = 0.0f
;
458 pContext
->Listener
.Velocity
[0] = 0.0f
;
459 pContext
->Listener
.Velocity
[1] = 0.0f
;
460 pContext
->Listener
.Velocity
[2] = 0.0f
;
461 pContext
->Listener
.Forward
[0] = 0.0f
;
462 pContext
->Listener
.Forward
[1] = 0.0f
;
463 pContext
->Listener
.Forward
[2] = -1.0f
;
464 pContext
->Listener
.Up
[0] = 0.0f
;
465 pContext
->Listener
.Up
[1] = 1.0f
;
466 pContext
->Listener
.Up
[2] = 0.0f
;
469 pContext
->LastError
= AL_NO_ERROR
;
470 pContext
->InUse
= AL_FALSE
;
473 pContext
->Frequency
= pContext
->Device
->Frequency
;
476 pContext
->DistanceModel
= AL_INVERSE_DISTANCE_CLAMPED
;
477 pContext
->DopplerFactor
= 1.0f
;
478 pContext
->DopplerVelocity
= 1.0f
;
479 pContext
->flSpeedOfSound
= SPEEDOFSOUNDMETRESPERSEC
;
481 pContext
->lNumStereoSources
= 1;
482 pContext
->lNumMonoSources
= pContext
->Device
->MaxNoOfSources
- pContext
->lNumStereoSources
;
484 pContext
->AuxiliaryEffectSlotMax
= GetConfigValueInt(NULL
, "slots", 4);
485 pContext
->NumSends
= GetConfigValueInt(NULL
, "sends", MAX_SENDS
);
486 if(pContext
->NumSends
> MAX_SENDS
)
487 pContext
->NumSends
= MAX_SENDS
;
489 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";
491 level
= GetConfigValueInt(NULL
, "cf_level", 0);
492 if(level
> 0 && level
<= 6)
494 pContext
->bs2b
= calloc(1, sizeof(*pContext
->bs2b
));
495 bs2b_set_srate(pContext
->bs2b
, pContext
->Frequency
);
496 bs2b_set_level(pContext
->bs2b
, level
);
499 aluInitPanning(pContext
);
506 Clean up Context, destroy any remaining Sources
508 static ALCvoid
ExitContext(ALCcontext
*pContext
)
511 pContext
->LastError
= AL_NO_ERROR
;
512 pContext
->InUse
= AL_FALSE
;
514 free(pContext
->bs2b
);
515 pContext
->bs2b
= NULL
;
518 ///////////////////////////////////////////////////////
521 ///////////////////////////////////////////////////////
522 // ALC Functions calls
525 // This should probably move to another c file but for now ...
526 ALCAPI ALCdevice
* ALCAPIENTRY
alcCaptureOpenDevice(const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
528 ALCboolean DeviceFound
= ALC_FALSE
;
529 ALCdevice
*pDevice
= NULL
;
536 SetALCError(ALC_INVALID_VALUE
);
540 if(deviceName
&& !deviceName
[0])
543 pDevice
= malloc(sizeof(ALCdevice
));
546 //Initialise device structure
547 memset(pDevice
, 0, sizeof(ALCdevice
));
550 pDevice
->IsCaptureDevice
= AL_TRUE
;
552 pDevice
->Frequency
= frequency
;
553 pDevice
->Format
= format
;
555 for(i
= 0;BackendList
[i
].Init
;i
++)
557 pDevice
->Funcs
= &BackendList
[i
].Funcs
;
558 if(ALCdevice_OpenCapture(pDevice
, deviceName
, frequency
, format
, SampleSize
))
560 SuspendContext(NULL
);
561 pDevice
->next
= g_pDeviceList
;
562 g_pDeviceList
= pDevice
;
564 ProcessContext(NULL
);
566 DeviceFound
= ALC_TRUE
;
573 SetALCError(ALC_INVALID_VALUE
);
579 SetALCError(ALC_OUT_OF_MEMORY
);
584 ALCAPI ALCboolean ALCAPIENTRY
alcCaptureCloseDevice(ALCdevice
*pDevice
)
586 ALCboolean bReturn
= ALC_FALSE
;
589 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
591 SuspendContext(NULL
);
593 list
= &g_pDeviceList
;
594 while(*list
!= pDevice
)
595 list
= &(*list
)->next
;
597 *list
= (*list
)->next
;
600 ProcessContext(NULL
);
602 ALCdevice_CloseCapture(pDevice
);
608 SetALCError(ALC_INVALID_DEVICE
);
613 ALCAPI
void ALCAPIENTRY
alcCaptureStart(ALCdevice
*pDevice
)
615 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
616 ALCdevice_StartCapture(pDevice
);
618 SetALCError(ALC_INVALID_DEVICE
);
621 ALCAPI
void ALCAPIENTRY
alcCaptureStop(ALCdevice
*pDevice
)
623 if ((pDevice
)&&(pDevice
->IsCaptureDevice
))
624 ALCdevice_StopCapture(pDevice
);
626 SetALCError(ALC_INVALID_DEVICE
);
629 ALCAPI
void ALCAPIENTRY
alcCaptureSamples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCsizei lSamples
)
631 if ((pDevice
) && (pDevice
->IsCaptureDevice
))
632 ALCdevice_CaptureSamples(pDevice
, pBuffer
, lSamples
);
634 SetALCError(ALC_INVALID_DEVICE
);
640 Return last ALC generated error code
642 ALCAPI ALCenum ALCAPIENTRY
alcGetError(ALCdevice
*device
)
648 errorCode
= g_eLastContextError
;
649 g_eLastContextError
= ALC_NO_ERROR
;
659 ALCAPI ALCvoid ALCAPIENTRY
alcSuspendContext(ALCcontext
*pContext
)
661 // Not a lot happens here !
671 ALCAPI ALCvoid ALCAPIENTRY
alcProcessContext(ALCcontext
*pContext
)
673 // Not a lot happens here !
681 Returns information about the Device, and error strings
683 ALCAPI
const ALCchar
* ALCAPIENTRY
alcGetString(ALCdevice
*pDevice
,ALCenum param
)
685 const ALCchar
*value
= NULL
;
695 case ALC_INVALID_ENUM
:
696 value
= alcErrInvalidEnum
;
699 case ALC_INVALID_VALUE
:
700 value
= alcErrInvalidValue
;
703 case ALC_INVALID_DEVICE
:
704 value
= alcErrInvalidDevice
;
707 case ALC_INVALID_CONTEXT
:
708 value
= alcErrInvalidContext
;
711 case ALC_OUT_OF_MEMORY
:
712 value
= alcErrOutOfMemory
;
715 case ALC_DEFAULT_DEVICE_SPECIFIER
:
716 value
= alcDefaultDeviceSpecifier
;
719 case ALC_DEVICE_SPECIFIER
:
721 value
= pDevice
->szDeviceName
;
723 value
= alcDeviceList
;
726 case ALC_ALL_DEVICES_SPECIFIER
:
727 value
= alcAllDeviceList
;
730 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER
:
731 value
= alcDefaultAllDeviceSpecifier
;
734 case ALC_CAPTURE_DEVICE_SPECIFIER
:
736 value
= pDevice
->szDeviceName
;
738 value
= alcCaptureDeviceList
;
741 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
:
742 value
= alcCaptureDefaultDeviceSpecifier
;
746 value
= alcExtensionList
;
750 SetALCError(ALC_INVALID_ENUM
);
761 Returns information about the Device and the version of Open AL
763 ALCAPI ALCvoid ALCAPIENTRY
alcGetIntegerv(ALCdevice
*device
,ALCenum param
,ALsizei size
,ALCint
*data
)
767 if ((device
)&&(device
->IsCaptureDevice
))
769 SuspendContext(NULL
);
774 case ALC_CAPTURE_SAMPLES
:
775 if ((size
) && (data
))
776 *data
= ALCdevice_AvailableSamples(device
);
778 SetALCError(ALC_INVALID_VALUE
);
782 SetALCError(ALC_INVALID_ENUM
);
786 ProcessContext(NULL
);
795 case ALC_MAJOR_VERSION
:
797 SetALCError(ALC_INVALID_VALUE
);
799 *data
= alcMajorVersion
;
802 case ALC_MINOR_VERSION
:
804 SetALCError(ALC_INVALID_VALUE
);
806 *data
= alcMinorVersion
;
809 case ALC_EFX_MAJOR_VERSION
:
811 SetALCError(ALC_INVALID_VALUE
);
813 *data
= alcEFXMajorVersion
;
816 case ALC_EFX_MINOR_VERSION
:
818 SetALCError(ALC_INVALID_VALUE
);
820 *data
= alcEFXMinorVersion
;
823 case ALC_MAX_AUXILIARY_SENDS
:
825 SetALCError(ALC_INVALID_VALUE
);
826 else if(device
&& device
->Context
)
827 *data
= device
->Context
->NumSends
;
832 case ALC_ATTRIBUTES_SIZE
:
834 SetALCError(ALC_INVALID_DEVICE
);
836 SetALCError(ALC_INVALID_VALUE
);
841 case ALC_ALL_ATTRIBUTES
:
843 SetALCError(ALC_INVALID_DEVICE
);
845 SetALCError(ALC_INVALID_VALUE
);
850 data
[i
++] = ALC_FREQUENCY
;
851 data
[i
++] = device
->Frequency
;
853 data
[i
++] = ALC_REFRESH
;
854 data
[i
++] = device
->Frequency
/ device
->UpdateSize
;
856 data
[i
++] = ALC_SYNC
;
857 data
[i
++] = ALC_FALSE
;
859 SuspendContext(NULL
);
860 if(device
->Context
&& size
>= 12)
862 data
[i
++] = ALC_MONO_SOURCES
;
863 data
[i
++] = device
->Context
->lNumMonoSources
;
865 data
[i
++] = ALC_STEREO_SOURCES
;
866 data
[i
++] = device
->Context
->lNumStereoSources
;
868 data
[i
++] = ALC_MAX_AUXILIARY_SENDS
;
869 data
[i
++] = device
->Context
->NumSends
;
871 ProcessContext(NULL
);
879 SetALCError(ALC_INVALID_DEVICE
);
881 SetALCError(ALC_INVALID_VALUE
);
883 *data
= device
->Frequency
;
888 SetALCError(ALC_INVALID_DEVICE
);
890 SetALCError(ALC_INVALID_VALUE
);
892 *data
= device
->Frequency
/ device
->UpdateSize
;
897 SetALCError(ALC_INVALID_DEVICE
);
899 SetALCError(ALC_INVALID_VALUE
);
904 case ALC_MONO_SOURCES
:
905 if(!device
|| !device
->Context
)
906 SetALCError(ALC_INVALID_DEVICE
);
908 SetALCError(ALC_INVALID_VALUE
);
910 *data
= device
->Context
->lNumMonoSources
;
913 case ALC_STEREO_SOURCES
:
914 if(!device
|| !device
->Context
)
915 SetALCError(ALC_INVALID_DEVICE
);
917 SetALCError(ALC_INVALID_VALUE
);
919 *data
= device
->Context
->lNumStereoSources
;
923 SetALCError(ALC_INVALID_ENUM
);
928 SetALCError(ALC_INVALID_VALUE
);
936 alcIsExtensionPresent
938 Determines if there is support for a particular extension
940 ALCAPI ALCboolean ALCAPIENTRY
alcIsExtensionPresent(ALCdevice
*device
, const ALCchar
*extName
)
942 ALCboolean bResult
= ALC_FALSE
;
951 len
= strlen(extName
);
952 ptr
= alcExtensionList
;
955 if(strncasecmp(ptr
, extName
, len
) == 0 &&
956 (ptr
[len
] == '\0' || isspace(ptr
[len
])))
961 if((ptr
=strchr(ptr
, ' ')) != NULL
)
965 } while(isspace(*ptr
));
970 SetALCError(ALC_INVALID_VALUE
);
979 Retrieves the function address for a particular extension function
981 ALCAPI ALCvoid
* ALCAPIENTRY
alcGetProcAddress(ALCdevice
*device
, const ALCchar
*funcName
)
983 ALCvoid
*pFunction
= NULL
;
990 while(alcFunctions
[i
].funcName
&&
991 strcmp(alcFunctions
[i
].funcName
,funcName
) != 0)
993 pFunction
= alcFunctions
[i
].address
;
996 SetALCError(ALC_INVALID_VALUE
);
1005 Get the value for a particular ALC Enumerated Value
1007 ALCAPI ALCenum ALCAPIENTRY
alcGetEnumValue(ALCdevice
*device
, const ALCchar
*enumName
)
1014 while ((enumeration
[i
].enumName
)&&(strcmp(enumeration
[i
].enumName
,enumName
)))
1016 val
= enumeration
[i
].value
;
1018 if(!enumeration
[i
].enumName
)
1019 SetALCError(ALC_INVALID_VALUE
);
1028 Create and attach a Context to a particular Device.
1030 ALCAPI ALCcontext
* ALCAPIENTRY
alcCreateContext(ALCdevice
*device
, const ALCint
*attrList
)
1032 ALCcontext
*ALContext
= NULL
;
1033 ALuint ulAttributeIndex
, ulRequestedStereoSources
;
1034 ALuint RequestedSends
;
1036 if ((device
)&&(!device
->IsCaptureDevice
))
1038 // Reset Context Last Error code
1039 g_eLastContextError
= ALC_NO_ERROR
;
1041 // Current implementation only allows one Context per Device
1042 if(!device
->Context
)
1044 ALContext
= calloc(1, sizeof(ALCcontext
));
1047 SetALCError(ALC_OUT_OF_MEMORY
);
1051 ALContext
->Device
= device
;
1052 InitContext(ALContext
);
1054 device
->Context
= ALContext
;
1056 SuspendContext(NULL
);
1058 ALContext
->next
= g_pContextList
;
1059 g_pContextList
= ALContext
;
1062 ProcessContext(NULL
);
1064 // Check for attributes
1067 ulAttributeIndex
= 0;
1068 while ((ulAttributeIndex
< 10) && (attrList
[ulAttributeIndex
]))
1070 if (attrList
[ulAttributeIndex
] == ALC_STEREO_SOURCES
)
1072 ulRequestedStereoSources
= attrList
[ulAttributeIndex
+ 1];
1074 if (ulRequestedStereoSources
> ALContext
->Device
->MaxNoOfSources
)
1075 ulRequestedStereoSources
= ALContext
->Device
->MaxNoOfSources
;
1077 ALContext
->lNumStereoSources
= ulRequestedStereoSources
;
1078 ALContext
->lNumMonoSources
= ALContext
->Device
->MaxNoOfSources
- ALContext
->lNumStereoSources
;
1081 if(attrList
[ulAttributeIndex
] == ALC_MAX_AUXILIARY_SENDS
)
1083 RequestedSends
= attrList
[ulAttributeIndex
+ 1];
1085 if(RequestedSends
> ALContext
->NumSends
)
1086 RequestedSends
= ALContext
->NumSends
;
1088 ALContext
->NumSends
= RequestedSends
;
1091 ulAttributeIndex
+= 2;
1097 SetALCError(ALC_INVALID_VALUE
);
1102 SetALCError(ALC_INVALID_DEVICE
);
1113 ALCAPI ALCvoid ALCAPIENTRY
alcDestroyContext(ALCcontext
*context
)
1119 // Lock context list
1120 SuspendContext(NULL
);
1122 if (IsContext(context
))
1125 SuspendContext(context
);
1127 ReleaseALSources(context
);
1128 ReleaseALAuxiliaryEffectSlots(context
);
1130 context
->Device
->Context
= NULL
;
1132 list
= &g_pContextList
;
1133 while(*list
!= context
)
1134 list
= &(*list
)->next
;
1136 *list
= (*list
)->next
;
1140 ProcessContext(context
);
1142 ExitContext(context
);
1144 // Free memory (MUST do this after ProcessContext)
1145 memset(context
, 0, sizeof(ALCcontext
));
1149 SetALCError(ALC_INVALID_CONTEXT
);
1151 ProcessContext(NULL
);
1156 alcGetCurrentContext
1158 Returns the currently active Context
1160 ALCAPI ALCcontext
* ALCAPIENTRY
alcGetCurrentContext(ALCvoid
)
1162 ALCcontext
*pContext
= NULL
;
1166 SuspendContext(NULL
);
1168 pContext
= g_pContextList
;
1169 while ((pContext
) && (!pContext
->InUse
))
1170 pContext
= pContext
->next
;
1172 ProcessContext(NULL
);
1179 alcGetContextsDevice
1181 Returns the Device that a particular Context is attached to
1183 ALCAPI ALCdevice
* ALCAPIENTRY
alcGetContextsDevice(ALCcontext
*pContext
)
1185 ALCdevice
*pDevice
= NULL
;
1189 SuspendContext(NULL
);
1190 if (IsContext(pContext
))
1191 pDevice
= pContext
->Device
;
1193 SetALCError(ALC_INVALID_CONTEXT
);
1194 ProcessContext(NULL
);
1201 alcMakeContextCurrent
1203 Makes the given Context the active Context
1205 ALCAPI ALCboolean ALCAPIENTRY
alcMakeContextCurrent(ALCcontext
*context
)
1207 ALCcontext
*ALContext
;
1208 ALboolean bReturn
= AL_TRUE
;
1212 SuspendContext(NULL
);
1214 // context must be a valid Context or NULL
1215 if ((IsContext(context
)) || (context
== NULL
))
1217 if ((ALContext
=alcGetCurrentContext()))
1219 SuspendContext(ALContext
);
1220 ALContext
->InUse
=AL_FALSE
;
1221 ProcessContext(ALContext
);
1224 if ((ALContext
=context
) && (ALContext
->Device
))
1226 SuspendContext(ALContext
);
1227 ALContext
->InUse
=AL_TRUE
;
1228 ProcessContext(ALContext
);
1233 SetALCError(ALC_INVALID_CONTEXT
);
1237 ProcessContext(NULL
);
1246 Open the Device specified.
1248 ALCAPI ALCdevice
* ALCAPIENTRY
alcOpenDevice(const ALCchar
*deviceName
)
1250 ALboolean bDeviceFound
= AL_FALSE
;
1256 if(deviceName
&& !deviceName
[0])
1259 device
= malloc(sizeof(ALCdevice
));
1264 //Initialise device structure
1265 memset(device
, 0, sizeof(ALCdevice
));
1268 device
->IsCaptureDevice
= AL_FALSE
;
1271 device
->Frequency
= GetConfigValueInt(NULL
, "frequency", SWMIXER_OUTPUT_RATE
);
1272 if((ALint
)device
->Frequency
<= 0)
1273 device
->Frequency
= SWMIXER_OUTPUT_RATE
;
1275 fmt
= GetConfigValue(NULL
, "format", "AL_FORMAT_STEREO16");
1277 device
->Format
= alGetEnumValue(fmt
);
1279 if(!aluChannelsFromFormat(device
->Format
))
1280 device
->Format
= AL_FORMAT_STEREO16
;
1282 device
->UpdateSize
= GetConfigValueInt(NULL
, "refresh", 4096);
1283 if((ALint
)device
->UpdateSize
<= 0)
1284 device
->UpdateSize
= 4096;
1286 device
->MaxNoOfSources
= GetConfigValueInt(NULL
, "sources", 256);
1287 if((ALint
)device
->MaxNoOfSources
<= 0)
1288 device
->MaxNoOfSources
= 256;
1290 // Find a playback device to open
1291 SuspendContext(NULL
);
1292 for(i
= 0;BackendList
[i
].Init
;i
++)
1294 device
->Funcs
= &BackendList
[i
].Funcs
;
1295 if(ALCdevice_OpenPlayback(device
, deviceName
))
1297 device
->next
= g_pDeviceList
;
1298 g_pDeviceList
= device
;
1301 bDeviceFound
= AL_TRUE
;
1305 ProcessContext(NULL
);
1309 // No suitable output device found
1310 SetALCError(ALC_INVALID_VALUE
);
1316 SetALCError(ALC_OUT_OF_MEMORY
);
1325 Close the specified Device
1327 ALCAPI ALCboolean ALCAPIENTRY
alcCloseDevice(ALCdevice
*pDevice
)
1329 ALCboolean bReturn
= ALC_FALSE
;
1332 if ((pDevice
)&&(!pDevice
->IsCaptureDevice
))
1334 SuspendContext(NULL
);
1336 list
= &g_pDeviceList
;
1337 while(*list
!= pDevice
)
1338 list
= &(*list
)->next
;
1340 *list
= (*list
)->next
;
1343 ProcessContext(NULL
);
1345 if(pDevice
->Context
)
1348 AL_PRINT("alcCloseDevice(): destroying 1 Context\n");
1350 alcDestroyContext(pDevice
->Context
);
1352 ALCdevice_ClosePlayback(pDevice
);
1354 //Release device structure
1355 memset(pDevice
, 0, sizeof(ALCdevice
));
1361 SetALCError(ALC_INVALID_DEVICE
);
1367 ALCvoid
ReleaseALC(ALCvoid
)
1370 if(g_ulDeviceCount
> 0)
1371 AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount
, (g_ulDeviceCount
>1)?"s":"");
1374 while(g_pDeviceList
)
1376 if(g_pDeviceList
->IsCaptureDevice
)
1377 alcCaptureCloseDevice(g_pDeviceList
);
1379 alcCloseDevice(g_pDeviceList
);
1383 ///////////////////////////////////////////////////////