Reputation: 557
I'm trying to implement and audio processor and android, where the input will be sine wave generated, and then some effects will be impemented (echo, distortion, etc.) so how should I design my application regarding threading and buffering.
Please help if there is any architecture that should be followed
Upvotes: 1
Views: 1265
Reputation: 20027
Gstreamer has been ported to android. It's a framework for handling a multitude of formats and playing, transcoding and creating effects also in realtime.
One can easily build own filters, if you can't find correct parametrizations from the existing ones.
Upvotes: 0
Reputation: 2215
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.
Upvotes: 3