upgrade SDL to version 2.0.8
[platform/upstream/SDL.git] / test / testaudioinfo.c
1 /*
2   Copyright (C) 1997-2018 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     SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
22
23     if (n == -1)
24         SDL_Log("  Driver can't detect specific %s devices.\n\n", typestr);
25     else if (n == 0)
26         SDL_Log("  No %s devices found.\n\n", typestr);
27     else {
28         int i;
29         for (i = 0; i < n; i++) {
30             const char *name = SDL_GetAudioDeviceName(i, iscapture);
31             if (name != NULL)
32                 SDL_Log("  %d: %s\n", i, name);
33             else
34                 SDL_Log("  %d Error: %s\n", i, SDL_GetError());
35         }
36         SDL_Log("\n");
37     }
38 }
39 int
40 main(int argc, char **argv)
41 {
42     int n;
43
44     /* Enable standard application logging */
45     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
46
47     /* Load the SDL library */
48     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
49         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
50         return (1);
51     }
52
53     /* Print available audio drivers */
54     n = SDL_GetNumAudioDrivers();
55     if (n == 0) {
56         SDL_Log("No built-in audio drivers\n\n");
57     } else {
58         int i;
59         SDL_Log("Built-in audio drivers:\n");
60         for (i = 0; i < n; ++i) {
61             SDL_Log("  %d: %s\n", i, SDL_GetAudioDriver(i));
62         }
63         SDL_Log("Select a driver with the SDL_AUDIODRIVER environment variable.\n");
64     }
65
66     SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
67
68     print_devices(0);
69     print_devices(1);
70
71     SDL_Quit();
72     return 0;
73 }