openal-info.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * OpenAL Info Utility
  3. *
  4. * Copyright (c) 2010 by Chris Robinson <[email protected]>
  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 "AL/alc.h"
  27. #include "AL/al.h"
  28. #include "AL/alext.h"
  29. #ifndef ALC_ENUMERATE_ALL_EXT
  30. #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
  31. #define ALC_ALL_DEVICES_SPECIFIER 0x1013
  32. #endif
  33. #ifndef ALC_EXT_EFX
  34. #define ALC_EFX_MAJOR_VERSION 0x20001
  35. #define ALC_EFX_MINOR_VERSION 0x20002
  36. #define ALC_MAX_AUXILIARY_SENDS 0x20003
  37. #endif
  38. #define MAX_WIDTH 80
  39. static void printList(const char *list, char separator)
  40. {
  41. size_t col = MAX_WIDTH, len;
  42. const char *indent = " ";
  43. const char *next;
  44. if(!list || *list == '\0')
  45. {
  46. fprintf(stdout, "\n%s!!! none !!!\n", indent);
  47. return;
  48. }
  49. do {
  50. next = strchr(list, separator);
  51. if(next)
  52. {
  53. len = next-list;
  54. do {
  55. next++;
  56. } while(*next == separator);
  57. }
  58. else
  59. len = strlen(list);
  60. if(len + col + 2 >= MAX_WIDTH)
  61. {
  62. fprintf(stdout, "\n%s", indent);
  63. col = strlen(indent);
  64. }
  65. else
  66. {
  67. fputc(' ', stdout);
  68. col++;
  69. }
  70. len = fwrite(list, 1, len, stdout);
  71. col += len;
  72. if(!next || *next == '\0')
  73. break;
  74. fputc(',', stdout);
  75. col++;
  76. list = next;
  77. } while(1);
  78. fputc('\n', stdout);
  79. }
  80. static void printDeviceList(const char *list)
  81. {
  82. if(!list || *list == '\0')
  83. printf(" !!! none !!!\n");
  84. else do {
  85. printf(" %s\n", list);
  86. list += strlen(list) + 1;
  87. } while(*list != '\0');
  88. }
  89. static ALenum checkALErrors(int linenum)
  90. {
  91. ALenum err = alGetError();
  92. if(err != AL_NO_ERROR)
  93. printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
  94. return err;
  95. }
  96. #define checkALErrors() checkALErrors(__LINE__)
  97. static ALCenum checkALCErrors(ALCdevice *device, int linenum)
  98. {
  99. ALCenum err = alcGetError(device);
  100. if(err != ALC_NO_ERROR)
  101. printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
  102. return err;
  103. }
  104. #define checkALCErrors(x) checkALCErrors((x),__LINE__)
  105. static void printALCInfo(ALCdevice *device)
  106. {
  107. ALCint major, minor;
  108. if(device)
  109. {
  110. const ALCchar *devname = NULL;
  111. printf("\n");
  112. if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  113. devname = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
  114. if(checkALCErrors(device) != ALC_NO_ERROR || !devname)
  115. devname = alcGetString(device, ALC_DEVICE_SPECIFIER);
  116. printf("** Info for device \"%s\" **\n", devname);
  117. }
  118. alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
  119. alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
  120. if(checkALCErrors(device) == ALC_NO_ERROR)
  121. printf("ALC version: %d.%d\n", major, minor);
  122. if(device)
  123. {
  124. printf("ALC extensions:");
  125. printList(alcGetString(device, ALC_EXTENSIONS), ' ');
  126. checkALCErrors(device);
  127. }
  128. }
  129. static void printHRTFInfo(ALCdevice *device)
  130. {
  131. LPALCGETSTRINGISOFT alcGetStringiSOFT;
  132. ALCint num_hrtfs;
  133. if(alcIsExtensionPresent(device, "ALC_SOFT_HRTF") == ALC_FALSE)
  134. {
  135. printf("HRTF extension not available\n");
  136. return;
  137. }
  138. alcGetStringiSOFT = alcGetProcAddress(device, "alcGetStringiSOFT");
  139. alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs);
  140. if(!num_hrtfs)
  141. printf("No HRTFs found\n");
  142. else
  143. {
  144. ALCint i;
  145. printf("Available HRTFs:\n");
  146. for(i = 0;i < num_hrtfs;++i)
  147. {
  148. const ALCchar *name = alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i);
  149. printf(" %s\n", name);
  150. }
  151. }
  152. checkALCErrors(device);
  153. }
  154. static void printALInfo(void)
  155. {
  156. printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
  157. printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
  158. printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
  159. printf("OpenAL extensions:");
  160. printList(alGetString(AL_EXTENSIONS), ' ');
  161. checkALErrors();
  162. }
  163. static void printEFXInfo(ALCdevice *device)
  164. {
  165. ALCint major, minor, sends;
  166. static const ALchar filters[][32] = {
  167. "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
  168. };
  169. char filterNames[] = "Low-pass,High-pass,Band-pass,";
  170. static const ALchar effects[][32] = {
  171. "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
  172. "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
  173. "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
  174. "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
  175. "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
  176. };
  177. static const ALchar dedeffects[][64] = {
  178. "AL_EFFECT_DEDICATED_DIALOGUE",
  179. "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
  180. };
  181. char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
  182. "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
  183. "Ring Modulator,Autowah,Compressor,Equalizer,"
  184. "Dedicated Dialog,Dedicated LFE,";
  185. char *current;
  186. int i;
  187. if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
  188. {
  189. printf("EFX not available\n");
  190. return;
  191. }
  192. alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
  193. alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
  194. if(checkALCErrors(device) == ALC_NO_ERROR)
  195. printf("EFX version: %d.%d\n", major, minor);
  196. alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
  197. if(checkALCErrors(device) == ALC_NO_ERROR)
  198. printf("Max auxiliary sends: %d\n", sends);
  199. current = filterNames;
  200. for(i = 0;filters[i][0];i++)
  201. {
  202. char *next = strchr(current, ',');
  203. ALenum val;
  204. val = alGetEnumValue(filters[i]);
  205. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  206. memmove(current, next+1, strlen(next));
  207. else
  208. current = next+1;
  209. }
  210. printf("Supported filters:");
  211. printList(filterNames, ',');
  212. current = effectNames;
  213. for(i = 0;effects[i][0];i++)
  214. {
  215. char *next = strchr(current, ',');
  216. ALenum val;
  217. val = alGetEnumValue(effects[i]);
  218. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  219. memmove(current, next+1, strlen(next));
  220. else
  221. current = next+1;
  222. }
  223. if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
  224. {
  225. for(i = 0;dedeffects[i][0];i++)
  226. {
  227. char *next = strchr(current, ',');
  228. ALenum val;
  229. val = alGetEnumValue(dedeffects[i]);
  230. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  231. memmove(current, next+1, strlen(next));
  232. else
  233. current = next+1;
  234. }
  235. }
  236. else
  237. {
  238. for(i = 0;dedeffects[i][0];i++)
  239. {
  240. char *next = strchr(current, ',');
  241. memmove(current, next+1, strlen(next));
  242. }
  243. }
  244. printf("Supported effects:");
  245. printList(effectNames, ',');
  246. }
  247. int main(int argc, char *argv[])
  248. {
  249. ALCdevice *device;
  250. ALCcontext *context;
  251. if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
  252. strcmp(argv[1], "-h") == 0))
  253. {
  254. printf("Usage: %s [playback device]\n", argv[0]);
  255. return 0;
  256. }
  257. printf("Available playback devices:\n");
  258. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  259. printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
  260. else
  261. printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
  262. printf("Available capture devices:\n");
  263. printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
  264. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  265. printf("Default playback device: %s\n",
  266. alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
  267. else
  268. printf("Default playback device: %s\n",
  269. alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
  270. printf("Default capture device: %s\n",
  271. alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
  272. printALCInfo(NULL);
  273. device = alcOpenDevice((argc>1) ? argv[1] : NULL);
  274. if(!device)
  275. {
  276. printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
  277. return 1;
  278. }
  279. printALCInfo(device);
  280. printHRTFInfo(device);
  281. context = alcCreateContext(device, NULL);
  282. if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
  283. {
  284. if(context)
  285. alcDestroyContext(context);
  286. alcCloseDevice(device);
  287. printf("\n!!! Failed to set a context !!!\n\n");
  288. return 1;
  289. }
  290. printALInfo();
  291. printEFXInfo(device);
  292. alcMakeContextCurrent(NULL);
  293. alcDestroyContext(context);
  294. alcCloseDevice(device);
  295. return 0;
  296. }