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
33 #ifndef ALC_ENUMERATE_ALL_EXT
34 #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
35 #define ALC_ALL_DEVICES_SPECIFIER 0x1013
39 #define ALC_EFX_MAJOR_VERSION 0x20001
40 #define ALC_EFX_MINOR_VERSION 0x20002
41 #define ALC_MAX_AUXILIARY_SENDS 0x20003
46 #define WIN32_LEAN_AND_MEAN
49 static WCHAR
*FromUTF8(const char *str
)
54 if((len
=MultiByteToWideChar(CP_UTF8
, 0, str
, -1, NULL
, 0)) > 0)
56 out
= calloc(sizeof(WCHAR
), len
);
57 MultiByteToWideChar(CP_UTF8
, 0, str
, -1, out
, len
);
62 /* Override printf, fprintf, and fwrite so we can print UTF-8 strings. */
63 static void al_fprintf(FILE *file
, const char *fmt
, ...)
70 vsnprintf(str
, sizeof(str
), fmt
, ap
);
73 str
[sizeof(str
)-1] = 0;
76 fprintf(file
, "<UTF-8 error> %s", str
);
78 fprintf(file
, "%ls", wstr
);
81 #define fprintf al_fprintf
82 #define printf(...) al_fprintf(stdout, __VA_ARGS__)
84 static int al_fwrite(const void *ptr
, size_t size
, size_t nmemb
, FILE *file
)
91 if(len
> sizeof(str
)-1)
93 memcpy(str
, ptr
, len
);
98 fprintf(file
, "<UTF-8 error> %s", str
);
100 fprintf(file
, "%ls", wstr
);
105 #define fwrite al_fwrite
111 static void printList(const char *list
, char separator
)
113 size_t col
= MAX_WIDTH
, len
;
114 const char *indent
= " ";
117 if(!list
|| *list
== '\0')
119 fprintf(stdout
, "\n%s!!! none !!!\n", indent
);
124 next
= strchr(list
, separator
);
130 } while(*next
== separator
);
135 if(len
+ col
+ 2 >= MAX_WIDTH
)
137 fprintf(stdout
, "\n%s", indent
);
138 col
= strlen(indent
);
146 len
= fwrite(list
, 1, len
, stdout
);
149 if(!next
|| *next
== '\0')
159 static void printDeviceList(const char *list
)
161 if(!list
|| *list
== '\0')
162 printf(" !!! none !!!\n");
164 printf(" %s\n", list
);
165 list
+= strlen(list
) + 1;
166 } while(*list
!= '\0');
170 static ALenum
checkALErrors(int linenum
)
172 ALenum err
= alGetError();
173 if(err
!= AL_NO_ERROR
)
174 printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err
), err
, linenum
);
177 #define checkALErrors() checkALErrors(__LINE__)
179 static ALCenum
checkALCErrors(ALCdevice
*device
, int linenum
)
181 ALCenum err
= alcGetError(device
);
182 if(err
!= ALC_NO_ERROR
)
183 printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device
, err
), err
, linenum
);
186 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
189 static void printALCInfo(ALCdevice
*device
)
195 const ALCchar
*devname
= NULL
;
197 if(alcIsExtensionPresent(device
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
198 devname
= alcGetString(device
, ALC_ALL_DEVICES_SPECIFIER
);
199 if(checkALCErrors(device
) != ALC_NO_ERROR
|| !devname
)
200 devname
= alcGetString(device
, ALC_DEVICE_SPECIFIER
);
201 printf("** Info for device \"%s\" **\n", devname
);
203 alcGetIntegerv(device
, ALC_MAJOR_VERSION
, 1, &major
);
204 alcGetIntegerv(device
, ALC_MINOR_VERSION
, 1, &minor
);
205 if(checkALCErrors(device
) == ALC_NO_ERROR
)
206 printf("ALC version: %d.%d\n", major
, minor
);
209 printf("ALC extensions:");
210 printList(alcGetString(device
, ALC_EXTENSIONS
), ' ');
211 checkALCErrors(device
);
215 static void printHRTFInfo(ALCdevice
*device
)
217 LPALCGETSTRINGISOFT alcGetStringiSOFT
;
220 if(alcIsExtensionPresent(device
, "ALC_SOFT_HRTF") == ALC_FALSE
)
222 printf("HRTF extension not available\n");
226 alcGetStringiSOFT
= alcGetProcAddress(device
, "alcGetStringiSOFT");
228 alcGetIntegerv(device
, ALC_NUM_HRTF_SPECIFIERS_SOFT
, 1, &num_hrtfs
);
230 printf("No HRTFs found\n");
234 printf("Available HRTFs:\n");
235 for(i
= 0;i
< num_hrtfs
;++i
)
237 const ALCchar
*name
= alcGetStringiSOFT(device
, ALC_HRTF_SPECIFIER_SOFT
, i
);
238 printf(" %s\n", name
);
241 checkALCErrors(device
);
244 static void printALInfo(void)
246 printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR
));
247 printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER
));
248 printf("OpenAL version string: %s\n", alGetString(AL_VERSION
));
249 printf("OpenAL extensions:");
250 printList(alGetString(AL_EXTENSIONS
), ' ');
254 static void printEFXInfo(ALCdevice
*device
)
256 ALCint major
, minor
, sends
;
257 static const ALchar filters
[][32] = {
258 "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
260 char filterNames
[] = "Low-pass,High-pass,Band-pass,";
261 static const ALchar effects
[][32] = {
262 "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
263 "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
264 "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
265 "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
266 "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
268 static const ALchar dedeffects
[][64] = {
269 "AL_EFFECT_DEDICATED_DIALOGUE",
270 "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
272 char effectNames
[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
273 "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
274 "Ring Modulator,Autowah,Compressor,Equalizer,"
275 "Dedicated Dialog,Dedicated LFE,";
279 if(alcIsExtensionPresent(device
, "ALC_EXT_EFX") == AL_FALSE
)
281 printf("EFX not available\n");
285 alcGetIntegerv(device
, ALC_EFX_MAJOR_VERSION
, 1, &major
);
286 alcGetIntegerv(device
, ALC_EFX_MINOR_VERSION
, 1, &minor
);
287 if(checkALCErrors(device
) == ALC_NO_ERROR
)
288 printf("EFX version: %d.%d\n", major
, minor
);
289 alcGetIntegerv(device
, ALC_MAX_AUXILIARY_SENDS
, 1, &sends
);
290 if(checkALCErrors(device
) == ALC_NO_ERROR
)
291 printf("Max auxiliary sends: %d\n", sends
);
293 current
= filterNames
;
294 for(i
= 0;filters
[i
][0];i
++)
296 char *next
= strchr(current
, ',');
299 val
= alGetEnumValue(filters
[i
]);
300 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
301 memmove(current
, next
+1, strlen(next
));
305 printf("Supported filters:");
306 printList(filterNames
, ',');
308 current
= effectNames
;
309 for(i
= 0;effects
[i
][0];i
++)
311 char *next
= strchr(current
, ',');
314 val
= alGetEnumValue(effects
[i
]);
315 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
316 memmove(current
, next
+1, strlen(next
));
320 if(alcIsExtensionPresent(device
, "ALC_EXT_DEDICATED"))
322 for(i
= 0;dedeffects
[i
][0];i
++)
324 char *next
= strchr(current
, ',');
327 val
= alGetEnumValue(dedeffects
[i
]);
328 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
329 memmove(current
, next
+1, strlen(next
));
336 for(i
= 0;dedeffects
[i
][0];i
++)
338 char *next
= strchr(current
, ',');
339 memmove(current
, next
+1, strlen(next
));
342 printf("Supported effects:");
343 printList(effectNames
, ',');
346 int main(int argc
, char *argv
[])
351 if(argc
> 1 && (strcmp(argv
[1], "--help") == 0 ||
352 strcmp(argv
[1], "-h") == 0))
354 printf("Usage: %s [playback device]\n", argv
[0]);
358 printf("Available playback devices:\n");
359 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
360 printDeviceList(alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
));
362 printDeviceList(alcGetString(NULL
, ALC_DEVICE_SPECIFIER
));
363 printf("Available capture devices:\n");
364 printDeviceList(alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
));
366 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
367 printf("Default playback device: %s\n",
368 alcGetString(NULL
, ALC_DEFAULT_ALL_DEVICES_SPECIFIER
));
370 printf("Default playback device: %s\n",
371 alcGetString(NULL
, ALC_DEFAULT_DEVICE_SPECIFIER
));
372 printf("Default capture device: %s\n",
373 alcGetString(NULL
, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
));
377 device
= alcOpenDevice((argc
>1) ? argv
[1] : NULL
);
380 printf("\n!!! Failed to open %s !!!\n\n", ((argc
>1) ? argv
[1] : "default device"));
383 printALCInfo(device
);
384 printHRTFInfo(device
);
386 context
= alcCreateContext(device
, NULL
);
387 if(!context
|| alcMakeContextCurrent(context
) == ALC_FALSE
)
390 alcDestroyContext(context
);
391 alcCloseDevice(device
);
392 printf("\n!!! Failed to set a context !!!\n\n");
397 printEFXInfo(device
);
399 alcMakeContextCurrent(NULL
);
400 alcDestroyContext(context
);
401 alcCloseDevice(device
);