audio: Allow querying of device buffer size.

This commit is contained in:
Ryan C. Gordon
2023-09-13 11:03:17 -04:00
parent cf95721130
commit 2f43f7bc53
7 changed files with 62 additions and 38 deletions

View File

@@ -19,6 +19,7 @@ print_devices(SDL_bool iscapture)
SDL_AudioSpec spec;
const char *typestr = ((iscapture) ? "capture" : "output");
int n = 0;
int frames;
SDL_AudioDeviceID *devices = iscapture ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
if (devices == NULL) {
@@ -37,10 +38,11 @@ print_devices(SDL_bool iscapture)
SDL_Log(" %d Error: %s\n", i, SDL_GetError());
}
if (SDL_GetAudioDeviceFormat(devices[i], &spec) == 0) {
if (SDL_GetAudioDeviceFormat(devices[i], &spec, &frames) == 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(" Buffer Size: %d frames\n", frames);
}
}
SDL_Log("\n");
@@ -53,6 +55,7 @@ int main(int argc, char **argv)
SDL_AudioSpec spec;
int i;
int n;
int frames;
SDLTest_CommonState *state;
/* Initialize test framework */
@@ -92,22 +95,24 @@ int main(int argc, char **argv)
print_devices(SDL_FALSE);
print_devices(SDL_TRUE);
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec) < 0) {
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, &frames) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default output): %s\n", SDL_GetError());
} else {
SDL_Log("Default Output Device:\n");
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("Buffer Size: %d frames\n", frames);
}
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_CAPTURE, &spec) < 0) {
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_CAPTURE, &spec, &frames) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default capture): %s\n", SDL_GetError());
} else {
SDL_Log("Default Capture Device:\n");
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("Buffer Size: %d frames\n", frames);
}
SDL_Quit();