test/testaudioinfo.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 3635 5ea5e4e6103f
child 7034 3a5a53435ebd
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@5535
     1
/*
slouken@5535
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@3338
    12
#include <stdio.h>
icculus@2049
    13
#include "SDL.h"
icculus@2049
    14
slouken@2060
    15
static void
slouken@2060
    16
print_devices(int iscapture)
icculus@2049
    17
{
icculus@2049
    18
    const char *typestr = ((iscapture) ? "capture" : "output");
icculus@2049
    19
    int n = SDL_GetNumAudioDevices(iscapture);
icculus@2049
    20
icculus@2049
    21
    printf("%s devices:\n", typestr);
icculus@2049
    22
icculus@2049
    23
    if (n == -1)
icculus@2049
    24
        printf("  Driver can't detect specific devices.\n\n", typestr);
icculus@2049
    25
    else if (n == 0)
icculus@2049
    26
        printf("  No %s devices found.\n\n", typestr);
slouken@2060
    27
    else {
icculus@2049
    28
        int i;
icculus@2049
    29
        for (i = 0; i < n; i++) {
icculus@2049
    30
            printf("  %s\n", SDL_GetAudioDeviceName(i, iscapture));
icculus@2049
    31
        }
icculus@2049
    32
        printf("\n");
icculus@2049
    33
    }
icculus@2049
    34
}
icculus@2049
    35
slouken@2060
    36
int
slouken@2060
    37
main(int argc, char **argv)
icculus@2049
    38
{
icculus@3635
    39
    /* Load the SDL library */
icculus@3635
    40
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
icculus@3635
    41
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
icculus@3635
    42
        return (1);
icculus@3635
    43
    }
icculus@3635
    44
icculus@2049
    45
    /* Print available audio drivers */
icculus@2049
    46
    int n = SDL_GetNumAudioDrivers();
icculus@2049
    47
    if (n == 0) {
icculus@2049
    48
        printf("No built-in audio drivers\n\n");
icculus@2049
    49
    } else {
icculus@2049
    50
        int i;
icculus@2049
    51
        printf("Built-in audio drivers:\n");
icculus@2049
    52
        for (i = 0; i < n; ++i) {
icculus@2049
    53
            printf("  %s\n", SDL_GetAudioDriver(i));
icculus@2049
    54
        }
icculus@2049
    55
        printf("\n");
icculus@2049
    56
    }
icculus@2049
    57
icculus@2049
    58
    printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
icculus@2049
    59
icculus@2049
    60
    print_devices(0);
icculus@2049
    61
    print_devices(1);
icculus@2049
    62
icculus@2049
    63
    SDL_Quit();
icculus@2049
    64
    return 0;
icculus@2049
    65
}