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