Fixed static and buzzing when trying to use floating point audio on the OpenSL ES audio driver.

This commit is contained in:
Sam Lantinga 2019-05-23 13:47:27 -07:00
parent e401b95025
commit 02f9667a08

View File

@ -35,13 +35,14 @@
#define LOG_TAG "SDL_openslES" #define LOG_TAG "SDL_openslES"
#if 0 #if 0
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
// #define LOGI(...) do {} while (0) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
// #define LOGE(...) do {} while (0) //#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
#define LOGV(...)
#else #else
#define LOGI(...)
#define LOGE(...) #define LOGE(...)
#define LOGI(...)
#define LOGV(...)
#endif #endif
/* engine interfaces */ /* engine interfaces */
@ -193,7 +194,7 @@ static void
bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
{ {
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) context; struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) context;
LOGI("SLES: Playback Callmeback"); LOGV("SLES: Playback Callmeback");
SDL_SemPost(audiodata->playsem); SDL_SemPost(audiodata->playsem);
return; return;
} }
@ -223,25 +224,27 @@ openslES_CreatePCMPlayer(_THIS)
SLresult result; SLresult result;
int i; int i;
#if 0 /* If we want to add floating point audio support (requires API level 21)
SDL_AudioFormat test_format = 0; it can be done as described here:
https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
test_format = SDL_FirstAudioFormat( this->spec.format ); */
#if 1
/* Just go with signed 16-bit audio as it's the most compatible */
this->spec.format = AUDIO_S16SYS;
#else
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
while (test_format != 0) { while (test_format != 0) {
if (SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format)) { if (SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format)) {
break; break;
} }
test_format = SDL_NextAudioFormat(); test_format = SDL_NextAudioFormat();
} }
if ( test_format == 0 ) { if (test_format == 0) {
/* Didn't find a compatible format : */ /* Didn't find a compatible format : */
LOGI( "No compatible audio format!" ); LOGI( "No compatible audio format, using signed 16-bit audio" );
return SDL_SetError("No compatible audio format!"); test_format = AUDIO_S16SYS;
} }
this->spec.format = test_format; this->spec.format = test_format;
#endif #endif
@ -250,7 +253,7 @@ openslES_CreatePCMPlayer(_THIS)
LOGI("Try to open %u hz %u bit chan %u %s samples %u", LOGI("Try to open %u hz %u bit chan %u %s samples %u",
this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format), this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
this->spec.channels, (test_format & 0x1000) ? "BE" : "LE", this->spec.samples); this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
/* configure audio source */ /* configure audio source */
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, NUM_BUFFERS }; SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, NUM_BUFFERS };
@ -496,7 +499,7 @@ openslES_WaitDevice(_THIS)
{ {
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden; struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
LOGI("openslES_WaitDevice( )"); LOGV("openslES_WaitDevice( )");
/* Wait for an audio chunk to finish */ /* Wait for an audio chunk to finish */
/* WaitForSingleObject(this->hidden->audio_sem, INFINITE); */ /* WaitForSingleObject(this->hidden->audio_sem, INFINITE); */
@ -522,7 +525,7 @@ openslES_GetDeviceBuf(_THIS)
{ {
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden; struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
LOGI("openslES_GetDeviceBuf( )"); LOGV("openslES_GetDeviceBuf( )");
return audiodata->pmixbuff[audiodata->next_buffer]; return audiodata->pmixbuff[audiodata->next_buffer];
} }
@ -532,7 +535,7 @@ openslES_PlayDevice(_THIS)
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden; struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
SLresult result; SLresult result;
LOGI("======openslES_PlayDevice( )======"); LOGV("======openslES_PlayDevice( )======");
/* Queue it up */ /* Queue it up */
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, audiodata->pmixbuff[audiodata->next_buffer], this->spec.size); result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, audiodata->pmixbuff[audiodata->next_buffer], this->spec.size);