test/testaudioinfo.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 10 Jan 2010 19:09:57 +0000
changeset 3635 5ea5e4e6103f
parent 3338 9de326b3099c
child 5535 96594ac5fd1a
permissions -rw-r--r--
Call SDL_Init() before SDL_GetNumAudioDrivers().

Not sure why that was reversed.
     1 #include <stdio.h>
     2 #include "SDL.h"
     3 
     4 static void
     5 print_devices(int iscapture)
     6 {
     7     const char *typestr = ((iscapture) ? "capture" : "output");
     8     int n = SDL_GetNumAudioDevices(iscapture);
     9 
    10     printf("%s devices:\n", typestr);
    11 
    12     if (n == -1)
    13         printf("  Driver can't detect specific devices.\n\n", typestr);
    14     else if (n == 0)
    15         printf("  No %s devices found.\n\n", typestr);
    16     else {
    17         int i;
    18         for (i = 0; i < n; i++) {
    19             printf("  %s\n", SDL_GetAudioDeviceName(i, iscapture));
    20         }
    21         printf("\n");
    22     }
    23 }
    24 
    25 int
    26 main(int argc, char **argv)
    27 {
    28     /* Load the SDL library */
    29     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
    30         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    31         return (1);
    32     }
    33 
    34     /* Print available audio drivers */
    35     int n = SDL_GetNumAudioDrivers();
    36     if (n == 0) {
    37         printf("No built-in audio drivers\n\n");
    38     } else {
    39         int i;
    40         printf("Built-in audio drivers:\n");
    41         for (i = 0; i < n; ++i) {
    42             printf("  %s\n", SDL_GetAudioDriver(i));
    43         }
    44         printf("\n");
    45     }
    46 
    47     printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
    48 
    49     print_devices(0);
    50     print_devices(1);
    51 
    52     SDL_Quit();
    53     return 0;
    54 }