openal-info.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 printALInfo(void)
  130. {
  131. printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
  132. printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
  133. printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
  134. printf("OpenAL extensions:");
  135. printList(alGetString(AL_EXTENSIONS), ' ');
  136. checkALErrors();
  137. }
  138. static void printEFXInfo(ALCdevice *device)
  139. {
  140. ALCint major, minor, sends;
  141. static const ALchar filters[][32] = {
  142. "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
  143. };
  144. char filterNames[] = "Low-pass,High-pass,Band-pass,";
  145. static const ALchar effects[][32] = {
  146. "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
  147. "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
  148. "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
  149. "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
  150. "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
  151. };
  152. static const ALchar dedeffects[][64] = {
  153. "AL_EFFECT_DEDICATED_DIALOGUE",
  154. "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
  155. };
  156. char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
  157. "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
  158. "Ring Modulator,Autowah,Compressor,Equalizer,"
  159. "Dedicated Dialog,Dedicated LFE,";
  160. char *current;
  161. int i;
  162. if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
  163. {
  164. printf("EFX not available\n");
  165. return;
  166. }
  167. alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
  168. alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
  169. if(checkALCErrors(device) == ALC_NO_ERROR)
  170. printf("EFX version: %d.%d\n", major, minor);
  171. alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
  172. if(checkALCErrors(device) == ALC_NO_ERROR)
  173. printf("Max auxiliary sends: %d\n", sends);
  174. current = filterNames;
  175. for(i = 0;filters[i][0];i++)
  176. {
  177. char *next = strchr(current, ',');
  178. ALenum val;
  179. val = alGetEnumValue(filters[i]);
  180. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  181. memmove(current, next+1, strlen(next));
  182. else
  183. current = next+1;
  184. }
  185. printf("Supported filters:");
  186. printList(filterNames, ',');
  187. current = effectNames;
  188. for(i = 0;effects[i][0];i++)
  189. {
  190. char *next = strchr(current, ',');
  191. ALenum val;
  192. val = alGetEnumValue(effects[i]);
  193. if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
  194. memmove(current, next+1, strlen(next));
  195. else
  196. current = next+1;
  197. }
  198. if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
  199. {
  200. for(i = 0;dedeffects[i][0];i++)
  201. {
  202. char *next = strchr(current, ',');
  203. ALenum val;
  204. val = alGetEnumValue(dedeffects[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. }
  211. else
  212. {
  213. for(i = 0;dedeffects[i][0];i++)
  214. {
  215. char *next = strchr(current, ',');
  216. memmove(current, next+1, strlen(next));
  217. }
  218. }
  219. printf("Supported effects:");
  220. printList(effectNames, ',');
  221. }
  222. int main(int argc, char *argv[])
  223. {
  224. ALCdevice *device;
  225. ALCcontext *context;
  226. if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
  227. strcmp(argv[1], "-h") == 0))
  228. {
  229. printf("Usage: %s [playback device]\n", argv[0]);
  230. return 0;
  231. }
  232. printf("Available playback devices:\n");
  233. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  234. printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
  235. else
  236. printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
  237. printf("Available capture devices:\n");
  238. printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
  239. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  240. printf("Default playback device: %s\n",
  241. alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
  242. else
  243. printf("Default playback device: %s\n",
  244. alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
  245. printf("Default capture device: %s\n",
  246. alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
  247. printALCInfo(NULL);
  248. device = alcOpenDevice((argc>1) ? argv[1] : NULL);
  249. if(!device)
  250. {
  251. printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
  252. return 1;
  253. }
  254. printALCInfo(device);
  255. context = alcCreateContext(device, NULL);
  256. if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
  257. {
  258. if(context)
  259. alcDestroyContext(context);
  260. alcCloseDevice(device);
  261. printf("\n!!! Failed to set a context !!!\n\n");
  262. return 1;
  263. }
  264. printALInfo();
  265. printEFXInfo(device);
  266. alcMakeContextCurrent(NULL);
  267. alcDestroyContext(context);
  268. alcCloseDevice(device);
  269. return 0;
  270. }