void SFXALProvider::init() { if( LoadOAL10Library( NULL, &mOpenAL ) != AL_TRUE ) { Con::printf( "SFXALProvider - OpenAL not available." ); return; } mALDL = new ALDeviceList( mOpenAL ); // Did we get any devices? if ( mALDL->GetNumDevices() < 1 ) { Con::printf( "SFXALProvider - No valid devices found!" ); return; } // Cool, loop through them, and caps em const char *deviceFormat = "OpenAL v%d.%d %s"; char temp[256]; for( S32 i = 0; i < mALDL->GetNumDevices(); i++ ) { ALDeviceInfo* info = new ALDeviceInfo; info->name = String( mALDL->GetDeviceName( i ) ); S32 major, minor, eax = 0; mALDL->GetDeviceVersion( i, &major, &minor ); // Apologies for the blatent enum hack -patw for( S32 j = SFXALEAX2; j < SFXALEAXRAM; j++ ) eax += (int)mALDL->IsExtensionSupported( i, (SFXALCaps)j ); if( eax > 0 ) { eax += 2; // EAX support starts at 2.0 dSprintf( temp, sizeof( temp ), "[EAX %d.0] %s", eax, ( mALDL->IsExtensionSupported( i, SFXALEAXRAM ) ? "EAX-RAM" : "" ) ); } else dStrcpy( temp, "" ); info->driver = String::ToString( deviceFormat, major, minor, temp ); info->hasHardware = eax > 0; info->maxBuffers = mALDL->GetMaxNumSources( i ); mDeviceInfo.push_back( info ); } regProvider( this ); }
/* * Init call */ ALDeviceList::ALDeviceList() { ALDEVICEINFO ALDeviceInfo; char *devices; int index; const char *defaultDeviceName; const char *actualDeviceName; // DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support vDeviceInfo.empty(); vDeviceInfo.reserve(10); defaultDeviceIndex = 0; // grab function pointers for 1.0-API functions, and if successful proceed to enumerate all devices if (LoadOAL10Library(NULL, &ALFunction) == TRUE) { if (ALFunction.alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) { devices = (char *)ALFunction.alcGetString(NULL, ALC_DEVICE_SPECIFIER); defaultDeviceName = (char *)ALFunction.alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); index = 0; // go through device list (each device terminated with a single NULL, list terminated with double NULL) while (*devices != NULL) { if (strcmp(defaultDeviceName, devices) == 0) { defaultDeviceIndex = index; } ALCdevice *device = ALFunction.alcOpenDevice(devices); if (device) { ALCcontext *context = ALFunction.alcCreateContext(device, NULL); if (context) { ALFunction.alcMakeContextCurrent(context); // if new actual device name isn't already in the list, then add it... actualDeviceName = ALFunction.alcGetString(device, ALC_DEVICE_SPECIFIER); bool bNewName = true; for (int i = 0; i < GetNumDevices(); i++) { if (strcmp(GetDeviceName(i), actualDeviceName) == 0) { bNewName = false; } } if ((bNewName) && (actualDeviceName != NULL) && (strlen(actualDeviceName) > 0)) { memset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO)); ALDeviceInfo.bSelected = true; ALDeviceInfo.strDeviceName = actualDeviceName; ALFunction.alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion); ALFunction.alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion); ALDeviceInfo.pvstrExtensions = new vector<string>; // Check for ALC Extensions if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_CAPTURE") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("ALC_EXT_CAPTURE"); if (ALFunction.alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("ALC_EXT_EFX"); // Check for AL Extensions if (ALFunction.alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_OFFSET"); if (ALFunction.alIsExtensionPresent("AL_EXT_LINEAR_DISTANCE") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_LINEAR_DISTANCE"); if (ALFunction.alIsExtensionPresent("AL_EXT_EXPONENT_DISTANCE") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_EXPONENT_DISTANCE"); if (ALFunction.alIsExtensionPresent("EAX2.0") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("EAX2.0"); if (ALFunction.alIsExtensionPresent("EAX3.0") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("EAX3.0"); if (ALFunction.alIsExtensionPresent("EAX4.0") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("EAX4.0"); if (ALFunction.alIsExtensionPresent("EAX5.0") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("EAX5.0"); if (ALFunction.alIsExtensionPresent("EAX-RAM") == AL_TRUE) ALDeviceInfo.pvstrExtensions->push_back("EAX-RAM"); // Get Source Count ALDeviceInfo.uiSourceCount = GetMaxNumSources(); vDeviceInfo.push_back(ALDeviceInfo); } ALFunction.alcMakeContextCurrent(NULL); ALFunction.alcDestroyContext(context); } ALFunction.alcCloseDevice(device); } devices += strlen(devices) + 1; index += 1; } } } ResetFilters(); }