testaudioinfo: Also test SDL_GetAudioDeviceSpec

This commit is contained in:
Ethan Lee 2022-09-29 10:41:40 -04:00
parent 40893821f2
commit 1ea1a90edb

View file

@ -15,6 +15,7 @@
static void static void
print_devices(int iscapture) print_devices(int iscapture)
{ {
SDL_AudioSpec spec;
const char *typestr = ((iscapture) ? "capture" : "output"); const char *typestr = ((iscapture) ? "capture" : "output");
int n = SDL_GetNumAudioDevices(iscapture); int n = SDL_GetNumAudioDevices(iscapture);
@ -32,6 +33,12 @@ print_devices(int iscapture)
SDL_Log(" %d: %s\n", i, name); SDL_Log(" %d: %s\n", i, 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) {
SDL_Log(" Sample Rate: %d\n", spec.freq);
SDL_Log(" Channels: %d\n", spec.channels);
SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
}
} }
SDL_Log("\n"); SDL_Log("\n");
} }
@ -76,9 +83,9 @@ main(int argc, char **argv)
} else { } else {
SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown"); SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_free(deviceName); SDL_free(deviceName);
SDL_Log("Sampling Rate: %d\n", spec.freq); SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Number of Channels: %d\n", spec.channels); SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("Audio Format: %d\n", spec.format); SDL_Log("SDL_AudioFormat: %X\n", spec.format);
} }
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) { if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) {
@ -86,9 +93,9 @@ main(int argc, char **argv)
} else { } else {
SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown"); SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_free(deviceName); SDL_free(deviceName);
SDL_Log("Sampling Rate: %d\n", spec.freq); SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Number of Channels: %d\n", spec.channels); SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("Audio Format: %d\n", spec.format); SDL_Log("SDL_AudioFormat: %X\n", spec.format);
} }