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
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
43 #define ALC_EFX_MAJOR_VERSION 0x20001
44 #define ALC_EFX_MINOR_VERSION 0x20002
45 #define ALC_MAX_AUXILIARY_SENDS 0x20003
51 static void printList(const char *list
, char separator
)
53 size_t col
= MAX_WIDTH
, len
;
54 const char *indent
= " ";
57 if(!list
|| *list
== '\0')
59 fprintf(stdout
, "\n%s!!! none !!!\n", indent
);
64 next
= strchr(list
, separator
);
67 len
= (size_t)(next
-list
);
70 } while(*next
== separator
);
75 if(len
+ col
+ 2 >= MAX_WIDTH
)
77 fprintf(stdout
, "\n%s", indent
);
86 len
= fwrite(list
, 1, len
, stdout
);
89 if(!next
|| *next
== '\0')
99 static void printDeviceList(const char *list
)
101 if(!list
|| *list
== '\0')
102 printf(" !!! none !!!\n");
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
);
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
);
126 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
129 static void printALCInfo(ALCdevice
*device
)
135 const ALCchar
*devname
= NULL
;
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
);
149 printf("ALC extensions:");
150 printList(alcGetString(device
, ALC_EXTENSIONS
), ' ');
151 checkALCErrors(device
);
155 static void printHRTFInfo(ALCdevice
*device
)
157 LPALCGETSTRINGISOFT alcGetStringiSOFT
;
160 if(alcIsExtensionPresent(device
, "ALC_SOFT_HRTF") == ALC_FALSE
)
162 printf("HRTF extension not available\n");
166 alcGetStringiSOFT
= (LPALCGETSTRINGISOFT
)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
= (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 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,";
251 if(alcIsExtensionPresent(device
, "ALC_EXT_EFX") == AL_FALSE
)
253 printf("EFX not available\n");
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
, ',');
271 val
= alGetEnumValue(filters
[i
]);
272 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
273 memmove(current
, next
+1, strlen(next
));
277 printf("Supported filters:");
278 printList(filterNames
, ',');
280 current
= effectNames
;
281 for(i
= 0;effects
[i
][0];i
++)
283 char *next
= strchr(current
, ',');
286 val
= alGetEnumValue(effects
[i
]);
287 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
288 memmove(current
, next
+1, strlen(next
));
292 if(alcIsExtensionPresent(device
, "ALC_EXT_DEDICATED"))
294 for(i
= 0;dedeffects
[i
][0];i
++)
296 char *next
= strchr(current
, ',');
299 val
= alGetEnumValue(dedeffects
[i
]);
300 if(alGetError() != AL_NO_ERROR
|| val
== 0 || val
== -1)
301 memmove(current
, next
+1, strlen(next
));
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
[])
324 /* OpenAL Soft gives UTF-8 strings, so set the console to expect that. */
325 SetConsoleOutputCP(CP_UTF8
);
328 if(argc
> 1 && (strcmp(argv
[1], "--help") == 0 ||
329 strcmp(argv
[1], "-h") == 0))
331 printf("Usage: %s [playback device]\n", argv
[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
));
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
));
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
));
354 device
= alcOpenDevice((argc
>1) ? argv
[1] : NULL
);
357 printf("\n!!! Failed to open %s !!!\n\n", ((argc
>1) ? argv
[1] : "default device"));
360 printALCInfo(device
);
361 printHRTFInfo(device
);
363 context
= alcCreateContext(device
, NULL
);
364 if(!context
|| alcMakeContextCurrent(context
) == ALC_FALSE
)
367 alcDestroyContext(context
);
368 alcCloseDevice(device
);
369 printf("\n!!! Failed to set a context !!!\n\n");
374 printResamplerInfo();
375 printEFXInfo(device
);
377 alcMakeContextCurrent(NULL
);
378 alcDestroyContext(context
);
379 alcCloseDevice(device
);