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 printResamplerInfo(void)
256 LPALGETSTRINGISOFT alGetStringiSOFT
;
257 ALint num_resamplers
;
260 if(!alIsExtensionPresent("AL_SOFT_source_resampler"))
262 printf("Resampler info not available\n");
266 alGetStringiSOFT
= alGetProcAddress("alGetStringiSOFT");
268 num_resamplers
= alGetInteger(AL_NUM_RESAMPLERS_SOFT
);
269 def_resampler
= alGetInteger(AL_DEFAULT_RESAMPLER_SOFT
);
272 printf("!!! No resamplers found !!!\n");
276 printf("Available resamplers:\n");
277 for(i
= 0;i
< num_resamplers
;++i
)
279 const ALchar
*name
= alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT
, i
);
280 printf(" %s%s\n", name
, (i
==def_resampler
)?" *":"");
286 static void printEFXInfo(ALCdevice
*device
)
288 ALCint major
, minor
, sends
;
289 static const ALchar filters
[][32] = {
290 "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
292 char filterNames
[] = "Low-pass,High-pass,Band-pass,";
293 static const ALchar effects
[][32] = {
294 "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
295 "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
296 "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
297 "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
298 "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
300 static const ALchar dedeffects
[][64] = {
301 "AL_EFFECT_DEDICATED_DIALOGUE",
302 "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
304 char effectNames
[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
305 "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
306 "Ring Modulator,Autowah,Compressor,Equalizer,"
307 "Dedicated Dialog,Dedicated LFE,";
311 if(alcIsExtensionPresent(device
, "ALC_EXT_EFX") == AL_FALSE
)
313 printf("EFX not available\n");
317 alcGetIntegerv(device
, ALC_EFX_MAJOR_VERSION
, 1, &major
);
318 alcGetIntegerv(device
, ALC_EFX_MINOR_VERSION
, 1, &minor
);
319 if(checkALCErrors(device
) == ALC_NO_ERROR
)
320 printf("EFX version: %d.%d\n", major
, minor
);
321 alcGetIntegerv(device
, ALC_MAX_AUXILIARY_SENDS
, 1, &sends
);
322 if(checkALCErrors(device
) == ALC_NO_ERROR
)
323 printf("Max auxiliary sends: %d\n", sends
);
325 current
= filterNames
;
326 for(i
= 0;filters
[i
][0];i
++)
328 char *next
= strchr(current
, ',');
331 val
= alGetEnumValue(filters
[i
]);
332 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
333 memmove(current
, next
+1, strlen(next
));
337 printf("Supported filters:");
338 printList(filterNames
, ',');
340 current
= effectNames
;
341 for(i
= 0;effects
[i
][0];i
++)
343 char *next
= strchr(current
, ',');
346 val
= alGetEnumValue(effects
[i
]);
347 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
348 memmove(current
, next
+1, strlen(next
));
352 if(alcIsExtensionPresent(device
, "ALC_EXT_DEDICATED"))
354 for(i
= 0;dedeffects
[i
][0];i
++)
356 char *next
= strchr(current
, ',');
359 val
= alGetEnumValue(dedeffects
[i
]);
360 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
361 memmove(current
, next
+1, strlen(next
));
368 for(i
= 0;dedeffects
[i
][0];i
++)
370 char *next
= strchr(current
, ',');
371 memmove(current
, next
+1, strlen(next
));
374 printf("Supported effects:");
375 printList(effectNames
, ',');
378 int main(int argc
, char *argv
[])
383 if(argc
> 1 && (strcmp(argv
[1], "--help") == 0 ||
384 strcmp(argv
[1], "-h") == 0))
386 printf("Usage: %s [playback device]\n", argv
[0]);
390 printf("Available playback devices:\n");
391 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
392 printDeviceList(alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
));
394 printDeviceList(alcGetString(NULL
, ALC_DEVICE_SPECIFIER
));
395 printf("Available capture devices:\n");
396 printDeviceList(alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
));
398 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
399 printf("Default playback device: %s\n",
400 alcGetString(NULL
, ALC_DEFAULT_ALL_DEVICES_SPECIFIER
));
402 printf("Default playback device: %s\n",
403 alcGetString(NULL
, ALC_DEFAULT_DEVICE_SPECIFIER
));
404 printf("Default capture device: %s\n",
405 alcGetString(NULL
, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
));
409 device
= alcOpenDevice((argc
>1) ? argv
[1] : NULL
);
412 printf("\n!!! Failed to open %s !!!\n\n", ((argc
>1) ? argv
[1] : "default device"));
415 printALCInfo(device
);
416 printHRTFInfo(device
);
418 context
= alcCreateContext(device
, NULL
);
419 if(!context
|| alcMakeContextCurrent(context
) == ALC_FALSE
)
422 alcDestroyContext(context
);
423 alcCloseDevice(device
);
424 printf("\n!!! Failed to set a context !!!\n\n");
429 printResamplerInfo();
430 printEFXInfo(device
);
432 alcMakeContextCurrent(NULL
);
433 alcDestroyContext(context
);
434 alcCloseDevice(device
);