test: Update testaudioinfo for SDL3 audio API.

main
Ryan C. Gordon 2023-06-24 11:24:51 -04:00
parent 883aee32c5
commit bb1cbbd33a
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 19 additions and 19 deletions

View File

@ -14,29 +14,30 @@
#include <SDL3/SDL_test.h> #include <SDL3/SDL_test.h>
static void static void
print_devices(int iscapture) print_devices(SDL_bool iscapture)
{ {
SDL_AudioSpec spec; SDL_AudioSpec spec;
const char *typestr = ((iscapture) ? "capture" : "output"); const char *typestr = ((iscapture) ? "capture" : "output");
int n = SDL_GetNumAudioDevices(iscapture); int n = 0;
SDL_AudioDeviceID *devices = iscapture ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : ""); if (devices == NULL) {
SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError());
if (n == -1) {
SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
} else if (n == 0) { } else if (n == 0) {
SDL_Log(" No %s devices found.\n\n", typestr); SDL_Log(" No %s devices found.\n\n", typestr);
} else { } else {
int i; int i;
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
const char *name = SDL_GetAudioDeviceName(i, iscapture); char *name = SDL_GetAudioDeviceName(devices[i]);
if (name != NULL) { if (name != NULL) {
SDL_Log(" %d: %s\n", i, name); SDL_Log(" %d: %s\n", i, name);
SDL_free(name);
} else { } else {
SDL_Log(" %d Error: %s\n", i, SDL_GetError()); SDL_Log(" %d Error: %s\n", i, SDL_GetError());
} }
if (SDL_GetAudioDeviceSpec(i, iscapture, &spec) == 0) { if (SDL_GetAudioDeviceFormat(devices[i], &spec) == 0) {
SDL_Log(" Sample Rate: %d\n", spec.freq); SDL_Log(" Sample Rate: %d\n", spec.freq);
SDL_Log(" Channels: %d\n", spec.channels); SDL_Log(" Channels: %d\n", spec.channels);
SDL_Log(" SDL_AudioFormat: %X\n", spec.format); SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
@ -44,11 +45,11 @@ print_devices(int iscapture)
} }
SDL_Log("\n"); SDL_Log("\n");
} }
SDL_free(devices);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char *deviceName = NULL;
SDL_AudioSpec spec; SDL_AudioSpec spec;
int i; int i;
int n; int n;
@ -88,24 +89,22 @@ int main(int argc, char **argv)
SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver()); SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
print_devices(0); print_devices(SDL_FALSE);
print_devices(1); print_devices(SDL_TRUE);
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 0) < 0) { if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError()); SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default output): %s\n", SDL_GetError());
} else { } else {
SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown"); SDL_Log("Default Output Device:\n");
SDL_free(deviceName);
SDL_Log("Sample Rate: %d\n", spec.freq); SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels); SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format); SDL_Log("SDL_AudioFormat: %X\n", spec.format);
} }
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) { if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_CAPTURE, &spec) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError()); SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default capture): %s\n", SDL_GetError());
} else { } else {
SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown"); SDL_Log("Default Capture Device:\n");
SDL_free(deviceName);
SDL_Log("Sample Rate: %d\n", spec.freq); SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels); SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format); SDL_Log("SDL_AudioFormat: %X\n", spec.format);
@ -115,3 +114,4 @@ int main(int argc, char **argv)
SDLTest_CommonDestroyState(state); SDLTest_CommonDestroyState(state);
return 0; return 0;
} }