From b21f6f547e52bda3be7909f59d1dd7d8a600895b Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 24 Feb 2025 11:35:27 -0500
Subject: [PATCH] audio: set SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES when opening
an audio device.
This makes behavior match SDL2 better.
Fixes #329.
---
src/sdl2_compat.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 9f5c237..fbb1a83 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6745,6 +6745,7 @@ static SDL_AudioDeviceID OpenAudioDeviceLocked(const char *devicename, int iscap
SDL2_AudioStream *stream2;
SDL_AudioDeviceID device3 = 0;
SDL_AudioSpec spec3;
+ char samples_str[32];
int id;
SDL_assert(obtained2 != NULL); /* we checked this before locking. */
@@ -6806,6 +6807,9 @@ static SDL_AudioDeviceID OpenAudioDeviceLocked(const char *devicename, int iscap
spec3.format = SDL_AUDIO_S16BE;
}
+ SDL3_snprintf(samples_str, sizeof (samples_str), "%u", (unsigned int) desired2->samples);
+ SDL3_SetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES, samples_str);
+
device3 = SDL3_OpenAudioDevice(device3, &spec3);
if (device3 == 0) {
return 0;