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
35 #include "win_main_utf8.h"
37 /* C doesn't allow casting between function and non-function pointer types, so
38 * with C99 we need to use a union to reinterpret the pointer type. Pre-C99
39 * still needs to use a normal cast and live with the warning (C++ is fine with
40 * a regular reinterpret_cast).
42 #if __STDC_VERSION__ >= 199901L
43 #define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f
45 #define FUNCTION_CAST(T, ptr) (T)(ptr)
50 static void printList(const char *list
, char separator
)
52 size_t col
= MAX_WIDTH
, len
;
53 const char *indent
= " ";
56 if(!list
|| *list
== '\0')
58 fprintf(stdout
, "\n%s!!! none !!!\n", indent
);
63 next
= strchr(list
, separator
);
66 len
= (size_t)(next
-list
);
69 } while(*next
== separator
);
74 if(len
+ col
+ 2 >= MAX_WIDTH
)
76 fprintf(stdout
, "\n%s", indent
);
85 len
= fwrite(list
, 1, len
, stdout
);
88 if(!next
|| *next
== '\0')
98 static void printDeviceList(const char *list
)
100 if(!list
|| *list
== '\0')
101 printf(" !!! none !!!\n");
103 printf(" %s\n", list
);
104 list
+= strlen(list
) + 1;
105 } while(*list
!= '\0');
109 static ALenum
checkALErrors(int linenum
)
111 ALenum err
= alGetError();
112 if(err
!= AL_NO_ERROR
)
113 printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err
), err
, linenum
);
116 #define checkALErrors() checkALErrors(__LINE__)
118 static ALCenum
checkALCErrors(ALCdevice
*device
, int linenum
)
120 ALCenum err
= alcGetError(device
);
121 if(err
!= ALC_NO_ERROR
)
122 printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device
, err
), err
, linenum
);
125 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
128 static void printALCInfo(ALCdevice
*device
)
134 const ALCchar
*devname
= NULL
;
136 if(alcIsExtensionPresent(device
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
137 devname
= alcGetString(device
, ALC_ALL_DEVICES_SPECIFIER
);
138 if(checkALCErrors(device
) != ALC_NO_ERROR
|| !devname
)
139 devname
= alcGetString(device
, ALC_DEVICE_SPECIFIER
);
140 printf("** Info for device \"%s\" **\n", devname
);
142 alcGetIntegerv(device
, ALC_MAJOR_VERSION
, 1, &major
);
143 alcGetIntegerv(device
, ALC_MINOR_VERSION
, 1, &minor
);
144 if(checkALCErrors(device
) == ALC_NO_ERROR
)
145 printf("ALC version: %d.%d\n", major
, minor
);
148 printf("ALC extensions:");
149 printList(alcGetString(device
, ALC_EXTENSIONS
), ' ');
150 checkALCErrors(device
);
154 static void printHRTFInfo(ALCdevice
*device
)
156 LPALCGETSTRINGISOFT alcGetStringiSOFT
;
159 if(alcIsExtensionPresent(device
, "ALC_SOFT_HRTF") == ALC_FALSE
)
161 printf("HRTF extension not available\n");
165 alcGetStringiSOFT
= FUNCTION_CAST(LPALCGETSTRINGISOFT
,
166 alcGetProcAddress(device
, "alcGetStringiSOFT"));
168 alcGetIntegerv(device
, ALC_NUM_HRTF_SPECIFIERS_SOFT
, 1, &num_hrtfs
);
170 printf("No HRTFs found\n");
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
), ' ');
194 static void printResamplerInfo(void)
196 LPALGETSTRINGISOFT alGetStringiSOFT
;
197 ALint num_resamplers
;
200 if(!alIsExtensionPresent("AL_SOFT_source_resampler"))
202 printf("Resampler info not available\n");
206 alGetStringiSOFT
= FUNCTION_CAST(LPALGETSTRINGISOFT
, alGetProcAddress("alGetStringiSOFT"));
208 num_resamplers
= alGetInteger(AL_NUM_RESAMPLERS_SOFT
);
209 def_resampler
= alGetInteger(AL_DEFAULT_RESAMPLER_SOFT
);
212 printf("!!! No resamplers found !!!\n");
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
)?" *":"");
226 static void printEFXInfo(ALCdevice
*device
)
228 static LPALGENFILTERS palGenFilters
;
229 static LPALDELETEFILTERS palDeleteFilters
;
230 static LPALFILTERI palFilteri
;
231 static LPALGENEFFECTS palGenEffects
;
232 static LPALDELETEEFFECTS palDeleteEffects
;
233 static LPALEFFECTI palEffecti
;
235 static const ALint filters
[] = {
236 AL_FILTER_LOWPASS
, AL_FILTER_HIGHPASS
, AL_FILTER_BANDPASS
,
239 char filterNames
[] = "Low-pass,High-pass,Band-pass,";
240 static const ALint effects
[] = {
241 AL_EFFECT_EAXREVERB
, AL_EFFECT_REVERB
, AL_EFFECT_CHORUS
,
242 AL_EFFECT_DISTORTION
, AL_EFFECT_ECHO
, AL_EFFECT_FLANGER
,
243 AL_EFFECT_FREQUENCY_SHIFTER
, AL_EFFECT_VOCAL_MORPHER
,
244 AL_EFFECT_PITCH_SHIFTER
, AL_EFFECT_RING_MODULATOR
,
245 AL_EFFECT_AUTOWAH
, AL_EFFECT_COMPRESSOR
, AL_EFFECT_EQUALIZER
,
248 static const ALint dedeffects
[] = {
249 AL_EFFECT_DEDICATED_DIALOGUE
, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT
,
252 char effectNames
[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
253 "Frequency Shifter,Vocal Morpher,Pitch Shifter,Ring Modulator,Autowah,"
254 "Compressor,Equalizer,Dedicated Dialog,Dedicated LFE,";
255 ALCint major
, minor
, sends
;
260 if(alcIsExtensionPresent(device
, "ALC_EXT_EFX") == AL_FALSE
)
262 printf("EFX not available\n");
266 palGenFilters
= FUNCTION_CAST(LPALGENFILTERS
, alGetProcAddress("alGenFilters"));
267 palDeleteFilters
= FUNCTION_CAST(LPALDELETEFILTERS
, alGetProcAddress("alDeleteFilters"));
268 palFilteri
= FUNCTION_CAST(LPALFILTERI
, alGetProcAddress("alFilteri"));
269 palGenEffects
= FUNCTION_CAST(LPALGENEFFECTS
, alGetProcAddress("alGenEffects"));
270 palDeleteEffects
= FUNCTION_CAST(LPALDELETEEFFECTS
, alGetProcAddress("alDeleteEffects"));
271 palEffecti
= FUNCTION_CAST(LPALEFFECTI
, alGetProcAddress("alEffecti"));
273 alcGetIntegerv(device
, ALC_EFX_MAJOR_VERSION
, 1, &major
);
274 alcGetIntegerv(device
, ALC_EFX_MINOR_VERSION
, 1, &minor
);
275 if(checkALCErrors(device
) == ALC_NO_ERROR
)
276 printf("EFX version: %d.%d\n", major
, minor
);
277 alcGetIntegerv(device
, ALC_MAX_AUXILIARY_SENDS
, 1, &sends
);
278 if(checkALCErrors(device
) == ALC_NO_ERROR
)
279 printf("Max auxiliary sends: %d\n", sends
);
281 palGenFilters(1, &object
);
284 current
= filterNames
;
285 for(i
= 0;filters
[i
] != AL_FILTER_NULL
;i
++)
287 char *next
= strchr(current
, ',');
288 assert(next
!= NULL
);
290 palFilteri(object
, AL_FILTER_TYPE
, filters
[i
]);
291 if(alGetError() != AL_NO_ERROR
)
292 memmove(current
, next
+1, strlen(next
));
296 printf("Supported filters:");
297 printList(filterNames
, ',');
299 palDeleteFilters(1, &object
);
300 palGenEffects(1, &object
);
303 current
= effectNames
;
304 for(i
= 0;effects
[i
] != AL_EFFECT_NULL
;i
++)
306 char *next
= strchr(current
, ',');
307 assert(next
!= NULL
);
309 palEffecti(object
, AL_EFFECT_TYPE
, effects
[i
]);
310 if(alGetError() != AL_NO_ERROR
)
311 memmove(current
, next
+1, strlen(next
));
315 if(alcIsExtensionPresent(device
, "ALC_EXT_DEDICATED"))
317 for(i
= 0;dedeffects
[i
] != AL_EFFECT_NULL
;i
++)
319 char *next
= strchr(current
, ',');
320 assert(next
!= NULL
);
322 palEffecti(object
, AL_EFFECT_TYPE
, dedeffects
[i
]);
323 if(alGetError() != AL_NO_ERROR
)
324 memmove(current
, next
+1, strlen(next
));
331 for(i
= 0;dedeffects
[i
] != AL_EFFECT_NULL
;i
++)
333 char *next
= strchr(current
, ',');
334 assert(next
!= NULL
);
335 memmove(current
, next
+1, strlen(next
));
338 printf("Supported effects:");
339 printList(effectNames
, ',');
341 palDeleteEffects(1, &object
);
345 int main(int argc
, char *argv
[])
351 /* OpenAL Soft gives UTF-8 strings, so set the console to expect that. */
352 SetConsoleOutputCP(CP_UTF8
);
355 if(argc
> 1 && (strcmp(argv
[1], "--help") == 0 ||
356 strcmp(argv
[1], "-h") == 0))
358 printf("Usage: %s [playback device]\n", argv
[0]);
362 printf("Available playback devices:\n");
363 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
364 printDeviceList(alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
));
366 printDeviceList(alcGetString(NULL
, ALC_DEVICE_SPECIFIER
));
367 printf("Available capture devices:\n");
368 printDeviceList(alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
));
370 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE
)
371 printf("Default playback device: %s\n",
372 alcGetString(NULL
, ALC_DEFAULT_ALL_DEVICES_SPECIFIER
));
374 printf("Default playback device: %s\n",
375 alcGetString(NULL
, ALC_DEFAULT_DEVICE_SPECIFIER
));
376 printf("Default capture device: %s\n",
377 alcGetString(NULL
, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
));
381 device
= alcOpenDevice((argc
>1) ? argv
[1] : NULL
);
384 printf("\n!!! Failed to open %s !!!\n\n", ((argc
>1) ? argv
[1] : "default device"));
387 printALCInfo(device
);
388 printHRTFInfo(device
);
390 context
= alcCreateContext(device
, NULL
);
391 if(!context
|| alcMakeContextCurrent(context
) == ALC_FALSE
)
394 alcDestroyContext(context
);
395 alcCloseDevice(device
);
396 printf("\n!!! Failed to set a context !!!\n\n");
401 printResamplerInfo();
402 printEFXInfo(device
);
404 alcMakeContextCurrent(NULL
);
405 alcDestroyContext(context
);
406 alcCloseDevice(device
);