Skip to content

audio: make SDL queue threshold configurable#1853

Open
popbones wants to merge 2 commits intomoonlight-stream:masterfrom
popbones:audio-queue-threshold-ui
Open

audio: make SDL queue threshold configurable#1853
popbones wants to merge 2 commits intomoonlight-stream:masterfrom
popbones:audio-queue-threshold-ui

Conversation

@popbones
Copy link
Copy Markdown

@popbones popbones commented Apr 3, 2026

Summary

  • add a user-configurable setting for Moonlight's pending SDL audio queue threshold
  • keep the default threshold at 30 ms so existing behavior is unchanged unless the user opts in
  • pass the configured threshold through to the SDL audio renderer instead of hardcoding it

Why

I was experimenting with higher values to reduce audio stuttering on my setup. Making the threshold configurable seemed preferable to changing the default for everyone.

Testing

  • no clean upstream build/test run included with this branch on this machine
  • feature change reviewed locally and kept narrowly scoped to settings/UI plus SDL audio threshold plumbing

Notes

For certain music like Cyberpunk 2077 title screen, the 30ms can cause the audio glitch very disorienting. For me, increasing it to 100 makes it unnoticeable for most of the time and only glitch a bit every now and then. See my comment in #1691

I got the idea when I had similar issues with chiaki-ng to play my PS5 games on SteamDeck. When in a bad spot, it may behave the same way. But Chiaki-ng has a setting to change something I assume do the same thing. And it worked for me.

@ns6089
Copy link
Copy Markdown
Contributor

ns6089 commented Apr 4, 2026

Audio crackling happens in two situations: buffer underrun and buffer overflow. So you need separate values for each of them: minimal buffer fullness at which playback gets started (either in the beginning or after buffer underrun), and maximum buffer size after which audio packets begin getting dropped. Then there's relative clock drift, but let's leave it aside for now as solving that properly requires moonlight protocol extension and realtime audio time-stretching DSP.

@popbones
Copy link
Copy Markdown
Author

popbones commented Apr 7, 2026

Thanks @ns6089

I’ve pushed some code and I hope it addresses your comment.

And here is a screenshot

image

I kept the default to effectively the current behavior since users should only need to tweak these when they have problems.

@ns6089
Copy link
Copy Markdown
Contributor

ns6089 commented Apr 7, 2026

How does it perform for you with 15ms playback and 30ms drop threshold? Those look like reasonable defaults to me, and may fix your problem without the need for the new GUI options. Since it's not a good idea to confuse the average user with advanced options placed right next to the basic ones, there's new Advanced config page in the planning, but unfortunately it's not ready yet.

@popbones
Copy link
Copy Markdown
Author

popbones commented Apr 7, 2026

How does it perform for you with 15ms playback and 30ms drop threshold? Those look like reasonable defaults to me, and may fix your problem without the need for the new GUI options. Since it's not a good idea to confuse the average user with advanced options placed right next to the basic ones, there's new Advanced config page in the planning, but unfortunately it's not ready yet.

For me, it's mainly the drop threshold, changing that to 100ms would make Cyberpunk 2077 title music work generally fine. I also tried 50ms and 70ms, but they seemed to be still too short. Changing the play side doesn't really affect my problem other than delaying the audio.

My suspicion is that some kind of jitter in Mac WiFi (probably related to AWDL, no proof though) caused the timing of audio to make tiny gaps in certain types of music or sound effects more noticeable.

My theory is that Moonlight receives bursty audio data that exceeds 30ms in durations longer than 30ms causing some data getting dropped.

This could cause the continuous undertone in Cyberpunk 2077 title music to sound like repeated onsets of the same sample instead of continuous ones. And this doesn't seem to happen on the iOS client in the same room.

Update:

I'm happy to wait for the advanced settings page while using my local build before it's ready. Just thought this might be helpful.

I see other people has similar problem and there didn't seem to be a definitive workaround yet. Myself has been having this problem over a year even after I upgraded my LAN network to latest generation. I guess for wireless network, there's always gonna be things like this.

It could be one of the first knob users can try if they have such issues. It's definitely more approachable than diving into network diagnostics and QoS.

@cgutman
Copy link
Copy Markdown
Member

cgutman commented Apr 9, 2026

I don't think I want to make this a UI option (at least not yet), but I'm willing to accept a PR that uses environment variables to override the defaults if you'd like to go that direction in the near term.

@popbones
Copy link
Copy Markdown
Author

popbones commented Apr 9, 2026

@cgutman

I wonder if there’s other places than environment variables since it would be rather cumbersome to use on Mac. Do you think it would be possible to make the setting readable from the config file (com.moonlight-stream.Moonlight.plist) but not exposed in the UI?

@hamzah-hayat
Copy link
Copy Markdown

@popbones Just wanted to say thanks, I am running a Macbook air (M1) and was having severe audio stuttering issues when connecting to my main PC.
I compiled your branch and also set the SDL queue threshold to 100ms and it completely solved my audio stuttering
I'm so grateful, thanks so much ☺️

@popbones
Copy link
Copy Markdown
Author

@popbones Just wanted to say thanks, I am running a Macbook air (M1) and was having severe audio stuttering issues when connecting to my main PC. I compiled your branch and also set the SDL queue threshold to 100ms and it completely solved my audio stuttering I'm so grateful, thanks so much ☺️

I'm glad it's helpful to you. 😊

@Meliods23
Copy link
Copy Markdown

@popbones

I love you my good sir, ran your changes after hamzah-hayat mentioned they worked for him and it solved my issue too on M4. I can finally enjoy frostpunk´s music. Thank you! :)

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