From 58bb1fe68f6acd8a08eb01eca384e3f95f8b04a3 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 3 Mar 2021 23:32:10 +0300
Subject: [PATCH] SDL_OpenAudio: recalculate spec->samples, if necessary.
---
src/SDL12_compat.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 6be21d2..997d9a3 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -4496,10 +4496,17 @@ SDL_OpenAudio(SDL_AudioSpec *want, SDL_AudioSpec *obtained)
}
if (!want->freq) {
want->freq = 22050;
+ want->samples = 0;
}
if (!want->channels) {
want->channels = 2;
}
+ if (!want->samples) {
+ Uint32 samp = (want->freq / 1000) * 46; /* ~46 ms */
+ Uint32 pow2 = 1;
+ while (pow2 < samp) pow2 <<= 1;
+ want->samples = pow2;
+ }
retval = SDL20_OpenAudio(want, NULL);
want->callback = data->app_callback;
want->userdata = data->app_userdata;