OpenAL enumeration fix

Openal enumeration after default device loading.
This commit is contained in:
marauder2k7 2022-08-14 10:36:02 +01:00
parent 3e88e2acb8
commit d02f5da414
2 changed files with 133 additions and 46 deletions

View file

@ -36,17 +36,17 @@
/* /*
* Init call * Init call
*/ */
ALDeviceList::ALDeviceList( const OPENALFNTABLE &oalft ) ALDeviceList::ALDeviceList(const OPENALFNTABLE& oalft)
{ {
VECTOR_SET_ASSOCIATION( vDeviceInfo ); VECTOR_SET_ASSOCIATION(vDeviceInfo);
ALDEVICEINFO ALDeviceInfo; ALDEVICEINFO ALDeviceInfo;
char *devices; char* devices;
int index; int index;
const char *defaultDeviceName; const char* defaultDeviceName;
const char *actualDeviceName; const char* actualDeviceName;
dMemcpy( &ALFunction, &oalft, sizeof( OPENALFNTABLE ) ); dMemcpy(&ALFunction, &oalft, sizeof(OPENALFNTABLE));
// DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support // DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support
vDeviceInfo.clear(); vDeviceInfo.clear();
@ -54,70 +54,69 @@ ALDeviceList::ALDeviceList( const OPENALFNTABLE &oalft )
defaultDeviceIndex = 0; defaultDeviceIndex = 0;
// grab function pointers for 1.0-API functions, and if successful proceed to enumerate all devices if (ALFunction.alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
const bool enumerationExtensionPresent = ALFunction.alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"); {
const bool enumerateAllExtensionPresent = ALFunction.alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"); devices = (char*)ALFunction.alcGetString(NULL, ALC_DEVICE_SPECIFIER);
if (enumerateAllExtensionPresent || enumerationExtensionPresent) { defaultDeviceName = (char*)ALFunction.alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
if (enumerateAllExtensionPresent)
{
devices = (char *)ALFunction.alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
defaultDeviceName = (char *)ALFunction.alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
}
else
{
devices = (char *)ALFunction.alcGetString(NULL, ALC_DEVICE_SPECIFIER);
defaultDeviceName = (char *)ALFunction.alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
}
index = 0; index = 0;
// go through device list (each device terminated with a single NULL, list terminated with double NULL) while (*devices != NULL)
while (*devices != 0) { {
if (String::compare(defaultDeviceName, devices) == 0) { if (dStrcmp(defaultDeviceName, devices) == 0)
{
defaultDeviceIndex = index; defaultDeviceIndex = index;
} }
ALCdevice *device = ALFunction.alcOpenDevice(devices); ALCdevice* device = ALFunction.alcOpenDevice(devices);
if (device) {
ALCcontext *context = ALFunction.alcCreateContext(device, NULL); if (device)
if (context) { {
ALCcontext* context = ALFunction.alcCreateContext(device, NULL);
if (context)
{
ALFunction.alcMakeContextCurrent(context); ALFunction.alcMakeContextCurrent(context);
// if new actual device name isn't already in the list, then add it...
actualDeviceName = devices; actualDeviceName = ALFunction.alcGetString(device, ALC_DEVICE_SPECIFIER);
bool bNewName = true; bool bNewName = true;
for (int i = 0; i < GetNumDevices(); i++) { for (int i = 0; i < GetNumDevices(); i++) {
if (String::compare(GetDeviceName(i), actualDeviceName) == 0) { if (dStrcmp(GetDeviceName(i), actualDeviceName) == 0) {
bNewName = false; bNewName = false;
} }
} }
if ((bNewName) && (actualDeviceName != NULL) && (dStrlen(actualDeviceName) > 0)) {
if ((bNewName) && (actualDeviceName != NULL) && (dStrlen(actualDeviceName) > 0))
{
dMemset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO)); dMemset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO));
ALDeviceInfo.bSelected = true; ALDeviceInfo.bSelected = true;
dStrncpy(ALDeviceInfo.strDeviceName, actualDeviceName, sizeof(ALDeviceInfo.strDeviceName)); dStrncpy(ALDeviceInfo.strDeviceName, actualDeviceName, sizeof(ALDeviceInfo.strDeviceName));
ALFunction.alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion); ALFunction.alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion);
ALFunction.alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion); ALFunction.alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion);
ALDeviceInfo.iCapsFlags = 0; ALDeviceInfo.iCapsFlags = 0;
// Check for ALC Extensions
if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_CAPTURE") == AL_TRUE) if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_CAPTURE") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALCapture; ALDeviceInfo.iCapsFlags |= SFXALCapture;
if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_TRUE) if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEFX; ALDeviceInfo.iCapsFlags |= SFXALEFX;
// Check for AL Extensions
if (ALFunction.alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE) if (ALFunction.alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALOffset; ALDeviceInfo.iCapsFlags |= SFXALOffset;
if (ALFunction.alIsExtensionPresent("AL_EXT_LINEAR_DISTANCE") == AL_TRUE) if (ALFunction.alIsExtensionPresent("AL_EXT_LINEAR_DISTANCE") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALLinearDistance; ALDeviceInfo.iCapsFlags |= SFXALLinearDistance;
if (ALFunction.alIsExtensionPresent("AL_EXT_EXPONENT_DISTANCE") == AL_TRUE) if (ALFunction.alIsExtensionPresent("AL_EXT_EXPONENT_DISTANCE") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALExponentDistance; ALDeviceInfo.iCapsFlags |= SFXALExponentDistance;
if (ALFunction.alIsExtensionPresent("EAX2.0") == AL_TRUE) if (ALFunction.alIsExtensionPresent("EAX2.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX2; ALDeviceInfo.iCapsFlags |= SFXALEAX2;
if (ALFunction.alIsExtensionPresent("EAX3.0") == AL_TRUE) if (ALFunction.alIsExtensionPresent("EAX3.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX3; ALDeviceInfo.iCapsFlags |= SFXALEAX3;
if (ALFunction.alIsExtensionPresent("EAX4.0") == AL_TRUE) if (ALFunction.alIsExtensionPresent("EAX4.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX4; ALDeviceInfo.iCapsFlags |= SFXALEAX4;
if (ALFunction.alIsExtensionPresent("EAX5.0") == AL_TRUE) if (ALFunction.alIsExtensionPresent("EAX5.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX5; ALDeviceInfo.iCapsFlags |= SFXALEAX5;
@ -128,6 +127,94 @@ ALDeviceList::ALDeviceList( const OPENALFNTABLE &oalft )
ALDeviceInfo.uiSourceCount = GetMaxNumSources(); ALDeviceInfo.uiSourceCount = GetMaxNumSources();
vDeviceInfo.push_back(ALDeviceInfo); vDeviceInfo.push_back(ALDeviceInfo);
}
ALFunction.alcMakeContextCurrent(NULL);
ALFunction.alcDestroyContext(context);
}
ALFunction.alcCloseDevice(device);
}
devices += dStrlen(devices) + 1;
index += 1;
}
}
index = 0;
if (ALFunction.alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
{
devices = (char*)ALFunction.alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
defaultDeviceName = (char*)ALFunction.alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
index = 0;
while (*devices != NULL)
{
if (dStrcmp(defaultDeviceName, devices) == 0)
{
defaultDeviceIndex = index;
}
ALCdevice* device = ALFunction.alcOpenDevice(devices);
if (device)
{
ALCcontext* context = ALFunction.alcCreateContext(device, NULL);
if (context)
{
ALFunction.alcMakeContextCurrent(context);
actualDeviceName = ALFunction.alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
bool bNewName = true;
for (int i = 0; i < GetNumDevices(); i++) {
if (dStrcmp(GetDeviceName(i), actualDeviceName) == 0) {
bNewName = false;
}
}
if ((bNewName) && (actualDeviceName != NULL) && (dStrlen(actualDeviceName) > 0))
{
dMemset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO));
ALDeviceInfo.bSelected = true;
dStrncpy(ALDeviceInfo.strDeviceName, actualDeviceName, sizeof(ALDeviceInfo.strDeviceName));
ALFunction.alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion);
ALFunction.alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion);
ALDeviceInfo.iCapsFlags = 0;
if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_CAPTURE") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALCapture;
if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEFX;
if (ALFunction.alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALOffset;
if (ALFunction.alIsExtensionPresent("AL_EXT_LINEAR_DISTANCE") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALLinearDistance;
if (ALFunction.alIsExtensionPresent("AL_EXT_EXPONENT_DISTANCE") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALExponentDistance;
if (ALFunction.alIsExtensionPresent("EAX2.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX2;
if (ALFunction.alIsExtensionPresent("EAX3.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX3;
if (ALFunction.alIsExtensionPresent("EAX4.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX4;
if (ALFunction.alIsExtensionPresent("EAX5.0") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAX5;
if (ALFunction.alIsExtensionPresent("EAX-RAM") == AL_TRUE)
ALDeviceInfo.iCapsFlags |= SFXALEAXRAM;
// Get Source Count
ALDeviceInfo.uiSourceCount = GetMaxNumSources();
vDeviceInfo.push_back(ALDeviceInfo);
} }
ALFunction.alcMakeContextCurrent(NULL); ALFunction.alcMakeContextCurrent(NULL);
ALFunction.alcDestroyContext(context); ALFunction.alcDestroyContext(context);

View file

@ -31,11 +31,11 @@
typedef struct typedef struct
{ {
char strDeviceName[256]; char strDeviceName[256];
S32 iMajorVersion; S32 iMajorVersion;
S32 iMinorVersion; S32 iMinorVersion;
U32 uiSourceCount; U32 uiSourceCount;
S32 iCapsFlags; S32 iCapsFlags;
bool bSelected; bool bSelected;
} ALDEVICEINFO, *LPALDEVICEINFO; } ALDEVICEINFO, *LPALDEVICEINFO;