Skip to content

Add native AAudio low-latency renderer#567

Open
olibols wants to merge 1 commit into
ClassicOldSong:moonlight-noirfrom
olibols:fix-aaudio-low-latency
Open

Add native AAudio low-latency renderer#567
olibols wants to merge 1 commit into
ClassicOldSong:moonlight-noirfrom
olibols:fix-aaudio-low-latency

Conversation

@olibols

@olibols olibols commented Jun 5, 2026

Copy link
Copy Markdown

Summary

  • Add a native AAudio renderer for Android O+ as the preferred low-latency audio path when system audio effects are disabled.
  • Keep the existing AudioTrack renderer as a fallback when AAudio is unavailable or setup fails.
  • Fix audio renderer preference wiring so enableAudioFx is passed to the renderer instead of playHostAudio.
  • Document the AAudio renderer in the README feature list.

Motivation

Some Android TV devices appear to deny AudioTrack's fast/low-latency output path even when Moonlight requests it, which can cause noticeable delayed audio while video and input latency remain low. A Google TV Streamer on Android TV 14 showed roughly 0.5s-1s delayed audio with the existing AudioTrack path.

The native AAudio callback path fixes the issue on that device in testing while preserving AudioTrack fallback for compatibility.

Related issues

This should address the same class of Android TV audio-latency reports as:

Implementation notes

  • AAudio is attempted only on Android O+ and only when system audio effects are disabled, because the low-latency path is incompatible with the effects pipeline.
  • The native renderer requests low-latency performance mode and exclusive sharing first, falling back to shared mode if needed.
  • A small native ring buffer feeds the AAudio data callback and drops old samples if the buffer fills to avoid latency growth.
  • The existing pending-audio-duration guard is preserved in the wrapper.

Tested

  • Built successfully:
    ./gradlew :app:assembleNonRoot_gameDebug
  • Installed app-nonRoot_game-armeabi-v7a-debug.apk on Google TV Streamer.
  • Confirmed audio delay was resolved on first test with system equalizer support disabled.

@lightrush

Copy link
Copy Markdown

This is very interesting. I didn't think it could be solved. Assumed it's just the buffer size that Google's chosen and that's it. Curious why adding a USB DAC workaroubds the issue. Whether it uses lower latency to begin with.

@ClassicOldSong

Copy link
Copy Markdown
Owner

Thanks for the PR, have you verified this still work with surround sound on AVR systems?

@olibols

olibols commented Jun 8, 2026

Copy link
Copy Markdown
Author

Thanks for the PR, have you verified this still work with surround sound on AVR systems?

Sorry I have been unable to test on anything other than my setup using just my tv's speakers. Apologies for the limited test surface.

@olibols

olibols commented Jun 8, 2026

Copy link
Copy Markdown
Author

Maybe it could be exposed as an experimental setting in the nightly build until it's been tested by more users.

@lightrush

Copy link
Copy Markdown

Maybe it could be exposed as an experimental setting

I would do exactly that. Would avoid most opposition and should make the maintainers calmly merge it.

@olibols

olibols commented Jun 11, 2026

Copy link
Copy Markdown
Author

Okay would just like to see what the maintainers say before I put any more into the PR

@udllpn

udllpn commented Jun 13, 2026

Copy link
Copy Markdown

Thank you very much! This is what I was looking for for a long time.

How can I download a build with this change incorporated?

@dbolger

dbolger commented Jun 13, 2026

Copy link
Copy Markdown

@olibols Would you be able to provide a build? Would love to try it out on my TV without setting up the entire Android SDK suite on my machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants