How do I reduce audio latency in xamarin.android application

Hi

I am trying to simultaneously record and play audio on a Xamarin Android app. I am having issues with latency. I'm not sure how to go about reducing it. When I play around with the buffer size and sample rate(as suggested by the documentation) I get the "Pop-Corn" effect on my audio output and no reduced latency.

In order for sound to record and play relatively clearly with no "Pop-Corn" efffect, I use a 44100Hz Sample rate and 320 Buffer size but latency is still an issue (Xiaomi Redmi 4A testing device).

Has anyone managed to solve this?

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    @jpillay07
    Try the follows to reduce latency:

    1. Do not do any audio processing in Java. Keep all audio processing in C++.
    2. Use the JNI (Java Native Interface) for successful interoperability between native (C++) code and Java. (Prepare yourself, this is not necessarily fun).
    3. Always make your code sample-rate and buffer size agnostic. Your app should work with any sample-rate or buffer size.
    4. Do not depend on audio features offered by Android because Android audio feature implementation/function is erratic, unpredictable and may be device dependent.
    5. The CPU governor reduces CPU frequency and may cause audio drop-outs. We once advised developers to use 'fake touch events' to keep the CPU governor from activating. However, this only works on Nexus devices. SuperpoweredCPU is a universal solution for Android CPU Frequency Scaling and is now included in Superpowered.
    6. Keep in mind that there are multiple, different audio signal paths and each has its own specific latency.
    7. Using Bluetooth audio will add minimum 100ms to latency.
    8. Wifi will also add latency. Highly variable, depends on implementation and needs to be measured on site. Can range from 40 ms to several seconds.
    9. For audio processing, do not use OpenSL ES ‘wrappers’ or OpenSL ES itself. Use self-contained android low latency audio API in static libraries like Superpowered Audio SDK.
    10. Use OpenSL ES for audio I/O only

    See the link: https://superpowered.com/android-audio-low-latency-primer

Sign In or Register to comment.