test/testaudioinfo.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 17 Oct 2006 09:15:21 +0000
changeset 2049 5f6550e5184f
child 2060 866052b01ee5
permissions -rw-r--r--
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
icculus@2049
     1
#include "SDL.h"
icculus@2049
     2
icculus@2049
     3
static void print_devices(int iscapture)
icculus@2049
     4
{
icculus@2049
     5
    const char *typestr = ((iscapture) ? "capture" : "output");
icculus@2049
     6
    int n = SDL_GetNumAudioDevices(iscapture);
icculus@2049
     7
icculus@2049
     8
    printf("%s devices:\n", typestr);
icculus@2049
     9
icculus@2049
    10
    if (n == -1)
icculus@2049
    11
        printf("  Driver can't detect specific devices.\n\n", typestr);
icculus@2049
    12
    else if (n == 0)
icculus@2049
    13
        printf("  No %s devices found.\n\n", typestr);
icculus@2049
    14
    else
icculus@2049
    15
    {
icculus@2049
    16
        int i;
icculus@2049
    17
        for (i = 0; i < n; i++) {
icculus@2049
    18
            printf("  %s\n", SDL_GetAudioDeviceName(i, iscapture));
icculus@2049
    19
        }
icculus@2049
    20
        printf("\n");
icculus@2049
    21
    }
icculus@2049
    22
}
icculus@2049
    23
icculus@2049
    24
int main(int argc, char **argv)
icculus@2049
    25
{
icculus@2049
    26
    /* Print available audio drivers */
icculus@2049
    27
    int n = SDL_GetNumAudioDrivers();
icculus@2049
    28
    if (n == 0) {
icculus@2049
    29
        printf("No built-in audio drivers\n\n");
icculus@2049
    30
    } else {
icculus@2049
    31
        int i;
icculus@2049
    32
        printf("Built-in audio drivers:\n");
icculus@2049
    33
        for (i = 0; i < n; ++i) {
icculus@2049
    34
            printf("  %s\n", SDL_GetAudioDriver(i));
icculus@2049
    35
        }
icculus@2049
    36
        printf("\n");
icculus@2049
    37
    }
icculus@2049
    38
icculus@2049
    39
    /* Load the SDL library */
icculus@2049
    40
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
icculus@2049
    41
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
icculus@2049
    42
        return (1);
icculus@2049
    43
    }
icculus@2049
    44
icculus@2049
    45
    printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
icculus@2049
    46
icculus@2049
    47
    print_devices(0);
icculus@2049
    48
    print_devices(1);
icculus@2049
    49
icculus@2049
    50
    SDL_Quit();
icculus@2049
    51
    return 0;
icculus@2049
    52
}
icculus@2049
    53