PageRenderTime 23ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/utils/openal-info.c

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