46 #ifndef ALC_ALL_DEVICES_SPECIFIER
47 #define ALC_ALL_DEVICES_SPECIFIER 0x1013
61 ALCdevice *device = alcGetContextsDevice( alcGetCurrentContext() );
63 i = alcGetError(device);
65 if ( i != ALC_NO_ERROR )
66 return (
const char*) alcGetString(device, i);
71 if ( i != AL_NO_ERROR )
72 return (
const char*)alGetString(i);
82 if ( (n_channels < 1) || (n_channels > 2) ) {
92 format = (n_channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
96 format = (n_channels == 1) ? AL_FORMAT_MONO8 : AL_FORMAT_STEREO8;
112 static void find_playback_device()
115 const char *default_device = (
const char*) alcGetString( NULL, ALC_DEFAULT_DEVICE_SPECIFIER );
118 if ( (user_device && default_device) && !strcmp(user_device, default_device) ) {
122 if ( alcIsExtensionPresent(NULL, (
const ALCchar*)
"ALC_ENUMERATION_EXT") == AL_TRUE ) {
123 const char *all_devices = NULL;
125 if ( alcIsExtensionPresent(NULL, (
const ALCchar*)
"ALC_ENUMERATE_ALL_EXT") == AL_TRUE ) {
128 all_devices = (
const char*) alcGetString(NULL, ALC_DEVICE_SPECIFIER);
131 const char *str_list = all_devices;
134 if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) {
138 if (user_device && !strcmp(str_list, user_device)) {
140 }
else if (default_device && !strcmp(str_list, default_device)) {
144 PlaybackDevices.push_back( new_device );
146 str_list += (ext_length + 1);
147 ext_length = strlen(str_list);
151 if (default_device) {
155 PlaybackDevices.push_back( new_device );
162 PlaybackDevices.push_back( new_device );
166 if ( PlaybackDevices.empty() ) {
170 std::sort( PlaybackDevices.begin(), PlaybackDevices.end(), openal_device_sort_func );
173 ALCdevice *device = NULL;
174 ALCcontext *context = NULL;
177 for (
size_t idx = 0;
idx < PlaybackDevices.size();
idx++) {
181 device = alcOpenDevice( (
const ALCchar*) pdev->
device_name.c_str() );
183 if (device == NULL) {
187 context = alcCreateContext(device, NULL);
189 if (context == NULL) {
190 alcCloseDevice(device);
194 alcMakeContextCurrent(context);
198 static const int MIN_SOURCES = 48;
201 for (si = 0; si < MIN_SOURCES; si++) {
202 ALuint source_id = 0;
203 alGenSources(1, &source_id);
205 if (alGetError() != AL_NO_ERROR) {
209 alDeleteSources(1, &source_id);
212 if (si == MIN_SOURCES) {
223 alcMakeContextCurrent(NULL);
224 alcDestroyContext(context);
225 alcCloseDevice(device);
232 alcMakeContextCurrent(NULL);
235 alcDestroyContext(context);
239 alcCloseDevice(device);
243 static void find_capture_device()
246 const char *default_device = (
const char*) alcGetString( NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER );
249 if ( (user_device && default_device) && !strcmp(user_device, default_device) ) {
253 if ( alcIsExtensionPresent(NULL, (
const ALCchar*)
"ALC_ENUMERATION_EXT") == AL_TRUE ) {
254 const char *all_devices = (
const char*) alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
256 const char *str_list = all_devices;
259 if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) {
263 if (user_device && !strcmp(str_list, user_device)) {
265 }
else if (default_device && !strcmp(str_list, default_device)) {
269 CaptureDevices.push_back( new_device );
271 str_list += (ext_length + 1);
272 ext_length = strlen(str_list);
276 if (default_device) {
280 CaptureDevices.push_back( new_device );
287 CaptureDevices.push_back( new_device );
291 if ( CaptureDevices.empty() ) {
295 std::sort( CaptureDevices.begin(), CaptureDevices.end(), openal_device_sort_func );
299 for (
size_t idx = 0;
idx < CaptureDevices.size();
idx++) {
300 const ALCchar *device_name = CaptureDevices[
idx].device_name.c_str();
302 ALCdevice *device = alcCaptureOpenDevice(device_name, 22050, AL_FORMAT_MONO8, 22050 * 2);
304 if (device == NULL) {
308 if (alcGetError(device) != ALC_NO_ERROR) {
309 alcCaptureCloseDevice(device);
314 Capture_device = CaptureDevices[
idx].device_name;
316 alcCaptureCloseDevice(device);
325 if ( !Playback_device.empty() ) {
327 *playback = Playback_device;
331 *capture = Capture_device;
347 ALCdevice *device = alcOpenDevice(NULL);
349 if (device == NULL) {
353 ALCcontext *context = alcCreateContext(device, NULL);
355 if (context == NULL) {
356 alcCloseDevice(device);
360 alcMakeContextCurrent(context);
363 ALCint AL_minor_version = 0;
364 alcGetIntegerv(NULL, ALC_MINOR_VERSION,
sizeof(ALCint), &AL_minor_version);
366 if (AL_minor_version < 1) {
368 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);
370 printf(
"OpenAL 1.1 or newer is required for proper operation.\n");
371 printf(
"Please upgrade to a newer version if on OS X or switch\n");
372 printf(
"to OpenAL-Soft on Linux.\n");
375 alcMakeContextCurrent(NULL);
376 alcDestroyContext(context);
377 alcCloseDevice(device);
385 alcMakeContextCurrent(NULL);
386 alcDestroyContext(context);
387 alcCloseDevice(device);
391 find_playback_device();
392 find_capture_device();
394 if ( Playback_device.empty() ) {
400 if ( !PlaybackDevices.empty() ) {
401 nprintf((
"OpenAL",
" Available Playback Devices:\n"));
403 for (
size_t idx = 0;
idx < PlaybackDevices.size();
idx++) {
404 nprintf((
"OpenAL",
" %s", PlaybackDevices[
idx].device_name.c_str()));
407 nprintf((
"OpenAL",
" *preferred*\n"));
409 nprintf((
"OpenAL",
" *default*\n"));
416 if ( !CaptureDevices.empty() ) {
417 if ( !PlaybackDevices.empty() ) {
421 nprintf((
"OpenAL",
" Available Capture Devices:\n"));
423 for (
size_t idx = 0;
idx < CaptureDevices.size();
idx++) {
424 nprintf((
"OpenAL",
" %s", CaptureDevices[
idx].device_name.c_str()));
427 nprintf((
"OpenAL",
" *preferred*\n"));
429 nprintf((
"OpenAL",
" *default*\n"));
441 PlaybackDevices.clear();
442 CaptureDevices.clear();
446 *playback = Playback_device;
450 *capture = Capture_device;
GLenum GLsizei GLenum format
struct OALdevice OALdevice
ALuint *typedef ALuint *typedef ALenum
const char * os_config_read_string(const char *section, const char *name, const char *default_value)
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
ALuint *typedef ALuint *typedef ALint
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
#define AL_FORMAT_STEREO_FLOAT32
GLuint const GLchar * name
OALdevice(const char *name)
ALenum openal_get_format(ALint bits, ALint n_channels)
int MessageBox(HWND h, const char *s1, const char *s2, int i)
bool openal_init_device(SCP_string *playback, SCP_string *capture)
const char * openal_error_string(int get_alc)
#define ALC_ALL_DEVICES_SPECIFIER
#define AL_FORMAT_MONO_FLOAT32