Suggestions:
Use an AudioTrack object in stream mode (AudioTrack.MODE_STREAM
) and keep it supplied with data using a loop which continuously calls the blocking AudioTrack write
from a specialised non-UI thread. That thread reads from a circular buffer where data is prepared by other threads.
Note that even though the minimum internal audio buffer size is constrained by the system ( be sure to check the result of the construction of the AudioTrack object ) you can write the data in smaller chunks, which can reduce your average latency.
Avoid doing floating point arithmetic, especially computing trig functions (e.g. sine) and floating point/integer conversions, in real time; prepare as much of the waveforms as you can in advance, and store them in cyclic tables; keep your PCM amplitudes in floating point form until the final step.