testaudioinfo.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. #include <stdio.h>
  11. #include "SDL.h"
  12. static void
  13. print_devices(int iscapture)
  14. {
  15. const char *typestr = ((iscapture) ? "capture" : "output");
  16. int n = SDL_GetNumAudioDevices(iscapture);
  17. SDL_Log("%s devices:\n", typestr);
  18. if (n == -1)
  19. SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
  20. else if (n == 0)
  21. SDL_Log(" No %s devices found.\n\n", typestr);
  22. else {
  23. int i;
  24. for (i = 0; i < n; i++) {
  25. SDL_Log(" %s\n", SDL_GetAudioDeviceName(i, iscapture));
  26. }
  27. SDL_Log("\n");
  28. }
  29. }
  30. int
  31. main(int argc, char **argv)
  32. {
  33. int n;
  34. /* Enable standard application logging */
  35. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  36. /* Load the SDL library */
  37. if (SDL_Init(SDL_INIT_AUDIO) < 0) {
  38. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
  39. return (1);
  40. }
  41. /* Print available audio drivers */
  42. n = SDL_GetNumAudioDrivers();
  43. if (n == 0) {
  44. SDL_Log("No built-in audio drivers\n\n");
  45. } else {
  46. int i;
  47. SDL_Log("Built-in audio drivers:\n");
  48. for (i = 0; i < n; ++i) {
  49. SDL_Log(" %s\n", SDL_GetAudioDriver(i));
  50. }
  51. SDL_Log("\n");
  52. }
  53. SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
  54. print_devices(0);
  55. print_devices(1);
  56. SDL_Quit();
  57. return 0;
  58. }