Define the CoreAudio default name only when needed
[openal-soft.git] / utils / openal-info.c
blob4bb73e76ebe3fff16bbc84fe1110c95993560398
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 <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "AL/alc.h"
31 #include "AL/al.h"
32 #include "AL/alext.h"
34 #include "win_main_utf8.h"
37 #ifndef ALC_ENUMERATE_ALL_EXT
38 #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
39 #define ALC_ALL_DEVICES_SPECIFIER 0x1013
40 #endif
42 #ifndef ALC_EXT_EFX
43 #define ALC_EFX_MAJOR_VERSION 0x20001
44 #define ALC_EFX_MINOR_VERSION 0x20002
45 #define ALC_MAX_AUXILIARY_SENDS 0x20003
46 #endif
49 #define MAX_WIDTH 80
51 static void printList(const char *list, char separator)
53 size_t col = MAX_WIDTH, len;
54 const char *indent = " ";
55 const char *next;
57 if(!list || *list == '\0')
59 fprintf(stdout, "\n%s!!! none !!!\n", indent);
60 return;
63 do {
64 next = strchr(list, separator);
65 if(next)
67 len = (size_t)(next-list);
68 do {
69 next++;
70 } while(*next == separator);
72 else
73 len = strlen(list);
75 if(len + col + 2 >= MAX_WIDTH)
77 fprintf(stdout, "\n%s", indent);
78 col = strlen(indent);
80 else
82 fputc(' ', stdout);
83 col++;
86 len = fwrite(list, 1, len, stdout);
87 col += len;
89 if(!next || *next == '\0')
90 break;
91 fputc(',', stdout);
92 col++;
94 list = next;
95 } while(1);
96 fputc('\n', stdout);
99 static void printDeviceList(const char *list)
101 if(!list || *list == '\0')
102 printf(" !!! none !!!\n");
103 else do {
104 printf(" %s\n", list);
105 list += strlen(list) + 1;
106 } while(*list != '\0');
110 static ALenum checkALErrors(int linenum)
112 ALenum err = alGetError();
113 if(err != AL_NO_ERROR)
114 printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
115 return err;
117 #define checkALErrors() checkALErrors(__LINE__)
119 static ALCenum checkALCErrors(ALCdevice *device, int linenum)
121 ALCenum err = alcGetError(device);
122 if(err != ALC_NO_ERROR)
123 printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
124 return err;
126 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
129 static void printALCInfo(ALCdevice *device)
131 ALCint major, minor;
133 if(device)
135 const ALCchar *devname = NULL;
136 printf("\n");
137 if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
138 devname = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
139 if(checkALCErrors(device) != ALC_NO_ERROR || !devname)
140 devname = alcGetString(device, ALC_DEVICE_SPECIFIER);
141 printf("** Info for device \"%s\" **\n", devname);
143 alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
144 alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
145 if(checkALCErrors(device) == ALC_NO_ERROR)
146 printf("ALC version: %d.%d\n", major, minor);
147 if(device)
149 printf("ALC extensions:");
150 printList(alcGetString(device, ALC_EXTENSIONS), ' ');
151 checkALCErrors(device);
155 static void printHRTFInfo(ALCdevice *device)
157 LPALCGETSTRINGISOFT alcGetStringiSOFT;
158 ALCint num_hrtfs;
160 if(alcIsExtensionPresent(device, "ALC_SOFT_HRTF") == ALC_FALSE)
162 printf("HRTF extension not available\n");
163 return;
166 alcGetStringiSOFT = (LPALCGETSTRINGISOFT)alcGetProcAddress(device, "alcGetStringiSOFT");
168 alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs);
169 if(!num_hrtfs)
170 printf("No HRTFs found\n");
171 else
173 ALCint i;
174 printf("Available HRTFs:\n");
175 for(i = 0;i < num_hrtfs;++i)
177 const ALCchar *name = alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i);
178 printf(" %s\n", name);
181 checkALCErrors(device);
184 static void printALInfo(void)
186 printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
187 printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
188 printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
189 printf("OpenAL extensions:");
190 printList(alGetString(AL_EXTENSIONS), ' ');
191 checkALErrors();
194 static void printResamplerInfo(void)
196 LPALGETSTRINGISOFT alGetStringiSOFT;
197 ALint num_resamplers;
198 ALint def_resampler;
200 if(!alIsExtensionPresent("AL_SOFT_source_resampler"))
202 printf("Resampler info not available\n");
203 return;
206 alGetStringiSOFT = (LPALGETSTRINGISOFT)alGetProcAddress("alGetStringiSOFT");
208 num_resamplers = alGetInteger(AL_NUM_RESAMPLERS_SOFT);
209 def_resampler = alGetInteger(AL_DEFAULT_RESAMPLER_SOFT);
211 if(!num_resamplers)
212 printf("!!! No resamplers found !!!\n");
213 else
215 ALint i;
216 printf("Available resamplers:\n");
217 for(i = 0;i < num_resamplers;++i)
219 const ALchar *name = alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT, i);
220 printf(" %s%s\n", name, (i==def_resampler)?" *":"");
223 checkALErrors();
226 static void printEFXInfo(ALCdevice *device)
228 ALCint major, minor, sends;
229 static const ALchar filters[][32] = {
230 "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
232 char filterNames[] = "Low-pass,High-pass,Band-pass,";
233 static const ALchar effects[][32] = {
234 "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
235 "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
236 "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
237 "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
238 "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
240 static const ALchar dedeffects[][64] = {
241 "AL_EFFECT_DEDICATED_DIALOGUE",
242 "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
244 char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
245 "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
246 "Ring Modulator,Autowah,Compressor,Equalizer,"
247 "Dedicated Dialog,Dedicated LFE,";
248 char *current;
249 int i;
251 if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
253 printf("EFX not available\n");
254 return;
257 alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
258 alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
259 if(checkALCErrors(device) == ALC_NO_ERROR)
260 printf("EFX version: %d.%d\n", major, minor);
261 alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
262 if(checkALCErrors(device) == ALC_NO_ERROR)
263 printf("Max auxiliary sends: %d\n", sends);
265 current = filterNames;
266 for(i = 0;filters[i][0];i++)
268 char *next = strchr(current, ',');
269 ALenum val;
271 val = alGetEnumValue(filters[i]);
272 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
273 memmove(current, next+1, strlen(next));
274 else
275 current = next+1;
277 printf("Supported filters:");
278 printList(filterNames, ',');
280 current = effectNames;
281 for(i = 0;effects[i][0];i++)
283 char *next = strchr(current, ',');
284 ALenum val;
286 val = alGetEnumValue(effects[i]);
287 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
288 memmove(current, next+1, strlen(next));
289 else
290 current = next+1;
292 if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
294 for(i = 0;dedeffects[i][0];i++)
296 char *next = strchr(current, ',');
297 ALenum val;
299 val = alGetEnumValue(dedeffects[i]);
300 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
301 memmove(current, next+1, strlen(next));
302 else
303 current = next+1;
306 else
308 for(i = 0;dedeffects[i][0];i++)
310 char *next = strchr(current, ',');
311 memmove(current, next+1, strlen(next));
314 printf("Supported effects:");
315 printList(effectNames, ',');
318 int main(int argc, char *argv[])
320 ALCdevice *device;
321 ALCcontext *context;
323 #ifdef _WIN32
324 /* OpenAL Soft gives UTF-8 strings, so set the console to expect that. */
325 SetConsoleOutputCP(CP_UTF8);
326 #endif
328 if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
329 strcmp(argv[1], "-h") == 0))
331 printf("Usage: %s [playback device]\n", argv[0]);
332 return 0;
335 printf("Available playback devices:\n");
336 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
337 printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
338 else
339 printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
340 printf("Available capture devices:\n");
341 printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
343 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
344 printf("Default playback device: %s\n",
345 alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
346 else
347 printf("Default playback device: %s\n",
348 alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
349 printf("Default capture device: %s\n",
350 alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
352 printALCInfo(NULL);
354 device = alcOpenDevice((argc>1) ? argv[1] : NULL);
355 if(!device)
357 printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
358 return 1;
360 printALCInfo(device);
361 printHRTFInfo(device);
363 context = alcCreateContext(device, NULL);
364 if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
366 if(context)
367 alcDestroyContext(context);
368 alcCloseDevice(device);
369 printf("\n!!! Failed to set a context !!!\n\n");
370 return 1;
373 printALInfo();
374 printResamplerInfo();
375 printEFXInfo(device);
377 alcMakeContextCurrent(NULL);
378 alcDestroyContext(context);
379 alcCloseDevice(device);
381 return 0;