🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
13 KiB

  1. /*
  2. * OpenAL Info Utility
  3. *
  4. * Copyright (c) 2010 by Chris Robinson <chris.kcat@gmail.com>
  5. *
  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:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  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.
  23. */
  24. #include <assert.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "AL/alc.h"
  30. #include "AL/al.h"
  31. #include "AL/alext.h"
  32. #include "win_main_utf8.h"
  33. /* C doesn't allow casting between function and non-function pointer types, so
  34. * with C99 we need to use a union to reinterpret the pointer type. Pre-C99
  35. * still needs to use a normal cast and live with the warning (C++ is fine with
  36. * a regular reinterpret_cast).
  37. */
  38. #if __STDC_VERSION__ >= 199901L
  39. #define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f
  40. #else
  41. #define FUNCTION_CAST(T, ptr) (T)(ptr)
  42. #endif
  43. #define MAX_WIDTH 80
  44. static void printList(const char *list, char separator)
  45. {
  46. size_t col = MAX_WIDTH, len;
  47. const char *indent = " ";
  48. const char *next;
  49. if(!list || *list == '\0')
  50. {
  51. fprintf(stdout, "\n%s!!! none !!!\n", indent);
  52. return;
  53. }
  54. do {
  55. next = strchr(list, separator);
  56. if(next)
  57. {
  58. len = (size_t)(next-list);
  59. do {
  60. next++;
  61. } while(*next == separator);
  62. }
  63. else
  64. len = strlen(list);
  65. if(len + col + 2 >= MAX_WIDTH)
  66. {
  67. fprintf(stdout, "\n%s", indent);
  68. col = strlen(indent);
  69. }
  70. else
  71. {
  72. fputc(' ', stdout);
  73. col++;
  74. }
  75. len = fwrite(list, 1, len, stdout);
  76. col += len;
  77. if(!next || *next == '\0')
  78. break;
  79. fputc(',', stdout);
  80. col++;
  81. list = next;
  82. } while(1);
  83. fputc('\n', stdout);
  84. }
  85. static void printDeviceList(const char *list)
  86. {
  87. if(!list || *list == '\0')
  88. printf(" !!! none !!!\n");
  89. else do {
  90. printf(" %s\n", list);
  91. list += strlen(list) + 1;
  92. } while(*list != '\0');
  93. }
  94. static ALenum checkALErrors(int linenum)
  95. {
  96. ALenum err = alGetError();
  97. if(err != AL_NO_ERROR)
  98. printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
  99. return err;
  100. }
  101. #define checkALErrors() checkALErrors(__LINE__)
  102. static ALCenum checkALCErrors(ALCdevice *device, int linenum)
  103. {
  104. ALCenum err = alcGetError(device);
  105. if(err != ALC_NO_ERROR)
  106. printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
  107. return err;
  108. }
  109. #define checkALCErrors(x) checkALCErrors((x),__LINE__)
  110. static void printALCInfo(ALCdevice *device)
  111. {
  112. ALCint major, minor;
  113. if(device)
  114. {
  115. const ALCchar *devname = NULL;
  116. printf("\n");
  117. if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  118. devname = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
  119. if(checkALCErrors(device) != ALC_NO_ERROR || !devname)
  120. devname = alcGetString(device, ALC_DEVICE_SPECIFIER);
  121. printf("** Info for device \"%s\" **\n", devname);
  122. }
  123. alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
  124. alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
  125. if(checkALCErrors(device) == ALC_NO_ERROR)
  126. printf("ALC version: %d.%d\n", major, minor);
  127. if(device)
  128. {
  129. printf("ALC extensions:");
  130. printList(alcGetString(device, ALC_EXTENSIONS), ' ');
  131. checkALCErrors(device);
  132. }
  133. }
  134. static void printHRTFInfo(ALCdevice *device)
  135. {
  136. LPALCGETSTRINGISOFT alcGetStringiSOFT;
  137. ALCint num_hrtfs;
  138. if(alcIsExtensionPresent(device, "ALC_SOFT_HRTF") == ALC_FALSE)
  139. {
  140. printf("HRTF extension not available\n");
  141. return;
  142. }
  143. alcGetStringiSOFT = FUNCTION_CAST(LPALCGETSTRINGISOFT,
  144. alcGetProcAddress(device, "alcGetStringiSOFT"));
  145. alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs);
  146. if(!num_hrtfs)
  147. printf("No HRTFs found\n");
  148. else
  149. {
  150. ALCint i;
  151. printf("Available HRTFs:\n");
  152. for(i = 0;i < num_hrtfs;++i)
  153. {
  154. const ALCchar *name = alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i);
  155. printf(" %s\n", name);
  156. }
  157. }
  158. checkALCErrors(device);
  159. }
  160. static void printModeInfo(ALCdevice *device)
  161. {
  162. if(alcIsExtensionPresent(device, "ALC_SOFT_output_mode"))
  163. {
  164. const char *modename = "(error)";
  165. ALCenum mode = 0;
  166. alcGetIntegerv(device, ALC_OUTPUT_MODE_SOFT, 1, &mode);
  167. checkALCErrors(device);
  168. switch(mode)
  169. {
  170. case ALC_ANY_SOFT: modename = "Unknown / unspecified"; break;
  171. case ALC_MONO_SOFT: modename = "Mono"; break;
  172. case ALC_STEREO_SOFT: modename = "Stereo (unspecified encoding)"; break;
  173. case ALC_STEREO_BASIC_SOFT: modename = "Stereo (basic)"; break;
  174. case ALC_STEREO_UHJ_SOFT: modename = "Stereo (UHJ)"; break;
  175. case ALC_STEREO_HRTF_SOFT: modename = "Stereo (HRTF)"; break;
  176. case ALC_QUAD_SOFT: modename = "Quadraphonic"; break;
  177. case ALC_SURROUND_5_1_SOFT: modename = "5.1 Surround"; break;
  178. case ALC_SURROUND_6_1_SOFT: modename = "6.1 Surround"; break;
  179. case ALC_SURROUND_7_1_SOFT: modename = "7.1 Surround"; break;
  180. }
  181. printf("Output channel mode: %s\n", modename);
  182. }
  183. else
  184. printf("Output mode extension not available\n");
  185. }
  186. static void printALInfo(void)
  187. {
  188. printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
  189. printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
  190. printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
  191. printf("OpenAL extensions:");
  192. printList(alGetString(AL_EXTENSIONS), ' ');
  193. checkALErrors();
  194. }
  195. static void printResamplerInfo(void)
  196. {
  197. LPALGETSTRINGISOFT alGetStringiSOFT;
  198. ALint num_resamplers;
  199. ALint def_resampler;
  200. if(!alIsExtensionPresent("AL_SOFT_source_resampler"))
  201. {
  202. printf("Resampler info not available\n");
  203. return;
  204. }
  205. alGetStringiSOFT = FUNCTION_CAST(LPALGETSTRINGISOFT, alGetProcAddress("alGetStringiSOFT"));
  206. num_resamplers = alGetInteger(AL_NUM_RESAMPLERS_SOFT);
  207. def_resampler = alGetInteger(AL_DEFAULT_RESAMPLER_SOFT);
  208. if(!num_resamplers)
  209. printf("!!! No resamplers found !!!\n");
  210. else
  211. {
  212. ALint i;
  213. printf("Available resamplers:\n");
  214. for(i = 0;i < num_resamplers;++i)
  215. {
  216. const ALchar *name = alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT, i);
  217. printf(" %s%s\n", name, (i==def_resampler)?" *":"");
  218. }
  219. }
  220. checkALErrors();
  221. }
  222. static void printEFXInfo(ALCdevice *device)
  223. {
  224. static LPALGENFILTERS palGenFilters;
  225. static LPALDELETEFILTERS palDeleteFilters;
  226. static LPALFILTERI palFilteri;
  227. static LPALGENEFFECTS palGenEffects;
  228. static LPALDELETEEFFECTS palDeleteEffects;
  229. static LPALEFFECTI palEffecti;
  230. static const ALint filters[] = {
  231. AL_FILTER_LOWPASS, AL_FILTER_HIGHPASS, AL_FILTER_BANDPASS,
  232. AL_FILTER_NULL
  233. };
  234. char filterNames[] = "Low-pass,High-pass,Band-pass,";
  235. static const ALint effects[] = {
  236. AL_EFFECT_EAXREVERB, AL_EFFECT_REVERB, AL_EFFECT_CHORUS,
  237. AL_EFFECT_DISTORTION, AL_EFFECT_ECHO, AL_EFFECT_FLANGER,
  238. AL_EFFECT_FREQUENCY_SHIFTER, AL_EFFECT_VOCAL_MORPHER,
  239. AL_EFFECT_PITCH_SHIFTER, AL_EFFECT_RING_MODULATOR,
  240. AL_EFFECT_AUTOWAH, AL_EFFECT_COMPRESSOR, AL_EFFECT_EQUALIZER,
  241. AL_EFFECT_NULL
  242. };
  243. static const ALint dedeffects[] = {
  244. AL_EFFECT_DEDICATED_DIALOGUE, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT,
  245. AL_EFFECT_NULL
  246. };
  247. char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
  248. "Frequency Shifter,Vocal Morpher,Pitch Shifter,Ring Modulator,Autowah,"
  249. "Compressor,Equalizer,Dedicated Dialog,Dedicated LFE,";
  250. ALCint major, minor, sends;
  251. ALuint object;
  252. char *current;
  253. int i;
  254. if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
  255. {
  256. printf("EFX not available\n");
  257. return;
  258. }
  259. palGenFilters = FUNCTION_CAST(LPALGENFILTERS, alGetProcAddress("alGenFilters"));
  260. palDeleteFilters = FUNCTION_CAST(LPALDELETEFILTERS, alGetProcAddress("alDeleteFilters"));
  261. palFilteri = FUNCTION_CAST(LPALFILTERI, alGetProcAddress("alFilteri"));
  262. palGenEffects = FUNCTION_CAST(LPALGENEFFECTS, alGetProcAddress("alGenEffects"));
  263. palDeleteEffects = FUNCTION_CAST(LPALDELETEEFFECTS, alGetProcAddress("alDeleteEffects"));
  264. palEffecti = FUNCTION_CAST(LPALEFFECTI, alGetProcAddress("alEffecti"));
  265. alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
  266. alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
  267. if(checkALCErrors(device) == ALC_NO_ERROR)
  268. printf("EFX version: %d.%d\n", major, minor);
  269. alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
  270. if(checkALCErrors(device) == ALC_NO_ERROR)
  271. printf("Max auxiliary sends: %d\n", sends);
  272. palGenFilters(1, &object);
  273. checkALErrors();
  274. current = filterNames;
  275. for(i = 0;filters[i] != AL_FILTER_NULL;i++)
  276. {
  277. char *next = strchr(current, ',');
  278. assert(next != NULL);
  279. palFilteri(object, AL_FILTER_TYPE, filters[i]);
  280. if(alGetError() != AL_NO_ERROR)
  281. memmove(current, next+1, strlen(next));
  282. else
  283. current = next+1;
  284. }
  285. printf("Supported filters:");
  286. printList(filterNames, ',');
  287. palDeleteFilters(1, &object);
  288. palGenEffects(1, &object);
  289. checkALErrors();
  290. current = effectNames;
  291. for(i = 0;effects[i] != AL_EFFECT_NULL;i++)
  292. {
  293. char *next = strchr(current, ',');
  294. assert(next != NULL);
  295. palEffecti(object, AL_EFFECT_TYPE, effects[i]);
  296. if(alGetError() != AL_NO_ERROR)
  297. memmove(current, next+1, strlen(next));
  298. else
  299. current = next+1;
  300. }
  301. if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
  302. {
  303. for(i = 0;dedeffects[i] != AL_EFFECT_NULL;i++)
  304. {
  305. char *next = strchr(current, ',');
  306. assert(next != NULL);
  307. palEffecti(object, AL_EFFECT_TYPE, dedeffects[i]);
  308. if(alGetError() != AL_NO_ERROR)
  309. memmove(current, next+1, strlen(next));
  310. else
  311. current = next+1;
  312. }
  313. }
  314. else
  315. {
  316. for(i = 0;dedeffects[i] != AL_EFFECT_NULL;i++)
  317. {
  318. char *next = strchr(current, ',');
  319. assert(next != NULL);
  320. memmove(current, next+1, strlen(next));
  321. }
  322. }
  323. printf("Supported effects:");
  324. printList(effectNames, ',');
  325. palDeleteEffects(1, &object);
  326. checkALErrors();
  327. }
  328. int main(int argc, char *argv[])
  329. {
  330. ALCdevice *device;
  331. ALCcontext *context;
  332. #ifdef _WIN32
  333. /* OpenAL Soft gives UTF-8 strings, so set the console to expect that. */
  334. SetConsoleOutputCP(CP_UTF8);
  335. #endif
  336. if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
  337. strcmp(argv[1], "-h") == 0))
  338. {
  339. printf("Usage: %s [playback device]\n", argv[0]);
  340. return 0;
  341. }
  342. printf("Available playback devices:\n");
  343. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  344. printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
  345. else
  346. printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
  347. printf("Available capture devices:\n");
  348. printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
  349. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  350. printf("Default playback device: %s\n",
  351. alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
  352. else
  353. printf("Default playback device: %s\n",
  354. alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
  355. printf("Default capture device: %s\n",
  356. alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
  357. printALCInfo(NULL);
  358. device = alcOpenDevice((argc>1) ? argv[1] : NULL);
  359. if(!device)
  360. {
  361. printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
  362. return 1;
  363. }
  364. printALCInfo(device);
  365. printHRTFInfo(device);
  366. context = alcCreateContext(device, NULL);
  367. if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
  368. {
  369. if(context)
  370. alcDestroyContext(context);
  371. alcCloseDevice(device);
  372. printf("\n!!! Failed to set a context !!!\n\n");
  373. return 1;
  374. }
  375. printModeInfo(device);
  376. printALInfo();
  377. printResamplerInfo();
  378. printEFXInfo(device);
  379. alcMakeContextCurrent(NULL);
  380. alcDestroyContext(context);
  381. alcCloseDevice(device);
  382. return 0;
  383. }