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>.
23 static const int indentation
= 4;
24 static const int maxmimumWidth
= 79;
26 static void printChar(int c
, int *width
)
29 *width
= ((c
== '\n') ? 0 : ((*width
) + 1));
32 static void indent(int *width
)
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')
50 if(extensions
[end
] == separator
|| extensions
[end
] == '\0')
52 if(width
+ end
- start
+ 2 > maxmimumWidth
)
54 printChar('\n', &width
);
59 printChar(extensions
[start
], &width
);
62 if(extensions
[end
] == '\0')
66 if(extensions
[end
] == '\0')
68 printChar(',', &width
);
69 printChar(' ', &width
);
73 printChar('\n', &width
);
76 static void die(const char *kind
, const char *description
)
78 fprintf(stderr
, "%s error %s occured\n", kind
, description
);
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
);
102 printf("Available %sdevices:\n", kind
);
111 static void printALCInfo (void)
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 ");
121 printDevices(ALC_DEVICE_SPECIFIER
, "playback ");
122 printDevices(ALC_CAPTURE_DEVICE_SPECIFIER
, "capture ");
125 printf("No device enumeration available\n");
127 device
= alcGetContextsDevice(alcGetCurrentContext());
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
);
139 printf("ALC version: %d.%d\n", (int)major
, (int)minor
);
141 printExtensions("ALC extensions", ' ',
142 alcGetString(device
, ALC_EXTENSIONS
));
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
));
157 ALCdevice
*device
= alcOpenDevice(NULL
);
158 ALCcontext
*context
= alcCreateContext(device
, NULL
);
159 alcMakeContextCurrent(context
);
166 alcMakeContextCurrent(NULL
);
167 alcDestroyContext(context
);
168 alcCloseDevice(device
);