From 2050f6cb431a6d86734f0e998ca7916619144e3f Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Wed, 25 May 2016 15:13:57 -0700 Subject: [PATCH] AudioAttributes docs: warn about small buffer size with FLAG_LOW_LATENCY Explain buffer size optimization. This CL has no code changes, just documentation changes. Bug: 28802853 Change-Id: I91942f00a3e9691e4fc05b24656b8bf4cb538bc2 Signed-off-by: Phil Burk --- media/java/android/media/AudioAttributes.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index a3bbdfcb26274..5286f8fa5ad31 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -225,9 +225,20 @@ public final class AudioAttributes implements Parcelable { public final static int FLAG_BYPASS_MUTE = 0x1 << 7; /** - * Flag requesting a low latency path. + * Flag requesting a low latency path when creating an AudioTrack. * When using this flag, the sample rate must match the native sample rate * of the device. Effects processing is also unavailable. + * + * Note that if this flag is used without specifying a bufferSizeInBytes then the + * AudioTrack's actual buffer size may be too small. It is recommended that a fairly + * large buffer should be specified when the AudioTrack is created. + * Then the actual size can be reduced by calling + * {@link AudioTrack#setBufferSizeInFrames(int)}. The buffer size can be optimized + * by lowering it after each write() call until the audio glitches, which is detected by calling + * {@link AudioTrack#getUnderrunCount()}. Then the buffer size can be increased + * until there are no glitches. + * This tuning step should be done while playing silence. + * This technique provides a compromise between latency and glitch rate. */ public final static int FLAG_LOW_LATENCY = 0x1 << 8;