1 /* -*- mode: C; tab-width:8; c-basic-offset:8 -*-
6 * alcinfo display info about a ALC extension and OpenAL renderer
8 * This file is in the Public Domain and comes with no warranty.
9 * Erik Hofman <erik@ehofman.com>
18 # include <OpenAL/al.h>
19 # include <OpenAL/alc.h>
23 # include <AL/alext.h>
26 #ifndef AL_VERSION_1_1
28 # include <OpenAL/altypes.h>
29 # include <OpenAL/alctypes.h>
31 # include <AL/altypes.h>
32 # include <AL/alctypes.h>
43 #ifndef ALC_ALL_DEVICES_SPECIFIER
44 # define ALC_ALL_DEVICES_SPECIFIER 0x1013
48 static const int indentation = 4;
49 static const int maxmimumWidth = 79;
51 void printExtensions (const char *, char, const char *);
52 void displayDevices(const char *, const char *);
53 char *getDeviceName(int, char **);
54 void testForError(void *, const string&);
55 void testForALCError(ALCdevice *);
57 int main(int argc, char **argv)
59 ALCint data[MAX_DATA];
60 ALCdevice *device = NULL;
61 ALCcontext *context = NULL;
65 if (alcIsExtensionPresent(NULL, "ALC_enumeration_EXT") == AL_TRUE)
67 if (alcIsExtensionPresent(NULL, "ALC_enumerate_all_EXT") == AL_FALSE)
68 s = (char *)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
70 s = (char *)alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
71 displayDevices("output", s);
73 s = (char *)alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
74 displayDevices("input", s);
77 s = getDeviceName(argc, argv);
78 device = alcOpenDevice(s);
79 testForError(device, "Audio device not available.");
81 context = alcCreateContext(device, NULL);
82 testForError(context, "Unable to create a valid context.");
84 alcMakeContextCurrent(context);
85 testForALCError(device);
87 s = (char *)alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER);
88 printf("default output device: %s\n", s);
89 testForALCError(device);
91 error = alcIsExtensionPresent(device, "ALC_EXT_capture");
94 s = (char *)alcGetString(device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
95 printf("default input device: %s\n", s);
96 testForALCError(device);
98 printf("capture support: %s\n", (error) ? "yes" : "no");
100 alcGetIntegerv(device, ALC_FREQUENCY, 1, data);
101 printf("mixer frequency: %u hz\n", data[0]);
102 testForALCError(device);
104 alcGetIntegerv(device, ALC_REFRESH, 1, data+1);
105 printf("refresh rate : %u hz\n", data[0]/data[1]);
106 testForALCError(device);
109 alcGetIntegerv(device, ALC_MONO_SOURCES, 1, data);
110 error = alcGetError(device);
111 if (error == AL_NONE) {
112 printf("supported sources; mono: %u, ", data[0]);
115 alcGetIntegerv(device, ALC_STEREO_SOURCES, 1, data);
116 printf("stereo: %u\n", data[0]);
117 testForALCError(device);
120 printf("ALC version: ");
121 alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, data);
122 printf("%i.", *data);
123 alcGetIntegerv(device, ALC_MINOR_VERSION, 1, data);
124 printf("%i\n", *data);
125 testForALCError(device);
127 s = (char *)alcGetString(device, ALC_EXTENSIONS);
128 printExtensions ("ALC extensions", ' ', s);
129 testForALCError(device);
131 s = (char *)alGetString(AL_VENDOR);
132 error = alGetError();
133 if ((error = alGetError()) != AL_NO_ERROR)
134 printf("Error #%x: %s\n", error, alGetString(error));
136 printf("OpenAL vendor string: %s\n", s);
138 s = (char *)alGetString(AL_RENDERER);
139 if ((error = alGetError()) != AL_NO_ERROR)
140 printf("Error #%x: %s\n", error, alGetString(error));
142 printf("OpenAL renderer string: %s\n", s);
144 s = (char *)alGetString(AL_VERSION);
145 if ((error = alGetError()) != AL_NO_ERROR)
146 printf("Error #%x: %s\n", error, alGetString(error));
148 printf("Querying AL_VERSION returned NULL pointer!\n");
150 printf("OpenAL version string: %s\n", s);
152 s = (char *)alGetString(AL_EXTENSIONS);
153 printExtensions ("OpenAL extensions", ' ', s);
154 testForALCError(device);
156 if (alcMakeContextCurrent(NULL) == 0)
157 printf("alcMakeContextCurrent failed.\n");
159 device = alcGetContextsDevice(context);
160 alcDestroyContext(context);
161 testForALCError(device);
163 if (alcCloseDevice(device) == 0)
164 printf("alcCloseDevice failed.\n");
169 /* -------------------------------------------------------------------------- */
172 printChar (int c, int *width)
175 *width = (c == '\n') ? 0 : (*width + 1);
182 for (i = 0; i < indentation; i++)
184 printChar (' ', width);
189 printExtensions (const char *header, char separator, const char *extensions)
191 int width = 0, start = 0, end = 0;
193 printf ("%s:\n", header);
194 if (extensions == NULL || extensions[0] == '\0')
202 if (extensions[end] == separator || extensions[end] == '\0')
204 if (width + end - start + 2 > maxmimumWidth)
206 printChar ('\n', &width);
211 printChar (extensions[start], &width);
214 if (extensions[end] == '\0')
220 if (extensions[end] == '\0')
224 printChar (',', &width);
225 printChar (' ', &width);
229 printChar ('\n', &width);
233 getCommandLineOption(int argc, char **argv, const string& option)
235 int slen = option.size();
239 for (i=0; i<argc; i++)
241 if (strncmp(argv[i], option.c_str(), slen) == 0)
244 if (i<argc) rv = argv[i];
252 getDeviceName(int argc, char **argv)
254 static char devname[255];
258 s = getCommandLineOption(argc, argv, "-d");
261 strncpy((char *)&devname, s, len);
264 s = getCommandLineOption(argc, argv, "-r");
267 strncat((char *)&devname, " on ", len);
270 strncat((char *)&devname, s, len);
272 s = (char *)&devname;
279 displayDevices(const char *type, const char *list)
283 ptr = (ALCchar *)list;
284 printf("list of all available %s devices:\n", type);
292 while (*(nptr += strlen(ptr)+1) != 0)
294 printf(" %s\n", ptr);
297 printf(" %s\n", ptr);
302 testForError(void *p, const string& s)
306 printf("\nError: %s\n\n", s.c_str());
312 testForALCError(ALCdevice *device)
315 error = alcGetError(device);
316 if (error != ALC_NO_ERROR)
317 printf("\nALC Error %x occurred: %s\n", error, alcGetString(device, error));