1

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

2 Answers2

3

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.

JulianSymes
  • 2,135
  • 22
  • 24
  • Can you help me with https://stackoverflow.com/questions/61184352/android-accessibility-service-real-time-audio-processing question – Feroz Siddiqui Apr 13 '20 at 08:54
0

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.

Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57