Add the reverb room rolloff to the source room rolloff, not override
[openal-soft/openal-hmr.git] / examples / openal-info.c
blobee4021c112dbc18244d6bcf880973332d6420323
1 /*
2 * openal-info: Display information about ALC and AL.
4 * Idea based on glxinfo for OpenGL.
5 * Initial OpenAL version by Erik Hofman <erik@ehofman.com>.
6 * Further hacked by Sven Panne <sven.panne@aedion.de>.
7 * More work (clean up) by Chris Robinson <chris.kcat@gmail.com>.
9 */
11 #if HAVE_CONFIG_H
12 #include "config.h"
13 #endif
15 #include <stdio.h>
16 #include <stdlib.h>
18 #include "AL/alc.h"
19 #include "AL/al.h"
20 #include "AL/alext.h"
23 static const int indentation = 4;
24 static const int maxmimumWidth = 79;
26 static void printChar(int c, int *width)
28 putchar(c);
29 *width = ((c == '\n') ? 0 : ((*width) + 1));
32 static void indent(int *width)
34 int i;
35 for(i = 0; i < indentation; i++)
36 printChar(' ', width);
39 static void printExtensions(const char *header, char separator, const char *extensions)
41 int width = 0, start = 0, end = 0;
43 printf("%s:\n", header);
44 if(extensions == NULL || extensions[0] == '\0')
45 return;
47 indent(&width);
48 while (1)
50 if(extensions[end] == separator || extensions[end] == '\0')
52 if(width + end - start + 2 > maxmimumWidth)
54 printChar('\n', &width);
55 indent(&width);
57 while(start < end)
59 printChar(extensions[start], &width);
60 start++;
62 if(extensions[end] == '\0')
63 break;
64 start++;
65 end++;
66 if(extensions[end] == '\0')
67 break;
68 printChar(',', &width);
69 printChar(' ', &width);
71 end++;
73 printChar('\n', &width);
76 static void die(const char *kind, const char *description)
78 fprintf(stderr, "%s error %s occured\n", kind, description);
79 exit(EXIT_FAILURE);
82 static void checkForErrors(void)
85 ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext());
86 ALCenum error = alcGetError(device);
87 if(error != ALC_NO_ERROR)
88 die("ALC", (const char*)alcGetString(device, error));
91 ALenum error = alGetError();
92 if(error != AL_NO_ERROR)
93 die("AL", (const char*)alGetString(error));
97 static void printDevices(ALCenum which, const char *kind)
99 const char *s = alcGetString(NULL, which);
100 checkForErrors();
102 printf("Available %sdevices:\n", kind);
103 while(*s != '\0')
105 printf(" %s\n", s);
106 while(*s++ != '\0')
111 static void printALCInfo (void)
113 ALCint major, minor;
114 ALCdevice *device;
116 if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE)
118 if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATE_ALL_EXT") == AL_TRUE)
119 printDevices(ALC_ALL_DEVICES_SPECIFIER, "playback ");
120 else
121 printDevices(ALC_DEVICE_SPECIFIER, "playback ");
122 printDevices(ALC_CAPTURE_DEVICE_SPECIFIER, "capture ");
124 else
125 printf("No device enumeration available\n");
127 device = alcGetContextsDevice(alcGetCurrentContext());
128 checkForErrors();
130 printf("Default device: %s\n",
131 alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER));
133 printf("Default capture device: %s\n",
134 alcGetString(device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
136 alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
137 alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &minor);
138 checkForErrors();
139 printf("ALC version: %d.%d\n", (int)major, (int)minor);
141 printExtensions("ALC extensions", ' ',
142 alcGetString(device, ALC_EXTENSIONS));
143 checkForErrors();
146 static void printALInfo(void)
148 printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
149 printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
150 printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
151 printExtensions("OpenAL extensions", ' ', alGetString(AL_EXTENSIONS));
152 checkForErrors();
155 int main()
157 ALCdevice *device = alcOpenDevice(NULL);
158 ALCcontext *context = alcCreateContext(device, NULL);
159 alcMakeContextCurrent(context);
160 checkForErrors();
162 printALCInfo();
163 printALInfo();
164 checkForErrors();
166 alcMakeContextCurrent(NULL);
167 alcDestroyContext(context);
168 alcCloseDevice(device);
170 return EXIT_SUCCESS;