Basic Design Pattern for Realtime Audio on Android

98 views
Skip to first unread message

Martin Roth

unread,
Dec 4, 2009, 7:20:56 AM12/4/09
to Android Music Developers
Alex, it was great to meet you on Wednesday. Thanks for starting the
group! Hopefully we can get more people involved.

One thing that has become clear is that a canonical design pattern for
low-latency real-time audio has emerged for Android. From a high
level, the audio thread looks like:

audioRecord.read(inputBuffer, 0, inputBuffer.length);
audioGenerator.processBuffers(inputBuffer, outputBuffer); // this
method should be implemented with the NDK
audioTrack.write(outputBuffer, 0, outputBuffer.length);

Of course, the audio thread should be set to the maximum priority:
Thread.setPriority(Thread.MAX_PRIORITY);

And the process in which the thread is running should also be set the
maximum priority:
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);

Unfortunately there is no native access to the audio buffers yet, and
so we must always go through Java. This isn't ideal, but it is the
best that we can do at the moment.

glasto...@googlemail.com

unread,
Dec 4, 2009, 2:28:50 PM12/4/09
to Android Music Developers
Thanks, Martin! I agree, that's very much the same pattern I use
(though I confess I didn't know about the constants- another reason I
should be using Eclipse!)
Reply all
Reply to author
Forward
0 new messages