Sample of using android's system library (libmedia.so) to record and play audio. It's faster than Java library and OpenSL. See image below to know how them work:

alt tag

And we have two ways to use the libmedia.so: The fisrt is make a fake library what have the same function's name with libmedia.so. But the fake library will not implement any function. we just use it to reference libmedia.so:

alt tag

In the second, we use dlfcn library to open system library and call the function of system library. I use this way in my project because in this way, we can implement it for multi version of android. Because the libmedia.so can be update with the android's version. So, with same function we can have different implementation in different android's version:

alt tag

The image below will show you how to implement the second way:

alt tag

Finally, this is the comparison of three way to implement record and play audio in android (Java library, OpenSL, Android system library):

alt tag