waydroid/waydroid

Reduce audio latency

T2hhbmEK opened this issue · 14 comments

I'm experiencing somewhat at least 300ms audio lagging using WayDroid. It would be better if WayDroid improves it.

There was a hack to Anbox to fix similar issue.

anbox/anbox#1034

It fixed the issue by synchronizing the Android audio thread with the client. It requires changing some APIs and a rebuilding of the Android image. It may cause audio to stop working if the client application isn't running.

There maybe some better implementations. That remains to be discussed.

alright, so I measures a round trip latency of 480~ms using jackdelay loop, this is certainly something that can be improved on for sure

I'm also experiencing this, initially I just figured it was my Bluetooth headphones acting up but I got the same latency issues with my onboard speakers.

I'm also experiencing this. The lag is especially annoying since I'm playing GDPS Editor 2.2 (Geometry Dash), which requires audio to sync (almost) perfectly.

Waydroid connects to the host Pulseaudio socket, someone with knowledge may look into https://github.com/waydroid/android_hardware_waydroid/tree/lineage-18.1/audio to figure out what's causing all the delay, perhaps playing with some environment variables from host (or even system.img/init.environ.rc) side like PULSE_LATENCY_MSEC=60 would help too?

Some further reading for someone interested: https://juho.tykkala.fi/Pulseaudio-and-latency

Waydroid connects to the host Pulseaudio socket, someone with knowledge may look into https://github.com/waydroid/android_hardware_waydroid/tree/lineage-18.1/audio to figure out what's causing all the delay, perhaps playing with some environment variables from host (or even system.img/init.environ.rc) side like PULSE_LATENCY_MSEC=60 would help too?

Some further reading for someone interested: https://juho.tykkala.fi/Pulseaudio-and-latency

IIRC I did try this to no success, but as I have no facilities to make test builds atm, I haven't really looked into it

Seems like there are more victims of this I've had multiple people report that the audio latency makes games like sonolus (works with libhoudini) very much unenjoyable

Linux: Arch
Audiostack: Pipewire
CPU: ryzen 2600
GPUL rx 580 + arc A350

@JamiKettunen do you have any other potential variables? I was able to get the latency down to 350ms using that specific one, which brings it down to usable range for a decent number of folk (probably)

Have been using redroid and scrcpy for a while. scrcpy started to support audio forwarding recently. Not yet checked WayDroid recently. IMO Audio latency is much lower. I prefer full screen emulation and redroid seems superior for my use case.

Overlaying a file /system/etc/init/audio.rc containing the following:

on init
    export PULSE_LATENCY_MSEC 60
    export PIPEWIRE_LATENCY 96/48000

I'm getting a lower QUANT on pw-top, to little success

you can use a "Microphone to speaker" device and pipewire + jackdelay to get a physical number to check.

from what I can tell there's a slight improvement, but it's still very much unplayable. Not sure if libhoudini is inducing latency as well.
I believe the offset I set is 200ms? I can't get mic-to-speaker apps on Waydroid to work at all so jack_delay won't work on my machine :(

Scrcpy seems to be able to forward audio with a little lower latency, but it still not feels like real-time audio.
I use these command to get sound from scrcpy;
scrcpy --no-video --audio-codec=aac --audio-encoder='OMX.google.aac.encoder'

Additionally --audio-buffer=value and --audio-bit-rate=value arguments are available.

Scrcpy seems to be able to forward audio with a little lower latency, but it still not feels like real-time audio. I use these command to get sound from scrcpy; scrcpy --no-video --audio-codec=aac --audio-encoder='OMX.google.aac.encoder'

Additionally --audio-buffer=value and --audio-bit-rate=value arguments are available.

any chance you could check the delay? I use a microphone to speaker app and jack_delay to test typically, I don't have time atm

Scrcpy seems to be able to forward audio with a little lower latency, but it still not feels like real-time audio. I use these command to get sound from scrcpy; scrcpy --no-video --audio-codec=aac --audio-encoder='OMX.google.aac.encoder'
Additionally --audio-buffer=value and --audio-bit-rate=value arguments are available.

any chance you could check the delay? I use a microphone to speaker app and jack_delay to test typically, I don't have time atm

I could not figure out how to use jack_delay to measure audio latency of waydroid.