Skip to content

Commit 9f369a1

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) (cherry picked from commit 7323104) (cherry picked from commit b8c8026)
1 parent 1f6e0e3 commit 9f369a1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/audio/openslES/SDL_openslES.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,27 +413,32 @@ static int openslES_CreatePCMPlayer(_THIS)
413413
SLresult result;
414414
int i;
415415

416-
/* If we want to add floating point audio support (requires API level 21)
417-
it can be done as described here:
418-
https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
419-
*/
416+
/* according to https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android,
417+
Android's OpenSL ES only supports Uint8 and _littleendian_ Sint16.
418+
(and float32, with an extension we use, below.) */
420419
if (SDL_GetAndroidSDKVersion() >= 21) {
421420
SDL_AudioFormat test_format;
422421
for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
423-
if (SDL_AUDIO_ISSIGNED(test_format)) {
422+
switch (test_format) {
423+
case SDL_AUDIO_U8:
424+
case SDL_AUDIO_S16LE:
425+
case SDL_AUDIO_F32:
424426
break;
427+
default:
428+
continue;
425429
}
430+
break;
426431
}
427432

428433
if (!test_format) {
429434
/* Didn't find a compatible format : */
430-
LOGI("No compatible audio format, using signed 16-bit audio");
431-
test_format = AUDIO_S16SYS;
435+
LOGI("No compatible audio format, using signed 16-bit LE audio");
436+
test_format = AUDIO_S16LSB;
432437
}
433438
this->spec.format = test_format;
434439
} else {
435440
/* Just go with signed 16-bit audio as it's the most compatible */
436-
this->spec.format = AUDIO_S16SYS;
441+
this->spec.format = AUDIO_S16LSB;
437442
}
438443

439444
/* Update the fragment size as size in bytes */

0 commit comments

Comments
 (0)