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
Suggestions:
Use an AudioTrack object in stream mode (
AudioTrack.MODE_STREAM) and keep it supplied with data using a loop which continuously calls the blockingAudioTrack writefrom 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.