🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.3 KiB

  1. /*
  2. Copyright (C) 1997-2022 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. SDL_AudioSpec spec;
  16. const char *typestr = ((iscapture) ? "capture" : "output");
  17. int n = SDL_GetNumAudioDevices(iscapture);
  18. SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
  19. if (n == -1)
  20. SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
  21. else if (n == 0)
  22. SDL_Log(" No %s devices found.\n\n", typestr);
  23. else {
  24. int i;
  25. for (i = 0; i < n; i++) {
  26. const char *name = SDL_GetAudioDeviceName(i, iscapture);
  27. if (name != NULL)
  28. SDL_Log(" %d: %s\n", i, name);
  29. else
  30. SDL_Log(" %d Error: %s\n", i, SDL_GetError());
  31. if (SDL_GetAudioDeviceSpec(i, iscapture, &spec) == 0) {
  32. SDL_Log(" Sample Rate: %d\n", spec.freq);
  33. SDL_Log(" Channels: %d\n", spec.channels);
  34. SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
  35. }
  36. }
  37. SDL_Log("\n");
  38. }
  39. }
  40. int
  41. main(int argc, char **argv)
  42. {
  43. char *deviceName = NULL;
  44. SDL_AudioSpec spec;
  45. int n;
  46. /* Enable standard application logging */
  47. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  48. /* Load the SDL library */
  49. if (SDL_Init(SDL_INIT_AUDIO) < 0) {
  50. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
  51. return (1);
  52. }
  53. /* Print available audio drivers */
  54. n = SDL_GetNumAudioDrivers();
  55. if (n == 0) {
  56. SDL_Log("No built-in audio drivers\n\n");
  57. } else {
  58. int i;
  59. SDL_Log("Built-in audio drivers:\n");
  60. for (i = 0; i < n; ++i) {
  61. SDL_Log(" %d: %s\n", i, SDL_GetAudioDriver(i));
  62. }
  63. SDL_Log("Select a driver with the SDL_AUDIODRIVER environment variable.\n");
  64. }
  65. SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
  66. print_devices(0);
  67. print_devices(1);
  68. if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 0) < 0) {
  69. SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
  70. } else {
  71. SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown");
  72. SDL_free(deviceName);
  73. SDL_Log("Sample Rate: %d\n", spec.freq);
  74. SDL_Log("Channels: %d\n", spec.channels);
  75. SDL_Log("SDL_AudioFormat: %X\n", spec.format);
  76. }
  77. if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) {
  78. SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
  79. } else {
  80. SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown");
  81. SDL_free(deviceName);
  82. SDL_Log("Sample Rate: %d\n", spec.freq);
  83. SDL_Log("Channels: %d\n", spec.channels);
  84. SDL_Log("SDL_AudioFormat: %X\n", spec.format);
  85. }
  86. SDL_Quit();
  87. return 0;
  88. }