2015-06-21 17:33:46 +02:00
|
|
|
/*
|
2026-01-01 09:39:50 -08:00
|
|
|
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
freely.
|
|
|
|
|
*/
|
2022-11-26 20:43:38 -08:00
|
|
|
#include <SDL3/SDL.h>
|
2022-12-15 05:58:20 +01:00
|
|
|
#include <SDL3/SDL_main.h>
|
2023-03-17 00:25:39 +01:00
|
|
|
#include <SDL3/SDL_test.h>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
static void
|
2024-09-18 07:52:28 -07:00
|
|
|
print_devices(bool recording)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-09-29 10:41:40 -04:00
|
|
|
SDL_AudioSpec spec;
|
2024-06-14 17:57:14 -04:00
|
|
|
const char *typestr = (recording ? "recording" : "playback");
|
2023-06-24 11:24:51 -04:00
|
|
|
int n = 0;
|
2023-09-13 11:03:17 -04:00
|
|
|
int frames;
|
2024-07-26 18:57:18 -07:00
|
|
|
SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
if (!devices) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log(" Driver failed to report %s devices: %s", typestr, SDL_GetError());
|
|
|
|
|
SDL_Log("%s", "");
|
2022-12-01 16:07:03 -05:00
|
|
|
} else if (n == 0) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log(" No %s devices found.", typestr);
|
|
|
|
|
SDL_Log("%s", "");
|
2022-12-01 16:07:03 -05:00
|
|
|
} else {
|
2015-06-21 17:33:46 +02:00
|
|
|
int i;
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Found %d %s device%s:", n, typestr, n != 1 ? "s" : "");
|
2015-06-21 17:33:46 +02:00
|
|
|
for (i = 0; i < n; i++) {
|
2024-06-01 22:05:21 -04:00
|
|
|
const char *name = SDL_GetAudioDeviceName(devices[i]);
|
2023-11-09 22:29:15 +01:00
|
|
|
if (name) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log(" %d: %s", i, name);
|
2022-12-01 16:07:03 -05:00
|
|
|
} else {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log(" %d Error: %s", i, SDL_GetError());
|
2022-12-01 16:07:03 -05:00
|
|
|
}
|
2022-09-29 10:41:40 -04:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
if (SDL_GetAudioDeviceFormat(devices[i], &spec, &frames)) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log(" Sample Rate: %d", spec.freq);
|
|
|
|
|
SDL_Log(" Channels: %d", spec.channels);
|
|
|
|
|
SDL_Log(" SDL_AudioFormat: %X", spec.format);
|
|
|
|
|
SDL_Log(" Buffer Size: %d frames", frames);
|
2022-09-29 10:41:40 -04:00
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("%s", "");
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2024-07-26 18:57:18 -07:00
|
|
|
SDL_free(devices);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
int main(int argc, char **argv)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-09-29 10:33:07 -04:00
|
|
|
SDL_AudioSpec spec;
|
2023-03-17 00:25:39 +01:00
|
|
|
int i;
|
2015-06-21 17:33:46 +02:00
|
|
|
int n;
|
2023-09-13 11:03:17 -04:00
|
|
|
int frames;
|
2023-03-17 00:25:39 +01:00
|
|
|
SDLTest_CommonState *state;
|
|
|
|
|
|
|
|
|
|
/* Initialize test framework */
|
|
|
|
|
state = SDLTest_CommonCreateState(argv, 0);
|
2023-11-09 22:29:15 +01:00
|
|
|
if (!state) {
|
2023-03-17 00:25:39 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-03-17 00:25:39 +01:00
|
|
|
/* Parse commandline */
|
|
|
|
|
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
/* Load the SDL library */
|
2024-08-22 17:33:49 -07:00
|
|
|
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());
|
2022-11-27 17:38:43 +01:00
|
|
|
return 1;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print available audio drivers */
|
|
|
|
|
n = SDL_GetNumAudioDrivers();
|
|
|
|
|
if (n == 0) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("No built-in audio drivers");
|
|
|
|
|
SDL_Log("%s", "");
|
2015-06-21 17:33:46 +02:00
|
|
|
} else {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Built-in audio drivers:");
|
2015-06-21 17:33:46 +02:00
|
|
|
for (i = 0; i < n; ++i) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log(" %d: %s", i, SDL_GetAudioDriver(i));
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Select a driver with the SDL_AUDIO_DRIVER environment variable.");
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Using audio driver: %s", SDL_GetCurrentAudioDriver());
|
|
|
|
|
SDL_Log("%s", "");
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2024-09-18 07:52:28 -07:00
|
|
|
print_devices(false);
|
|
|
|
|
print_devices(true);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &frames)) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Default Playback Device:");
|
|
|
|
|
SDL_Log("Sample Rate: %d", spec.freq);
|
|
|
|
|
SDL_Log("Channels: %d", spec.channels);
|
|
|
|
|
SDL_Log("SDL_AudioFormat: %X", spec.format);
|
|
|
|
|
SDL_Log("Buffer Size: %d frames", frames);
|
2024-08-22 17:33:49 -07:00
|
|
|
} else {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default playback): %s", SDL_GetError());
|
2022-09-29 10:33:07 -04:00
|
|
|
}
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &spec, &frames)) {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Default Recording Device:");
|
|
|
|
|
SDL_Log("Sample Rate: %d", spec.freq);
|
|
|
|
|
SDL_Log("Channels: %d", spec.channels);
|
|
|
|
|
SDL_Log("SDL_AudioFormat: %X", spec.format);
|
|
|
|
|
SDL_Log("Buffer Size: %d frames", frames);
|
2024-08-22 17:33:49 -07:00
|
|
|
} else {
|
2025-01-22 12:59:57 -08:00
|
|
|
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default recording): %s", SDL_GetError());
|
2022-09-29 10:33:07 -04:00
|
|
|
}
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_Quit();
|
2023-03-17 00:25:39 +01:00
|
|
|
SDLTest_CommonDestroyState(state);
|
2015-06-21 17:33:46 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
2023-06-24 11:24:51 -04:00
|
|
|
|