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