openal-info.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 "config.h"
  25. #include <stdio.h>
  26. #include <string.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. #define AL_FILTER_TYPE 0x8001
  39. #define AL_FILTER_NULL 0x0000
  40. #define AL_FILTER_LOWPASS 0x0001
  41. #define AL_FILTER_HIGHPASS 0x0002
  42. #define AL_FILTER_BANDPASS 0x0003
  43. #define AL_EFFECT_TYPE 0x8001
  44. #define AL_EFFECT_NULL 0x0000
  45. #define AL_EFFECT_EAXREVERB 0x8000
  46. #define AL_EFFECT_REVERB 0x0001
  47. #define AL_EFFECT_CHORUS 0x0002
  48. #define AL_EFFECT_DISTORTION 0x0003
  49. #define AL_EFFECT_ECHO 0x0004
  50. #define AL_EFFECT_FLANGER 0x0005
  51. #define AL_EFFECT_FREQUENCY_SHIFTER 0x0006
  52. #define AL_EFFECT_VOCAL_MORPHER 0x0007
  53. #define AL_EFFECT_PITCH_SHIFTER 0x0008
  54. #define AL_EFFECT_RING_MODULATOR 0x0009
  55. #define AL_EFFECT_AUTOWAH 0x000A
  56. #define AL_EFFECT_COMPRESSOR 0x000B
  57. #define AL_EFFECT_EQUALIZER 0x000C
  58. typedef void (AL_APIENTRY *LPALGENFILTERS)(ALsizei, ALuint*);
  59. typedef void (AL_APIENTRY *LPALDELETEFILTERS)(ALsizei, ALuint*);
  60. typedef void (AL_APIENTRY *LPALFILTERI)(ALuint, ALenum, ALint);
  61. typedef void (AL_APIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);
  62. typedef void (AL_APIENTRY *LPALDELETEEFFECTS)(ALsizei, ALuint*);
  63. typedef void (AL_APIENTRY *LPALEFFECTI)(ALuint, ALenum, ALint);
  64. #endif
  65. static LPALGENFILTERS palGenFilters;
  66. static LPALDELETEFILTERS palDeleteFilters;
  67. static LPALFILTERI palFilteri;
  68. static LPALGENEFFECTS palGenEffects;
  69. static LPALDELETEEFFECTS palDeleteEffects;
  70. static LPALEFFECTI palEffecti;
  71. #define MAX_WIDTH 80
  72. static void printList(const char *list, char separator)
  73. {
  74. size_t col = MAX_WIDTH, len;
  75. const char *indent = " ";
  76. const char *next;
  77. if(!list || *list == '\0')
  78. {
  79. fprintf(stdout, "\n%s!!! none !!!\n", indent);
  80. return;
  81. }
  82. do {
  83. next = strchr(list, separator);
  84. if(next)
  85. {
  86. len = next-list;
  87. do {
  88. next++;
  89. } while(*next == separator);
  90. }
  91. else
  92. len = strlen(list);
  93. if(len + col + 2 >= MAX_WIDTH)
  94. {
  95. fprintf(stdout, "\n%s", indent);
  96. col = strlen(indent);
  97. }
  98. else
  99. {
  100. fputc(' ', stdout);
  101. col++;
  102. }
  103. len = fwrite(list, 1, len, stdout);
  104. col += len;
  105. if(!next || *next == '\0')
  106. break;
  107. fputc(',', stdout);
  108. col++;
  109. list = next;
  110. } while(1);
  111. fputc('\n', stdout);
  112. }
  113. static void printDeviceList(const char *list)
  114. {
  115. if(!list || *list == '\0')
  116. printf(" !!! none !!!\n");
  117. else do {
  118. printf(" %s\n", list);
  119. list += strlen(list) + 1;
  120. } while(*list != '\0');
  121. }
  122. static ALenum checkALErrors(int linenum)
  123. {
  124. ALenum err = alGetError();
  125. if(err != AL_NO_ERROR)
  126. printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
  127. return err;
  128. }
  129. #define checkALErrors() checkALErrors(__LINE__)
  130. static ALCenum checkALCErrors(ALCdevice *device, int linenum)
  131. {
  132. ALCenum err = alcGetError(device);
  133. if(err != ALC_NO_ERROR)
  134. printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
  135. return err;
  136. }
  137. #define checkALCErrors(x) checkALCErrors((x),__LINE__)
  138. static void printALCInfo(ALCdevice *device)
  139. {
  140. ALCint major, minor;
  141. alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
  142. alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
  143. if(checkALCErrors(device) == ALC_NO_ERROR)
  144. printf("ALC version: %d.%d\n", major, minor);
  145. if(device)
  146. {
  147. printf("ALC extensions:");
  148. printList(alcGetString(device, ALC_EXTENSIONS), ' ');
  149. checkALCErrors(device);
  150. }
  151. }
  152. static void printALInfo(void)
  153. {
  154. printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
  155. printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
  156. printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
  157. printf("OpenAL extensions:");
  158. printList(alGetString(AL_EXTENSIONS), ' ');
  159. checkALErrors();
  160. }
  161. static void printEFXInfo(ALCdevice *device)
  162. {
  163. ALCint major, minor, sends;
  164. ALuint obj;
  165. int i;
  166. const ALenum filters[] = {
  167. AL_FILTER_LOWPASS, AL_FILTER_HIGHPASS, AL_FILTER_BANDPASS,
  168. AL_FILTER_NULL
  169. };
  170. char filterNames[] = "Low-pass,High-pass,Band-pass,";
  171. const ALenum effects[] = {
  172. AL_EFFECT_EAXREVERB, AL_EFFECT_REVERB, AL_EFFECT_CHORUS,
  173. AL_EFFECT_DISTORTION, AL_EFFECT_ECHO, AL_EFFECT_FLANGER,
  174. AL_EFFECT_FREQUENCY_SHIFTER, AL_EFFECT_VOCAL_MORPHER,
  175. AL_EFFECT_PITCH_SHIFTER, AL_EFFECT_RING_MODULATOR, AL_EFFECT_AUTOWAH,
  176. AL_EFFECT_COMPRESSOR, AL_EFFECT_EQUALIZER, AL_EFFECT_NULL
  177. };
  178. char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
  179. "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
  180. "Ring Modulator,Autowah,Compressor,Equalizer,";
  181. char *current;
  182. if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
  183. {
  184. printf("EFX not available\n");
  185. return;
  186. }
  187. alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
  188. alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
  189. if(checkALCErrors(device) == ALC_NO_ERROR)
  190. printf("EFX version: %d.%d\n", major, minor);
  191. alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
  192. if(checkALCErrors(device) == ALC_NO_ERROR)
  193. printf("Max auxiliary sends: %d\n", sends);
  194. palGenFilters = alGetProcAddress("alGenFilters");
  195. palDeleteFilters = alGetProcAddress("alDeleteFilters");
  196. palFilteri = alGetProcAddress("alFilteri");
  197. palGenEffects = alGetProcAddress("alGenEffects");
  198. palDeleteEffects = alGetProcAddress("alDeleteEffects");
  199. palEffecti = alGetProcAddress("alEffecti");
  200. if(checkALErrors() != AL_NO_ERROR ||
  201. !palGenFilters || !palDeleteFilters || !palFilteri ||
  202. !palGenEffects || !palDeleteEffects || !palEffecti)
  203. {
  204. printf("!!! Missing EFX functions !!!\n");
  205. return;
  206. }
  207. palGenFilters(1, &obj);
  208. if(checkALErrors() == AL_NO_ERROR)
  209. {
  210. current = filterNames;
  211. for(i = 0;filters[i] != AL_FILTER_NULL;i++)
  212. {
  213. char *next = strchr(current, ',');
  214. palFilteri(obj, AL_FILTER_TYPE, filters[i]);
  215. if(alGetError() == AL_NO_ERROR)
  216. current = next+1;
  217. else
  218. memmove(current, next+1, strlen(next));
  219. }
  220. palDeleteFilters(1, &obj);
  221. checkALErrors();
  222. printf("Supported filters:");
  223. printList(filterNames, ',');
  224. }
  225. palGenEffects(1, &obj);
  226. if(checkALErrors() == AL_NO_ERROR)
  227. {
  228. current = effectNames;
  229. for(i = 0;effects[i] != AL_EFFECT_NULL;i++)
  230. {
  231. char *next = strchr(current, ',');
  232. palEffecti(obj, AL_EFFECT_TYPE, effects[i]);
  233. if(alGetError() == AL_NO_ERROR)
  234. current = next+1;
  235. else
  236. memmove(current, next+1, strlen(next));
  237. }
  238. palDeleteEffects(1, &obj);
  239. checkALErrors();
  240. printf("Supported effects:");
  241. printList(effectNames, ',');
  242. }
  243. }
  244. int main(int argc, char *argv[])
  245. {
  246. ALCdevice *device;
  247. ALCcontext *context;
  248. if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
  249. strcmp(argv[1], "-h") == 0))
  250. {
  251. printf("Usage: %s [playback device]\n", argv[0]);
  252. return 0;
  253. }
  254. printf("Available playback devices:\n");
  255. if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
  256. printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
  257. else
  258. printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
  259. printf("Available capture devices:\n");
  260. printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
  261. printf("Default playback device: %s\n",
  262. alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
  263. printf("Default capture device: %s\n",
  264. alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
  265. printALCInfo(NULL);
  266. device = alcOpenDevice((argc>1) ? argv[1] : NULL);
  267. if(!device)
  268. {
  269. printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
  270. return 1;
  271. }
  272. printf("\n** Info for device \"%s\" **\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
  273. printALCInfo(device);
  274. context = alcCreateContext(device, NULL);
  275. if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
  276. {
  277. if(context)
  278. alcDestroyContext(context);
  279. alcCloseDevice(device);
  280. printf("\n!!! Failed to set a context !!!\n\n");
  281. return 1;
  282. }
  283. printALInfo();
  284. printEFXInfo(device);
  285. alcMakeContextCurrent(NULL);
  286. alcDestroyContext(context);
  287. alcCloseDevice(device);
  288. return 0;
  289. }