Ignore the listening angle for the wet path sound cones
[openal-soft.git] / utils / openal-info.c
blob5b45ceefbba9b85797e3b3818e85bd3602c119bf
1 /*
2 * OpenAL Info Utility
4 * Copyright (c) 2010 by Chris Robinson <chris.kcat@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include <stdio.h>
26 #include <string.h>
28 #include "AL/alc.h"
29 #include "AL/al.h"
30 #include "AL/alext.h"
32 #ifndef ALC_ENUMERATE_ALL_EXT
33 #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
34 #define ALC_ALL_DEVICES_SPECIFIER 0x1013
35 #endif
37 #ifndef ALC_EXT_EFX
38 #define ALC_EFX_MAJOR_VERSION 0x20001
39 #define ALC_EFX_MINOR_VERSION 0x20002
40 #define ALC_MAX_AUXILIARY_SENDS 0x20003
41 #endif
44 #define MAX_WIDTH 80
46 static void printList(const char *list, char separator)
48 size_t col = MAX_WIDTH, len;
49 const char *indent = " ";
50 const char *next;
52 if(!list || *list == '\0')
54 fprintf(stdout, "\n%s!!! none !!!\n", indent);
55 return;
58 do {
59 next = strchr(list, separator);
60 if(next)
62 len = next-list;
63 do {
64 next++;
65 } while(*next == separator);
67 else
68 len = strlen(list);
70 if(len + col + 2 >= MAX_WIDTH)
72 fprintf(stdout, "\n%s", indent);
73 col = strlen(indent);
75 else
77 fputc(' ', stdout);
78 col++;
81 len = fwrite(list, 1, len, stdout);
82 col += len;
84 if(!next || *next == '\0')
85 break;
86 fputc(',', stdout);
87 col++;
89 list = next;
90 } while(1);
91 fputc('\n', stdout);
94 static void printDeviceList(const char *list)
96 if(!list || *list == '\0')
97 printf(" !!! none !!!\n");
98 else do {
99 printf(" %s\n", list);
100 list += strlen(list) + 1;
101 } while(*list != '\0');
105 static ALenum checkALErrors(int linenum)
107 ALenum err = alGetError();
108 if(err != AL_NO_ERROR)
109 printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
110 return err;
112 #define checkALErrors() checkALErrors(__LINE__)
114 static ALCenum checkALCErrors(ALCdevice *device, int linenum)
116 ALCenum err = alcGetError(device);
117 if(err != ALC_NO_ERROR)
118 printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
119 return err;
121 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
124 static void printALCInfo(ALCdevice *device)
126 ALCint major, minor;
128 if(device)
130 const ALCchar *devname = NULL;
131 printf("\n");
132 if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
133 devname = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
134 if(checkALCErrors(device) != ALC_NO_ERROR || !devname)
135 devname = alcGetString(device, ALC_DEVICE_SPECIFIER);
136 printf("** Info for device \"%s\" **\n", devname);
138 alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
139 alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
140 if(checkALCErrors(device) == ALC_NO_ERROR)
141 printf("ALC version: %d.%d\n", major, minor);
142 if(device)
144 printf("ALC extensions:");
145 printList(alcGetString(device, ALC_EXTENSIONS), ' ');
146 checkALCErrors(device);
150 static void printHRTFInfo(ALCdevice *device)
152 LPALCGETSTRINGISOFT alcGetStringiSOFT;
153 ALCint num_hrtfs;
155 if(alcIsExtensionPresent(device, "ALC_SOFT_HRTF") == ALC_FALSE)
157 printf("HRTF extension not available\n");
158 return;
161 alcGetStringiSOFT = alcGetProcAddress(device, "alcGetStringiSOFT");
163 alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs);
164 if(!num_hrtfs)
165 printf("No HRTFs found\n");
166 else
168 ALCint i;
169 printf("Available HRTFs:\n");
170 for(i = 0;i < num_hrtfs;++i)
172 const ALCchar *name = alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i);
173 printf(" %s\n", name);
176 checkALCErrors(device);
179 static void printALInfo(void)
181 printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
182 printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
183 printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
184 printf("OpenAL extensions:");
185 printList(alGetString(AL_EXTENSIONS), ' ');
186 checkALErrors();
189 static void printEFXInfo(ALCdevice *device)
191 ALCint major, minor, sends;
192 static const ALchar filters[][32] = {
193 "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
195 char filterNames[] = "Low-pass,High-pass,Band-pass,";
196 static const ALchar effects[][32] = {
197 "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
198 "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
199 "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
200 "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
201 "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
203 static const ALchar dedeffects[][64] = {
204 "AL_EFFECT_DEDICATED_DIALOGUE",
205 "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
207 char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
208 "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
209 "Ring Modulator,Autowah,Compressor,Equalizer,"
210 "Dedicated Dialog,Dedicated LFE,";
211 char *current;
212 int i;
214 if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
216 printf("EFX not available\n");
217 return;
220 alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
221 alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
222 if(checkALCErrors(device) == ALC_NO_ERROR)
223 printf("EFX version: %d.%d\n", major, minor);
224 alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
225 if(checkALCErrors(device) == ALC_NO_ERROR)
226 printf("Max auxiliary sends: %d\n", sends);
228 current = filterNames;
229 for(i = 0;filters[i][0];i++)
231 char *next = strchr(current, ',');
232 ALenum val;
234 val = alGetEnumValue(filters[i]);
235 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
236 memmove(current, next+1, strlen(next));
237 else
238 current = next+1;
240 printf("Supported filters:");
241 printList(filterNames, ',');
243 current = effectNames;
244 for(i = 0;effects[i][0];i++)
246 char *next = strchr(current, ',');
247 ALenum val;
249 val = alGetEnumValue(effects[i]);
250 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
251 memmove(current, next+1, strlen(next));
252 else
253 current = next+1;
255 if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
257 for(i = 0;dedeffects[i][0];i++)
259 char *next = strchr(current, ',');
260 ALenum val;
262 val = alGetEnumValue(dedeffects[i]);
263 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
264 memmove(current, next+1, strlen(next));
265 else
266 current = next+1;
269 else
271 for(i = 0;dedeffects[i][0];i++)
273 char *next = strchr(current, ',');
274 memmove(current, next+1, strlen(next));
277 printf("Supported effects:");
278 printList(effectNames, ',');
281 int main(int argc, char *argv[])
283 ALCdevice *device;
284 ALCcontext *context;
286 if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
287 strcmp(argv[1], "-h") == 0))
289 printf("Usage: %s [playback device]\n", argv[0]);
290 return 0;
293 printf("Available playback devices:\n");
294 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
295 printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
296 else
297 printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
298 printf("Available capture devices:\n");
299 printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
301 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
302 printf("Default playback device: %s\n",
303 alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
304 else
305 printf("Default playback device: %s\n",
306 alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
307 printf("Default capture device: %s\n",
308 alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
310 printALCInfo(NULL);
312 device = alcOpenDevice((argc>1) ? argv[1] : NULL);
313 if(!device)
315 printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
316 return 1;
318 printALCInfo(device);
319 printHRTFInfo(device);
321 context = alcCreateContext(device, NULL);
322 if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
324 if(context)
325 alcDestroyContext(context);
326 alcCloseDevice(device);
327 printf("\n!!! Failed to set a context !!!\n\n");
328 return 1;
331 printALInfo();
332 printEFXInfo(device);
334 alcMakeContextCurrent(NULL);
335 alcDestroyContext(context);
336 alcCloseDevice(device);
338 return 0;