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("Quering 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 /* alut testing mechanism */
157 context = alcGetCurrentContext();
160 printf("Error: no current context\n");
164 if (alGetError () != AL_NO_ERROR)
166 printf("Alert: AL error on entry\n");
170 if (alcGetError (alcGetContextsDevice (context)) != ALC_NO_ERROR)
172 printf("Alert: ALC error on entry\n");
176 /* end of alut test */
179 if (alcMakeContextCurrent(NULL) == 0)
180 printf("alcMakeContextCurrent failed.\n");
182 device = alcGetContextsDevice(context);
183 alcDestroyContext(context);
184 testForALCError(device);
186 if (alcCloseDevice(device) == 0)
187 printf("alcCloseDevice failed.\n");
192 /* -------------------------------------------------------------------------- */
195 printChar (int c, int *width)
198 *width = (c == '\n') ? 0 : (*width + 1);
205 for (i = 0; i < indentation; i++)
207 printChar (' ', width);
212 printExtensions (const char *header, char separator, const char *extensions)
214 int width = 0, start = 0, end = 0;
216 printf ("%s:\n", header);
217 if (extensions == NULL || extensions[0] == '\0')
225 if (extensions[end] == separator || extensions[end] == '\0')
227 if (width + end - start + 2 > maxmimumWidth)
229 printChar ('\n', &width);
234 printChar (extensions[start], &width);
237 if (extensions[end] == '\0')
243 if (extensions[end] == '\0')
247 printChar (',', &width);
248 printChar (' ', &width);
252 printChar ('\n', &width);
256 getCommandLineOption(int argc, char **argv, const string& option)
258 int slen = option.size();
262 for (i=0; i<argc; i++)
264 if (strncmp(argv[i], option.c_str(), slen) == 0)
267 if (i<argc) rv = argv[i];
275 getDeviceName(int argc, char **argv)
277 static char devname[255];
281 s = getCommandLineOption(argc, argv, "-d");
284 strncpy((char *)&devname, s, len);
287 s = getCommandLineOption(argc, argv, "-r");
290 strncat((char *)&devname, " on ", len);
293 strncat((char *)&devname, s, len);
295 s = (char *)&devname;
302 displayDevices(const char *type, const char *list)
306 ptr = (ALCchar *)list;
307 printf("list of all available %s devices:\n", type);
315 while (*(nptr += strlen(ptr)+1) != 0)
317 printf(" %s\n", ptr);
320 printf(" %s\n", ptr);
325 testForError(void *p, const string& s)
329 printf("\nError: %s\n\n", s.c_str());
335 testForALCError(ALCdevice *device)
338 error = alcGetError(device);
339 if (error != ALC_NO_ERROR)
340 printf("\nALC Error %x occurred: %s\n", error, alcGetString(device, error));