Hi,
I have a requirement to inject a custom global audio effect in Android (at the core system-level) to the audio pipeline. The requirement is that every buffer of audio that will output from the speaker, ear-piece or a2dp routes will be processed with a custom effect.
I'll be building a custom ROM which includes this feature, implemented as a custom *.so library (software only, no hardware). The library expects 16bit signed stereo PCM audio buffers and output the same.
The library is software based so there will be no need for drivers & porting. Also, I started looking into the AudioFlinger code in android-4.1.2_r1 (maguro), but I'm open to check out newer branches too.
I'm familiar with Android Core sources and been looking into the media server implementation, and AudioFlinger specifically.
I found the lines of code that the AudioFlinger threads writes the PCM buffers to the HAL (to the output sink). Please correct me if I'm wrong here:
1) The Mixer (inherits from PlaybackThread) & FastMixer (Thread, for low latency) threads are the ones responsible for mixing the buffers from the currently played tracks and passing them to the HAL, for the actual sound to come out of the speaker or ear piece.
2) The DuplicatingThread & DirectoutputThread (both inherit from PlaybackThread) are somehow related to A2DP (BT). I'll be happy for some info about them.
With the lines of code above (in 1), I was able to add my changes so that the audio effect was global to speaker output (did not try ear piece yet) by calling my libraries methods on the mixed audio buffer prior to writing it into the sink. Let's assume speaker route is enough for now.
In order to use a better design approach I've been looking into the native API of audio effects in: hardware/libhardware/include/hardware/audio_effect.h and the source code of the built-in audio effects provided with AOSP (visualizer, virtualizer etc.), including the audio_effects.conf file that maps the libraries of the native effects to uuid(s).
Wrapping my effect library this way would be perfect (it actually maps 1:1 with the API in the above header), but some things are not clear to me here. It seems like this API was deigned to eventually expose these effects to the Java Layer (Apps), to be used by apps (and per-track - not sure about this).
I did not find (yet?) a way to configure, in code or in the conf file, an audio effect library to load with the initialization of AudioFlinger or the playback threads.
I'll be happy to hear if anyone had experience with this low level audio effects API (for custom needs) and if this can be used for my needs.
Thanks.
Omri