Hello,

I'm trying to write an audio sink for my application. I am using the
AudioTrack class and it works pretty well. In other words I get the
audio to play correctly (stream mode).

I am using it in C code via the NDK, but that shouldn't matter. The
AudioTrack creation and feeding is done in a separate thread from the
UI.

However, I am having issues with the speed in which it's handling the
AudioTrack.write() call. As you can see in the following traces, it
takes between 50 ms to 70 ms to write 6144 shorts (or 3072 samples).
At 44100 Hz that's almost the duration of the buffer I'm writing ! I
assume that's because all the hardware buffers are used and it's
waiting to write. But I think it should rather exit right away, saying
no buffer was written (like during the pre- roll at the beggining).

I tried another technique, by checking the value returned by
AudioTrack.getPlaybackHeadPosition() to know when the amount I'm
trying to write has been freeed. AudioTrack.write() is a lot faster in
that case to write the same 6144 shorts. But then I can hear audio
glitches, even though the AudioTrack is then initialized with 4x the
value returned by getMinBufferSize() and each buffer I try to write is
the size of getMinBufferSize(). And when I write that kind of buffer
there's about 3x the min size needed by the hardware, so there
shouldn't be any underruns there.

It seems to me that AudioTrack.write() should not be blocking for so
long, as the API can return 0 if the buffers are full. Anyone noticed
such issues or has another idea to avoid such a long wait ? The
underrun I noticed also seem like a bug.

This test was done on a Nexus One. Decoding the MP3 and converting to
the right PCM kind takes considerably less time than writing the
buffer on the hardware, which is a shame given the speed of the
hardware !

02-16 09:49:13.918: WARN/corelog(14003): 00504d50-Open '/sdcard/Amanda
Blank - DJ.mp3'
02-16 09:49:14.068: WARN/corelog(14003): 00504d50-Created a new
AudioTrack 0x44b6c240 SampleRate 44100 BufferSize 12288
02-16 09:49:14.068: WARN/corelog(14003): 00504d50-calling
AudioTrack.flush()
02-16 09:49:14.408: WARN/ActivityManager(74): Activity pause timeout
for HistoryRecord{4494bcf8 com.CoreCodec.CorePlayer/
com.CoreCodec.coreui.UIWindow}
02-16 09:49:14.608: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b6c370 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.608: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:14.608: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b74030 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.608: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:14.618: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b71018 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.618: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 0
02-16 09:49:14.618: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b71018 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.618: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 0
02-16 09:49:14.618: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b71018 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.618: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 0
02-16 09:49:14.628: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b71018 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.628: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 0
02-16 09:49:14.628: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b71018 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:14.628: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 0
02-16 09:49:14.628: WARN/corelog(14003): 00504d50-calling
AudioTrack.start()
02-16 09:49:14.728: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b71018 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.008: WARN/AudioFlinger(52): write blocked for 279
msecs, 188 delayed writes, thread 0xd768
02-16 09:49:15.018: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.018: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b77048 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.018: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.028: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b7ae58 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.063: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.068: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b7de70 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.128: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.138: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b80e88 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.198: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.208: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b83ea0 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.271: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.278: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b86eb8 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.340: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.348: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b89ed0 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.413: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.418: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b8cee8 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.483: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.488: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b8ff00 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.549: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.549: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b92f18 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.619: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144
02-16 09:49:15.619: WARN/corelog(14003): 00504d50-calling
AudioTrack.write() with buffer 0x44b95f30 iBufferSize 6144 (out of
12288 bytes) iBufferOffset 0
02-16 09:49:15.688: WARN/corelog(14003): 00504d50-AudioTrack.write()
returned 6144


A longer version of the log : 
http://devcenter.coreforge.org/corepaste/pasting.php?id=syfnwh&key=8757371a

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to