From 54570fdfb499ac8b45e71249f41a21277d0f55df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Sep 2019 09:26:52 +0200 Subject: [PATCH] Android OpenSL: Fix bug where we should have enqueued two buffers on startup. I don't actually think this matters much though. Seems to make absolutely no difference on any of my devices, but you never know. --- android/jni/native-audio-so.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/android/jni/native-audio-so.cpp b/android/jni/native-audio-so.cpp index 27729ab2cd..b2d684da00 100644 --- a/android/jni/native-audio-so.cpp +++ b/android/jni/native-audio-so.cpp @@ -124,13 +124,16 @@ bool OpenSLContext::Init() { result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); assert(SL_RESULT_SUCCESS == result); - // Render and enqueue a first buffer. (or should we just play the buffer empty?) - buffer[0] = new short[framesPerBuffer * 2]; - buffer[1] = new short[framesPerBuffer * 2]; + // Enqueue two empty buffers. + buffer[0] = new short[framesPerBuffer * 2]{}; + buffer[1] = new short[framesPerBuffer * 2]{}; curBuffer = 0; - audioCallback(buffer[curBuffer], framesPerBuffer); - + result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeof(buffer[curBuffer])); + if (SL_RESULT_SUCCESS != result) { + return false; + } + curBuffer ^= 1; result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeof(buffer[curBuffer])); if (SL_RESULT_SUCCESS != result) { return false;