// initializes hardware device from perferred/default/enumerated list bool openal_init_device(SCP_string *playback, SCP_string *capture) { if ( !Playback_device.empty() ) { if (playback) { *playback = Playback_device; } if (capture) { *capture = Capture_device; } return true; } if (playback) { playback->erase(); } if (capture) { capture->erase(); } // This reuses the code for the launcher to make sure everything is consistent auto platform_info = openal_get_platform_information(); if (platform_info.version_major <= 1 && platform_info.version_minor < 1) { os::dialogs::Message(os::dialogs::MESSAGEBOX_ERROR, "OpenAL 1.1 or newer is required for proper operation. On Linux and Windows OpenAL Soft is recommended. If you are on Mac OS X you need to upgrade your OS."); return false; } // go through and find out what devices we actually want to use ... find_playback_device(&platform_info); find_capture_device(&platform_info); if ( Playback_device.empty() ) { return false; } #ifndef NDEBUG if ( !PlaybackDevices.empty() ) { nprintf(("OpenAL", " Available Playback Devices:\n")); for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) { nprintf(("OpenAL", " %s", PlaybackDevices[idx].device_name.c_str())); if (PlaybackDevices[idx].type == OAL_DEVICE_USER) { nprintf(("OpenAL", " *preferred*\n")); } else if (PlaybackDevices[idx].type == OAL_DEVICE_DEFAULT) { nprintf(("OpenAL", " *default*\n")); } else { nprintf(("OpenAL", "\n")); } } } if ( !CaptureDevices.empty() ) { if ( !PlaybackDevices.empty() ) { nprintf(("OpenAL", "\n")); } nprintf(("OpenAL", " Available Capture Devices:\n")); for (size_t idx = 0; idx < CaptureDevices.size(); idx++) { nprintf(("OpenAL", " %s", CaptureDevices[idx].device_name.c_str())); if (CaptureDevices[idx].type == OAL_DEVICE_USER) { nprintf(("OpenAL", " *preferred*\n")); } else if (CaptureDevices[idx].type == OAL_DEVICE_DEFAULT) { nprintf(("OpenAL", " *default*\n")); } else { nprintf(("OpenAL", "\n")); } } nprintf(("OpenAL", "\n")); } #endif // cleanup PlaybackDevices.clear(); CaptureDevices.clear(); if (playback) { *playback = Playback_device; } if (capture) { *capture = Capture_device; } return true; }
// initializes hardware device from perferred/default/enumerated list bool openal_init_device(SCP_string *playback, SCP_string *capture) { if ( !Playback_device.empty() ) { if (playback) { *playback = Playback_device; } if (capture) { *capture = Capture_device; } return true; } if (playback) { playback->erase(); } if (capture) { capture->erase(); } // initialize default setup first, for version check... ALCdevice *device = alcOpenDevice(NULL); if (device == NULL) { return false; } ALCcontext *context = alcCreateContext(device, NULL); if (context == NULL) { alcCloseDevice(device); return false; } alcMakeContextCurrent(context); // version check (for 1.0 or 1.1) ALCint AL_minor_version = 0; alcGetIntegerv(NULL, ALC_MINOR_VERSION, sizeof(ALCint), &AL_minor_version); if (AL_minor_version < 1) { #ifdef _WIN32 MessageBox(NULL, "OpenAL 1.1 or newer is required for proper operation. Please upgrade your OpenAL drivers, which\nare available at http://www.openal.org/downloads.html, and try running the game again.", NULL, MB_OK); #else printf("OpenAL 1.1 or newer is required for proper operation.\n"); printf("Please upgrade to a newer version if on OS X or switch\n"); printf("to OpenAL-Soft on Linux.\n"); #endif alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); return false; } alcGetError(device); // close default device alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); // go through and find out what devices we actually want to use ... find_playback_device(); find_capture_device(); if ( Playback_device.empty() ) { return false; } #ifndef NDEBUG if ( !PlaybackDevices.empty() ) { nprintf(("OpenAL", " Available Playback Devices:\n")); for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) { nprintf(("OpenAL", " %s", PlaybackDevices[idx].device_name.c_str())); if (PlaybackDevices[idx].type == OAL_DEVICE_USER) { nprintf(("OpenAL", " *preferred*\n")); } else if (PlaybackDevices[idx].type == OAL_DEVICE_DEFAULT) { nprintf(("OpenAL", " *default*\n")); } else { nprintf(("OpenAL", "\n")); } } } if ( !CaptureDevices.empty() ) { if ( !PlaybackDevices.empty() ) { nprintf(("OpenAL", "\n")); } nprintf(("OpenAL", " Available Capture Devices:\n")); for (size_t idx = 0; idx < CaptureDevices.size(); idx++) { nprintf(("OpenAL", " %s", CaptureDevices[idx].device_name.c_str())); if (CaptureDevices[idx].type == OAL_DEVICE_USER) { nprintf(("OpenAL", " *preferred*\n")); } else if (CaptureDevices[idx].type == OAL_DEVICE_DEFAULT) { nprintf(("OpenAL", " *default*\n")); } else { nprintf(("OpenAL", "\n")); } } nprintf(("OpenAL", "\n")); } #endif // cleanup PlaybackDevices.clear(); CaptureDevices.clear(); if (playback) { *playback = Playback_device; } if (capture) { *capture = Capture_device; } return true; }
// initializes hardware device from perferred/default/enumerated list bool openal_init_device(SCP_string *playback, SCP_string *capture) { if ( !Playback_device.empty() ) { if (playback) { *playback = Playback_device; } if (capture) { *capture = Capture_device; } return true; } if (playback) { playback->erase(); } if (capture) { capture->erase(); } // initialize default setup first, for version check... ALCdevice *device = alcOpenDevice(NULL); if (device == NULL) { return false; } ALCcontext *context = alcCreateContext(device, NULL); if (context == NULL) { alcCloseDevice(device); return false; } alcMakeContextCurrent(context); // version check (for 1.0 or 1.1) ALCint AL_minor_version = 0; alcGetIntegerv(NULL, ALC_MINOR_VERSION, sizeof(ALCint), &AL_minor_version); if (AL_minor_version < 1) { os::dialogs::Message(os::dialogs::MESSAGEBOX_ERROR, "OpenAL 1.1 or newer is required for proper operation. On Linux and Windows OpenAL Soft is recommended. If you are on Mac OS X you need to upgrade your OS."); alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); return false; } alcGetError(device); // close default device alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); // go through and find out what devices we actually want to use ... find_playback_device(); find_capture_device(); if ( Playback_device.empty() ) { return false; } #ifndef NDEBUG if ( !PlaybackDevices.empty() ) { nprintf(("OpenAL", " Available Playback Devices:\n")); for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) { nprintf(("OpenAL", " %s", PlaybackDevices[idx].device_name.c_str())); if (PlaybackDevices[idx].type == OAL_DEVICE_USER) { nprintf(("OpenAL", " *preferred*\n")); } else if (PlaybackDevices[idx].type == OAL_DEVICE_DEFAULT) { nprintf(("OpenAL", " *default*\n")); } else { nprintf(("OpenAL", "\n")); } } } if ( !CaptureDevices.empty() ) { if ( !PlaybackDevices.empty() ) { nprintf(("OpenAL", "\n")); } nprintf(("OpenAL", " Available Capture Devices:\n")); for (size_t idx = 0; idx < CaptureDevices.size(); idx++) { nprintf(("OpenAL", " %s", CaptureDevices[idx].device_name.c_str())); if (CaptureDevices[idx].type == OAL_DEVICE_USER) { nprintf(("OpenAL", " *preferred*\n")); } else if (CaptureDevices[idx].type == OAL_DEVICE_DEFAULT) { nprintf(("OpenAL", " *default*\n")); } else { nprintf(("OpenAL", "\n")); } } nprintf(("OpenAL", "\n")); } #endif // cleanup PlaybackDevices.clear(); CaptureDevices.clear(); if (playback) { *playback = Playback_device; } if (capture) { *capture = Capture_device; } return true; }