🛠️🐜 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.

437 lines
12 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 <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include "AL/alc.h"
  28. #include "AL/al.h"
  29. #include "AL/alext.h"
  30. #ifndef ALC_ENUMERATE_ALL_EXT
  31. #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
  32. #define ALC_ALL_DEVICES_SPECIFIER 0x1013
  33. #endif
  34. #ifndef ALC_EXT_EFX
  35. #define ALC_EFX_MAJOR_VERSION 0x20001
  36. #define ALC_EFX_MINOR_VERSION 0x20002
  37. #define ALC_MAX_AUXILIARY_SENDS 0x20003
  38. #endif
  39. #ifdef _WIN32
  40. #define WIN32_LEAN_AND_MEAN
  41. #include <windows.h>
  42. static WCHAR *FromUTF8(const char *str)
  43. {
  44. WCHAR *out = NULL;
  45. int len;
  46. if((len=MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) > 0)
  47. {
  48. out = calloc(sizeof(WCHAR), len);
  49. MultiByteToWideChar(CP_UTF8, 0, str, -1, out, len);
  50. }
  51. return out;
  52. }
  53. /* Override printf, fprintf, and fwrite so we can print UTF-8 strings. */
  54. static void al_fprintf(FILE *file, const char *fmt, ...)
  55. {
  56. char str[1024];
  57. WCHAR *wstr;
  58. va_list ap;
  59. va_start(ap, fmt);
  60. vsnprintf(str, sizeof(str), fmt, ap);
  61. va_end(ap);
  62. str[sizeof(str)-1] = 0;
  63. wstr = FromUTF8(str);
  64. if(!wstr)
  65. fprintf(file, "<UTF-8 error> %s", str);
  66. else
  67. fprintf(file, "%ls", wstr);
  68. free(wstr);
  69. }
  70. #define fprintf al_fprintf
  71. #define printf(...) al_fprintf(stdout, __VA_ARGS__)
  72. static size_t al_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
  73. {
  74. char str[1024];
  75. WCHAR *wstr;
  76. size_t len;
  77. len = size * nmemb;
  78. if(len > sizeof(str)-1)
  79. len = sizeof(str)-1;
  80. memcpy(str, ptr, len);
  81. str[len] = 0;
  82. wstr = FromUTF8(str);
  83. if(!wstr)
  84. fprintf(file, "<UTF-8 error> %s", str);
  85. else
  86. fprintf(file, "%ls", wstr);
  87. free(wstr);
  88. return len / size;
  89. }
  90. #define fwrite al_fwrite
  91. #endif
  92. #define MAX_WIDTH 80
  93. static void printList(const char *list, char separator)
  94. {
  95. size_t col = MAX_WIDTH, len;
  96. const char *indent = " ";
  97. const char *next;
  98. if(!list || *list == '\0')
  99. {
  100. fprintf(stdout, "\n%s!!! none !!!\n", indent);
  101. return;
  102. }
  103. do {
  104. next = strchr(list, separator);
  105. if(next)
  106. {
  107. len = next-list;
  108. do {
  109. next++;
  110. } while(*next == separator);
  111. }
  112. else
  113. len = strlen(list);
  114. if(len + col + 2 >= MAX_WIDTH)
  115. {
  116. fprintf(stdout, "\n%s", indent);
  117. col = strlen(indent);
  118. }
  119. else
  120. {
  121. fputc(' ', stdout);
  122. col++;
  123. }
  124. len = fwrite(list, 1, len, stdout);
  125. col += len;
  126. if(!next || *next == '\0')
  127. break;
  128. fputc(',', stdout);
  129. col++;
  130. list = next;
  131. } while(1);
  132. fputc('\n', stdout);
  133. }
  134. static void printDeviceList(const char *list)
  135. {
  136. if(!list || *list == '\0')
  137. printf(" !!! none !!!\n");
  138. else do {
  139. printf(" %s\n", list);
  140. list += strlen(list) + 1;
  141. } while(*list != '\0');
  142. }
  143. static ALenum checkALErrors(int linenum)
  144. {
  145. ALenum err = alGetError();
  146. if(err != AL_NO_ERROR)
  147. printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
  148. return err;
  149. }
  150. #define checkALErrors() checkALErrors(__LINE__)
  151. static ALCenum checkALCErrors(ALCdevice *device, int linenum)
  152. {
  153. ALCenum err = alcGetError(device);
  154. if(err != ALC_NO_ERROR)
  155. printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
  156. return err;
  157. }
  158. #define checkALCErrors(x) checkALCErrors((x),__LINE__)
  159. static void printALCInfo(ALCdevice *device)
  160. {
  161. ALCint major, minor;
  162. if(device)
  163. {
  164. const ALCchar *devname = NULL;
  165. printf("\n");
  166. if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  167. devname = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
  168. if(checkALCErrors(device) != ALC_NO_ERROR || !devname)
  169. devname = alcGetString(device, ALC_DEVICE_SPECIFIER);
  170. printf("** Info for device \"%s\" **\n", devname);
  171. }
  172. alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
  173. alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
  174. if(checkALCErrors(device) == ALC_NO_ERROR)
  175. printf("ALC version: %d.%d\n", major, minor);
  176. if(device)
  177. {
  178. printf("ALC extensions:");
  179. printList(alcGetString(device, ALC_EXTENSIONS), ' ');
  180. checkALCErrors(device);
  181. }
  182. }
  183. static void printHRTFInfo(ALCdevice *device)
  184. {
  185. LPALCGETSTRINGISOFT alcGetStringiSOFT;
  186. ALCint num_hrtfs;
  187. if(alcIsExtensionPresent(device, "ALC_SOFT_HRTF") == ALC_FALSE)
  188. {
  189. printf("HRTF extension not available\n");
  190. return;
  191. }
  192. alcGetStringiSOFT = alcGetProcAddress(device, "alcGetStringiSOFT");
  193. alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs);
  194. if(!num_hrtfs)
  195. printf("No HRTFs found\n");
  196. else
  197. {
  198. ALCint i;
  199. printf("Available HRTFs:\n");
  200. for(i = 0;i < num_hrtfs;++i)
  201. {
  202. const ALCchar *name = alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i);
  203. printf(" %s\n", name);
  204. }
  205. }
  206. checkALCErrors(device);
  207. }
  208. static void printALInfo(void)
  209. {
  210. printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
  211. printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
  212. printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
  213. printf("OpenAL extensions:");
  214. printList(alGetString(AL_EXTENSIONS), ' ');
  215. checkALErrors();
  216. }
  217. static void printResamplerInfo(void)
  218. {
  219. LPALGETSTRINGISOFT alGetStringiSOFT;
  220. ALint num_resamplers;
  221. ALint def_resampler;
  222. if(!alIsExtensionPresent("AL_SOFT_source_resampler"))
  223. {
  224. printf("Resampler info not available\n");
  225. return;
  226. }
  227. alGetStringiSOFT = alGetProcAddress("alGetStringiSOFT");
  228. num_resamplers = alGetInteger(AL_NUM_RESAMPLERS_SOFT);
  229. def_resampler = alGetInteger(AL_DEFAULT_RESAMPLER_SOFT);
  230. if(!num_resamplers)
  231. printf("!!! No resamplers found !!!\n");
  232. else
  233. {
  234. ALint i;
  235. printf("Available resamplers:\n");
  236. for(i = 0;i < num_resamplers;++i)
  237. {
  238. const ALchar *name = alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT, i);
  239. printf(" %s%s\n", name, (i==def_resampler)?" *":"");
  240. }
  241. }
  242. checkALErrors();
  243. }
  244. static void printEFXInfo(ALCdevice *device)
  245. {
  246. ALCint major, minor, sends;
  247. static const ALchar filters[][32] = {
  248. "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
  249. };
  250. char filterNames[] = "Low-pass,High-pass,Band-pass,";
  251. static const ALchar effects[][32] = {
  252. "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
  253. "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
  254. "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
  255. "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
  256. "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
  257. };
  258. static const ALchar dedeffects[][64] = {
  259. "AL_EFFECT_DEDICATED_DIALOGUE",
  260. "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
  261. };
  262. char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
  263. "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
  264. "Ring Modulator,Autowah,Compressor,Equalizer,"
  265. "Dedicated Dialog,Dedicated LFE,";
  266. char *current;
  267. int i;
  268. if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
  269. {
  270. printf("EFX not available\n");
  271. return;
  272. }
  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);
  280. current = filterNames;
  281. for(i = 0;filters[i][0];i++)
  282. {
  283. char *next = strchr(current, ',');
  284. ALenum val;
  285. val = alGetEnumValue(filters[i]);
  286. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  287. memmove(current, next+1, strlen(next));
  288. else
  289. current = next+1;
  290. }
  291. printf("Supported filters:");
  292. printList(filterNames, ',');
  293. current = effectNames;
  294. for(i = 0;effects[i][0];i++)
  295. {
  296. char *next = strchr(current, ',');
  297. ALenum val;
  298. val = alGetEnumValue(effects[i]);
  299. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  300. memmove(current, next+1, strlen(next));
  301. else
  302. current = next+1;
  303. }
  304. if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
  305. {
  306. for(i = 0;dedeffects[i][0];i++)
  307. {
  308. char *next = strchr(current, ',');
  309. ALenum val;
  310. val = alGetEnumValue(dedeffects[i]);
  311. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  312. memmove(current, next+1, strlen(next));
  313. else
  314. current = next+1;
  315. }
  316. }
  317. else
  318. {
  319. for(i = 0;dedeffects[i][0];i++)
  320. {
  321. char *next = strchr(current, ',');
  322. memmove(current, next+1, strlen(next));
  323. }
  324. }
  325. printf("Supported effects:");
  326. printList(effectNames, ',');
  327. }
  328. int main(int argc, char *argv[])
  329. {
  330. ALCdevice *device;
  331. ALCcontext *context;
  332. if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
  333. strcmp(argv[1], "-h") == 0))
  334. {
  335. printf("Usage: %s [playback device]\n", argv[0]);
  336. return 0;
  337. }
  338. printf("Available playback devices:\n");
  339. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  340. printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
  341. else
  342. printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
  343. printf("Available capture devices:\n");
  344. printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
  345. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  346. printf("Default playback device: %s\n",
  347. alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
  348. else
  349. printf("Default playback device: %s\n",
  350. alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
  351. printf("Default capture device: %s\n",
  352. alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
  353. printALCInfo(NULL);
  354. device = alcOpenDevice((argc>1) ? argv[1] : NULL);
  355. if(!device)
  356. {
  357. printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
  358. return 1;
  359. }
  360. printALCInfo(device);
  361. printHRTFInfo(device);
  362. context = alcCreateContext(device, NULL);
  363. if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
  364. {
  365. if(context)
  366. alcDestroyContext(context);
  367. alcCloseDevice(device);
  368. printf("\n!!! Failed to set a context !!!\n\n");
  369. return 1;
  370. }
  371. printALInfo();
  372. printResamplerInfo();
  373. printEFXInfo(device);
  374. alcMakeContextCurrent(NULL);
  375. alcDestroyContext(context);
  376. alcCloseDevice(device);
  377. return 0;
  378. }