Permalink
Browse files

Add option to use nbasili's low latency Android patch.

  • Loading branch information...
AerialX committed Sep 18, 2011
1 parent 13208eb commit 5fae12e4ab0ebf0781a0a7a6d96a10e19008dc23
Showing with 37 additions and 1 deletion.
  1. +30 −1 Alc/backends/android.c
  2. +4 −0 CMakeLists.txt
  3. +3 −0 config.h.in
View
@@ -89,7 +89,12 @@ static void* thread_function(void* arg)
jobject track = (*env)->NewObject(env, cAudioTrack, mAudioTrack,
STREAM_MUSIC, sampleRateInHz, channelConfig, audioFormat, device->NumUpdates * bufferSizeInBytes, MODE_STREAM);
+#ifdef HAVE_ANDROID_LOW_LATENCY
+ int started = 0;
+ size_t overallBytes = 0;
+#else
(*env)->CallNonvirtualVoidMethod(env, track, cAudioTrack, mPlay);
+#endif
jarray buffer = (*env)->NewByteArray(env, bufferSizeInBytes);
@@ -102,7 +107,26 @@ static void* thread_function(void* arg)
aluMixData(device, pBuffer, bufferSizeInSamples);
(*env)->ReleasePrimitiveArrayCritical(env, buffer, pBuffer, 0);
- (*env)->CallNonvirtualIntMethod(env, track, cAudioTrack, mWrite, buffer, 0, bufferSizeInBytes);
+#ifdef HAVE_ANDROID_LOW_LATENCY
+ if (bufferSizeInBytes >= 0)
+ {
+ if (started)
+ {
+#endif
+ (*env)->CallNonvirtualIntMethod(env, track, cAudioTrack, mWrite, buffer, 0, bufferSizeInBytes);
+#ifdef HAVE_ANDROID_LOW_LATENCY
+ }
+ else
+ {
+ overallBytes += (*env)->CallNonvirtualIntMethod(env, track, cAudioTrack, mWrite, buffer, 0, bufferSizeInBytes);
+ if (overallBytes >= (device->NumUpdates * bufferSizeInBytes))
+ {
+ (*env)->CallNonvirtualVoidMethod(env, track, cAudioTrack, mPlay);
+ started = 1;
+ }
+ }
+ }
+#endif
}
else
{
@@ -160,6 +184,11 @@ static ALCenum android_open_playback(ALCdevice *device, const ALCchar *deviceNam
device->szDeviceName = strdup(deviceName);
device->ExtraData = data;
+#ifdef HAVE_ANDROID_LOW_LATENCY
+ device->Frequency = 22050;
+ device->NumUpdates = 1;
+#endif
+
return ALC_NO_ERROR;
}
View
@@ -37,6 +37,7 @@ OPTION(PULSEAUDIO "Check for PulseAudio backend" ON)
OPTION(COREAUDIO "Check for CoreAudio backend" ON)
OPTION(OPENSL "Check for OpenSL backend" ON)
OPTION(ANDROID "Check for Android backend" ON)
+OPTION(ANDROID_LOW_LATENCY "Enable Android low-latency backend" OFF)
OPTION(WAVE "Enable Wave Writer backend" ON)
OPTION(REQUIRE_ALSA "Require ALSA backend" OFF)
@@ -630,6 +631,9 @@ IF(ANDROID)
SET(HAVE_ANDROID 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/android.c)
SET(BACKENDS "${BACKENDS} Android,")
+ IF(ANDROID_LOW_LATENCY)
+ SET(HAVE_ANDROID_LOW_LATENCY 1)
+ ENDIF()
ENDIF()
ENDIF()
ENDIF()
View
@@ -41,6 +41,9 @@
/* Define if we have the Android backend */
#cmakedefine HAVE_ANDROID
+/* Define if we want to use the low latency Android backend */
+#cmakedefine HAVE_ANDROID_LOW_LATENCY
+
/* Define if we have the Wave Writer backend */
#cmakedefine HAVE_WAVE

0 comments on commit 5fae12e

Please sign in to comment.