Skip to content

Commit f6de887

Browse files
committed
openslES: OpenSL ES on Android only supports two formats, limit to that.
(Three with the floating point extension, which we use.) This is according to: https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android Previously, this would accept a request for Sint8 or Sint32 and disaster would ensue. Fixes #13779. (cherry picked from commit 0b2a003)
1 parent 7c189b1 commit f6de887

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/audio/openslES/SDL_openslES.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,28 +426,29 @@ static void OPENSLES_DestroyPCMPlayer(SDL_AudioDevice *device)
426426

427427
static bool OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device)
428428
{
429-
/* If we want to add floating point audio support (requires API level 21)
430-
it can be done as described here:
431-
https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
432-
*/
429+
/* according to https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android,
430+
Android's OpenSL ES only supports Uint8 and _littleendian_ Sint16.
431+
(and float32, with an extension we use, below.) */
433432
if (SDL_GetAndroidSDKVersion() >= 21) {
434433
const SDL_AudioFormat *closefmts = SDL_ClosestAudioFormats(device->spec.format);
435434
SDL_AudioFormat test_format;
436435
while ((test_format = *(closefmts++)) != 0) {
437-
if (SDL_AUDIO_ISSIGNED(test_format)) {
436+
switch (test_format) {
437+
case SDL_AUDIO_U8:
438+
case SDL_AUDIO_S16LE:
439+
case SDL_AUDIO_F32:
438440
break;
439-
}
440441
}
441442

442443
if (!test_format) {
443444
// Didn't find a compatible format :
444-
LOGI("No compatible audio format, using signed 16-bit audio");
445-
test_format = SDL_AUDIO_S16;
445+
LOGI("No compatible audio format, using signed 16-bit LE audio");
446+
test_format = SDL_AUDIO_S16LE;
446447
}
447448
device->spec.format = test_format;
448449
} else {
449450
// Just go with signed 16-bit audio as it's the most compatible
450-
device->spec.format = SDL_AUDIO_S16;
451+
device->spec.format = SDL_AUDIO_S16LE;
451452
}
452453

453454
// Update the fragment size as size in bytes

0 commit comments

Comments
 (0)