audio: make SDL queue threshold configurable#1853
audio: make SDL queue threshold configurable#1853popbones wants to merge 2 commits intomoonlight-stream:masterfrom
Conversation
|
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. |
|
Thanks @ns6089 I’ve pushed some code and I hope it addresses your comment. And here is a screenshot
I kept the default to effectively the current behavior since users should only need to tweak these when they have problems. |
|
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. |
|
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. |
|
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? |
|
@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'm glad it's helpful to you. 😊 |
|
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! :) |

Summary
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
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.