13
#include <SDL3/SDL_main.h>
14
#include <SDL3/SDL_test.h>
17
print_devices(SDL_bool recording)
20
const char *typestr = (recording ? "recording" : "playback");
23
SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
26
SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError());
28
SDL_Log(" No %s devices found.\n\n", typestr);
31
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
32
for (i = 0; i < n; i++) {
33
const char *name = SDL_GetAudioDeviceName(devices[i]);
35
SDL_Log(" %d: %s\n", i, name);
37
SDL_Log(" %d Error: %s\n", i, SDL_GetError());
40
if (SDL_GetAudioDeviceFormat(devices[i], &spec, &frames) == 0) {
41
SDL_Log(" Sample Rate: %d\n", spec.freq);
42
SDL_Log(" Channels: %d\n", spec.channels);
43
SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
44
SDL_Log(" Buffer Size: %d frames\n", frames);
52
int main(int argc, char **argv)
58
SDLTest_CommonState *state;
61
state = SDLTest_CommonCreateState(argv, 0);
67
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
70
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
75
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
76
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
81
n = SDL_GetNumAudioDrivers();
83
SDL_Log("No built-in audio drivers\n\n");
85
SDL_Log("Built-in audio drivers:\n");
86
for (i = 0; i < n; ++i) {
87
SDL_Log(" %d: %s\n", i, SDL_GetAudioDriver(i));
89
SDL_Log("Select a driver with the SDL_AUDIO_DRIVER environment variable.\n");
92
SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
94
print_devices(SDL_FALSE);
95
print_devices(SDL_TRUE);
97
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &frames) < 0) {
98
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default playback): %s\n", SDL_GetError());
100
SDL_Log("Default Playback Device:\n");
101
SDL_Log("Sample Rate: %d\n", spec.freq);
102
SDL_Log("Channels: %d\n", spec.channels);
103
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
104
SDL_Log("Buffer Size: %d frames\n", frames);
107
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &spec, &frames) < 0) {
108
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default recording): %s\n", SDL_GetError());
110
SDL_Log("Default Recording Device:\n");
111
SDL_Log("Sample Rate: %d\n", spec.freq);
112
SDL_Log("Channels: %d\n", spec.channels);
113
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
114
SDL_Log("Buffer Size: %d frames\n", frames);
118
SDLTest_CommonDestroyState(state);