google / oboe

Oboe is a C++ library that makes it easy to build high-performance audio apps on Android.
Apache License 2.0
3.68k stars 561 forks source link

Unable to set PerformanceMode::LowLatency #2040

Closed jsln closed 3 months ago

jsln commented 3 months ago

Android version(s): 14

Android device(s): Raspberry Pi 5 with audio card (HifiBerry DAC+ ADC Pro)

Oboe version: 1.8.1

Short description I am unable to get low latency when compiling AOSP Android 14 on a Raspberry Pi 5 with an HifiBerry DAC+ ADC Pro. I see an audio output latency of around 120ms. I also get quite high burst size (960 frames) for the capabilities of the HW.

Steps to reproduce Built AOSP, based on https://github.com/raspberry-vanilla. Set an audio stream with:

oboe::Result result = builder.setPerformanceMode(oboe::PerformanceMode::LowLatency)
            ->setDirection(oboe::Direction::Output)
            ->setPerformanceMode(oboe::PerformanceMode::LowLatency)
            ->setSharingMode(oboe::SharingMode::Exclusive)
            ->setDataCallback(mDataCallback)
            ->setErrorCallback(mErrorCallback)
            ->setUsage(oboe::Usage::Game)   // also tried without this setting
            ->openStream(mStream);

Expected behavior I expect much better latency figures, I see an output latency of ~120ms.

Actual behavior Audio output latency is around 120ms. It seems the stream does not get build with the given parameters. This is the logcat:

image

Device Raspberry Pi 5 with HifiBerry DAC+ ADC Pro

philburk commented 3 months ago

It appears that AOSP on RPi5 for HifiBerry does not support the low-latency "FAST TRACK" audio mode. So Oboe cannot provide it.

Are you using KonstaKang? If so then perhaps they could be convinced to support this.

Have you tried a USB Audio interface?

jsln commented 3 months ago

Hi @philburk , I observe a requested buffer by the audio driver of 960 samples (20ms). My understading is that not having FAST TRACK prevents us from getting smaller buffers, am I right?

However, initially that should not be a problem for us, around 20/30 ms should be good, the real problem is that the output is produced very consistently (with low jitter) with 120/125 ms delay. Could this also be explained by not having FAST TRACK implemented?

I guess USB audio would introduce other sources of latency, right? I have not tried this. Also the observed latency would depend on the USB hardware, it would be much easier to provide a HifiBerry with 3.5mm output. Furthermore, my measurement setup is much easier by plugging a scope to a 3.5 jack output.

Thanks!

philburk commented 3 months ago

My understading is that not having FAST TRACK prevents us from getting smaller buffers, am I right?

Right. 20 ms buffers is typical for NON-FAST tracks.

120/125 ms delay. Could this also be explained by not having FAST TRACK implemented?

Yes. The FAST track is designed to provide lower latency. Typically 15-40 msec for output.

USB audio would introduce other sources of latency, right?

It can. A USB-to-3.5mm adapter can add 2-50 msec, depending on the Manufacturer. The simple Google adapter only adds 2-3 msec. Some other adapters have fancy echo cancellation and processing that adds 4-50 msec.

Generally, USB audio interfaces like a Presonus 26C usually only add about 2 msec.

I see that you are discussing this on the raspberry-vanilla site. That is the right place to ask.

jsln commented 3 months ago

Thanks for your help, @philburk , I will try with the simple Google adapter, and continue the discussion in the raspberry-vanilla site.