Fixed static and buzzing when trying to use floating point audio on the OpenSL ES audio driver.
1.1 --- a/src/audio/openslES/SDL_openslES.c Thu May 23 11:32:36 2019 -0700
1.2 +++ b/src/audio/openslES/SDL_openslES.c Thu May 23 13:47:27 2019 -0700
1.3 @@ -35,13 +35,14 @@
1.4 #define LOG_TAG "SDL_openslES"
1.5
1.6 #if 0
1.7 +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
1.8 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
1.9 -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
1.10 -// #define LOGI(...) do {} while (0)
1.11 -// #define LOGE(...) do {} while (0)
1.12 +//#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
1.13 +#define LOGV(...)
1.14 #else
1.15 +#define LOGE(...)
1.16 #define LOGI(...)
1.17 -#define LOGE(...)
1.18 +#define LOGV(...)
1.19 #endif
1.20
1.21 /* engine interfaces */
1.22 @@ -193,7 +194,7 @@
1.23 bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
1.24 {
1.25 struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) context;
1.26 - LOGI("SLES: Playback Callmeback");
1.27 + LOGV("SLES: Playback Callmeback");
1.28 SDL_SemPost(audiodata->playsem);
1.29 return;
1.30 }
1.31 @@ -223,26 +224,28 @@
1.32 SLresult result;
1.33 int i;
1.34
1.35 -#if 0
1.36 - SDL_AudioFormat test_format = 0;
1.37 -
1.38 - test_format = SDL_FirstAudioFormat( this->spec.format );
1.39 -
1.40 - while (test_format != 0) {
1.41 + /* If we want to add floating point audio support (requires API level 21)
1.42 + it can be done as described here:
1.43 + https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
1.44 + */
1.45 +#if 1
1.46 + /* Just go with signed 16-bit audio as it's the most compatible */
1.47 + this->spec.format = AUDIO_S16SYS;
1.48 +#else
1.49 + SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
1.50 + while (test_format != 0) {
1.51 + if (SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format)) {
1.52 + break;
1.53 + }
1.54 + test_format = SDL_NextAudioFormat();
1.55 + }
1.56
1.57 - if (SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format)) {
1.58 - break;
1.59 - }
1.60 - test_format = SDL_NextAudioFormat();
1.61 - }
1.62 -
1.63 - if ( test_format == 0 ) {
1.64 - /* Didn't find a compatible format : */
1.65 - LOGI( "No compatible audio format!" );
1.66 - return SDL_SetError("No compatible audio format!");
1.67 - }
1.68 -
1.69 - this->spec.format = test_format;
1.70 + if (test_format == 0) {
1.71 + /* Didn't find a compatible format : */
1.72 + LOGI( "No compatible audio format, using signed 16-bit audio" );
1.73 + test_format = AUDIO_S16SYS;
1.74 + }
1.75 + this->spec.format = test_format;
1.76 #endif
1.77
1.78 /* Update the fragment size as size in bytes */
1.79 @@ -250,7 +253,7 @@
1.80
1.81 LOGI("Try to open %u hz %u bit chan %u %s samples %u",
1.82 this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
1.83 - this->spec.channels, (test_format & 0x1000) ? "BE" : "LE", this->spec.samples);
1.84 + this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
1.85
1.86 /* configure audio source */
1.87 SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, NUM_BUFFERS };
1.88 @@ -496,7 +499,7 @@
1.89 {
1.90 struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
1.91
1.92 - LOGI("openslES_WaitDevice( )");
1.93 + LOGV("openslES_WaitDevice( )");
1.94
1.95 /* Wait for an audio chunk to finish */
1.96 /* WaitForSingleObject(this->hidden->audio_sem, INFINITE); */
1.97 @@ -522,7 +525,7 @@
1.98 {
1.99 struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
1.100
1.101 - LOGI("openslES_GetDeviceBuf( )");
1.102 + LOGV("openslES_GetDeviceBuf( )");
1.103 return audiodata->pmixbuff[audiodata->next_buffer];
1.104 }
1.105
1.106 @@ -532,7 +535,7 @@
1.107 struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
1.108 SLresult result;
1.109
1.110 - LOGI("======openslES_PlayDevice( )======");
1.111 + LOGV("======openslES_PlayDevice( )======");
1.112
1.113 /* Queue it up */
1.114 result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, audiodata->pmixbuff[audiodata->next_buffer], this->spec.size);