diff options
author | Chris Robinson <[email protected]> | 2008-05-18 18:40:53 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2008-05-18 18:40:53 -0700 |
commit | fe79ab351ab6faa585d88de3cce6f5b806b276ed (patch) | |
tree | 6c1f20660b84d64f9079c656894df5334211f5ff /examples | |
parent | dc0a3a665342632673b9d7da6f91121b3dc0b88f (diff) |
Add a simple example that prints out some OpenAL info
Diffstat (limited to 'examples')
-rw-r--r-- | examples/openal-info.c | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/examples/openal-info.c b/examples/openal-info.c new file mode 100644 index 00000000..1693e899 --- /dev/null +++ b/examples/openal-info.c @@ -0,0 +1,170 @@ +/* + * openal-info: Display information about ALC and AL. + * + * Idea based on glxinfo for OpenGL. + * Initial OpenAL version by Erik Hofman <[email protected]>. + * Further hacked by Sven Panne <[email protected]>. + * + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <stdlib.h> + +#include "AL/alc.h" +#include "AL/al.h" +#include "AL/alext.h" + + +static const int indentation = 4; +static const int maxmimumWidth = 79; + +static void printChar(int c, int *width) +{ + putchar(c); + *width = ((c == '\n') ? 0 : ((*width) + 1)); +} + +static void indent(int *width) +{ + int i; + for(i = 0; i < indentation; i++) + printChar(' ', width); +} + +static void printExtensions(const char *header, char separator, const char *extensions) +{ + int width = 0, start = 0, end = 0; + + printf("%s:\n", header); + if(extensions == NULL || extensions[0] == '\0') + return; + + indent(&width); + while (1) + { + if(extensions[end] == separator || extensions[end] == '\0') + { + if(width + end - start + 2 > maxmimumWidth) + { + printChar('\n', &width); + indent(&width); + } + while(start < end) + { + printChar(extensions[start], &width); + start++; + } + if(extensions[end] == '\0') + break; + start++; + end++; + if(extensions[end] == '\0') + break; + printChar(',', &width); + printChar(' ', &width); + } + end++; + } + printChar('\n', &width); +} + +static void die(const char *kind, const char *description) +{ + fprintf(stderr, "%s error %s occured\n", kind, description); + exit(EXIT_FAILURE); +} + +static void checkForErrors(void) +{ + { + ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); + ALCenum error = alcGetError(device); + if(error != ALC_NO_ERROR) + die("ALC", (const char*)alcGetString(device, error)); + } + { + ALenum error = alGetError(); + if(error != AL_NO_ERROR) + die("AL", (const char*)alGetString(error)); + } +} + +static void printDevices(ALCenum which, const char *kind) +{ + const char *s = alcGetString(NULL, which); + checkForErrors(); + + printf("Available %sdevices:\n", kind); + while(*s != '\0') + { + printf(" %s\n", s); + while(*s++ != '\0') + ; + } +} + +static void printALCInfo (void) +{ + ALCint major, minor; + ALCdevice *device; + + if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE) + { + if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATE_ALL_EXT") == AL_TRUE) + printDevices(ALC_ALL_DEVICES_SPECIFIER, "playback "); + else + printDevices(ALC_DEVICE_SPECIFIER, "playback "); + printDevices(ALC_CAPTURE_DEVICE_SPECIFIER, "capture "); + } + else + printf("No device enumeration available\n"); + + device = alcGetContextsDevice(alcGetCurrentContext()); + checkForErrors(); + + printf("Default device: %s\n", + alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER)); + + printf("Default capture device: %s\n", + alcGetString(device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)); + + alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major); + alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &minor); + checkForErrors(); + printf("ALC version: %d.%d\n", (int)major, (int)minor); + + printExtensions("ALC extensions", ' ', + alcGetString(device, ALC_EXTENSIONS)); + checkForErrors(); +} + +static void printALInfo(void) +{ + printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR)); + printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER)); + printf("OpenAL version string: %s\n", alGetString(AL_VERSION)); + printExtensions("OpenAL extensions", ' ', alGetString(AL_EXTENSIONS)); + checkForErrors(); +} + +int main() +{ + ALCdevice *device = alcOpenDevice(NULL); + ALCcontext *context = alcCreateContext(device, NULL); + alcMakeContextCurrent(context); + checkForErrors(); + + printALCInfo(); + printALInfo(); + checkForErrors(); + + alcMakeContextCurrent(NULL); + alcDestroyContext(context); + alcCloseDevice(device); + + return EXIT_SUCCESS; +} |