test/testaudioinfo.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
slouken@5535
     1
/*
slouken@10737
     2
  Copyright (C) 1997-2017 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
slouken@10413
    21
    SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
icculus@2049
    22
icculus@2049
    23
    if (n == -1)
aschiffler@7639
    24
        SDL_Log("  Driver can't detect specific %s devices.\n\n", typestr);
icculus@2049
    25
    else if (n == 0)
aschiffler@7639
    26
        SDL_Log("  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++) {
slouken@10413
    30
            const char *name = SDL_GetAudioDeviceName(i, iscapture);
slouken@10413
    31
            if (name != NULL)
slouken@10413
    32
                SDL_Log("  %d: %s\n", i, name);
slouken@10413
    33
            else
slouken@10413
    34
                SDL_Log("  %d Error: %s\n", i, SDL_GetError());
icculus@2049
    35
        }
aschiffler@7639
    36
        SDL_Log("\n");
icculus@2049
    37
    }
icculus@2049
    38
}
icculus@2049
    39
slouken@2060
    40
int
slouken@2060
    41
main(int argc, char **argv)
icculus@2049
    42
{
icculus@7034
    43
    int n;
icculus@7034
    44
aschiffler@7639
    45
    /* Enable standard application logging */
aschiffler@7639
    46
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
    47
icculus@3635
    48
    /* Load the SDL library */
icculus@3635
    49
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
aschiffler@7639
    50
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
icculus@3635
    51
        return (1);
icculus@3635
    52
    }
icculus@3635
    53
icculus@2049
    54
    /* Print available audio drivers */
icculus@7034
    55
    n = SDL_GetNumAudioDrivers();
icculus@2049
    56
    if (n == 0) {
aschiffler@7639
    57
        SDL_Log("No built-in audio drivers\n\n");
icculus@2049
    58
    } else {
icculus@2049
    59
        int i;
aschiffler@7639
    60
        SDL_Log("Built-in audio drivers:\n");
icculus@2049
    61
        for (i = 0; i < n; ++i) {
slouken@10413
    62
            SDL_Log("  %d: %s\n", i, SDL_GetAudioDriver(i));
icculus@2049
    63
        }
slouken@10413
    64
        SDL_Log("Select a driver with the SDL_AUDIODRIVER environment variable.\n");
icculus@2049
    65
    }
icculus@2049
    66
aschiffler@7639
    67
    SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
icculus@2049
    68
icculus@2049
    69
    print_devices(0);
icculus@2049
    70
    print_devices(1);
icculus@2049
    71
icculus@2049
    72
    SDL_Quit();
icculus@2049
    73
    return 0;
icculus@2049
    74
}