libretro / RetroArch

Cross-platform, sophisticated frontend for the libretro API. Licensed GPLv3.
http://www.libretro.com
GNU General Public License v3.0
10.05k stars 1.81k forks source link

WASAPI Driver Audio Pops, Hitches and Frame Drops in Certain Cores #15920

Open Awakened0 opened 9 months ago

Awakened0 commented 9 months ago

Description

WASAPI causes frame drops, audio pops and hitches in certain cores that don't have an issue with xaudio. Also, if I mess with the WASAPI Shared Buffer Length setting, anything other than Auto or Off will cause content running in RetroArch to make a horrible buzzing noise, slow down to a crawl and become unresponsive. I'm lucky if I can get back into the UI to set it back to one of the safe options before it crashes. Turning on Exclusive mode just mutes the audio entirely. Don't notice any change with Float Format on or off.

BSNES with Yoshi's Island in level 1-1 is an easy one to play and hear it start popping and hitching. Then see it's dropping more frames compared to how smooth it is with xaudio. Mesen with Mega Man 3 is similar, but not as bad. Cores like MelonDS DS and SwanStation don't seem to have those issues though. Maybe it's something about accuracy focused cores that use interpreters?

My other audio settings are defaults, except Resampler Quality set to Highest. Setting it to Normal didn't seem to help anything.

Version/Commit

Environment information

sonninnos commented 9 months ago

Yep, bsnes seems to have something seriously wrong with audio, since all is fine with snes9x. Latency is smaller with wasapi, so the core somehow does not send data at proper rate, since even after changing the buffer size it always starts crackling after the same short while, and it seems like increasing the shared buffer size has no effect at all.

I can't replicate the buzzing thing though. Also exclusive mode works otherwise fine here, except the previous sound buffer will keep looping while in menu..

Exclusive mode does use the common audio latency buffer size though, so that explains why the audio is steady with bsnes.

Awakened0 commented 9 months ago

I got Exclusive mode to work by selecting my dedicated speakers or TV speakers over HDMI with the Device RetroArch audio setting. Default is muted for some reason in WASAPI Exclusive; maybe it's trying to use the motherboard's optical out since it's first in the list. The Speakers are set as my default output in Windows settings and I haven't had issues with that elsewhere. The audio was improved in exclusive, but there were still a few hitches in bsnes for me.

My motherboard has the Realtek ALC4080 chipset, which I guess is using USB audio. Googling that chip there are reports of crackling issues, but I haven't had that in any other game or app I have on here. Not sure what games I have installed use WASAPI though.

sonninnos commented 9 months ago

Ok, I seem to have figured out how to stop the crackling problem in shared mode. Next I'll try to look into the exclusive mode sound looping, and to prevent setting too small shared buffer so that the menu won't lock up.

bslenul commented 9 months ago

Noticed some weird performance regressions since I switched to wasapi yesterday, here's an example with the Phantom Hourglass intro using melonDS:

Wasapi (you can hear it stuttering and cracking + FPS fluctuates between low 57s and 58):

https://github.com/libretro/RetroArch/assets/33353403/d5800848-b431-4ee8-99b0-48a520c9d262

Xaudio:

https://github.com/libretro/RetroArch/assets/33353403/fca2b6c7-cd93-4dcd-8fa2-f2da43e2a90c

I still have audio with exclusive mode, but performances are even worse (~55fps in that same intro).

sonninnos commented 9 months ago

I got the remaining issues sorted, and hopefully they help with these new ones too, except I have no idea what could cause the bad performance in exclusive mode other than too small audio latency..

Shared buffer logic is refactored now, and the menu item also has dropdown selection, so time for some serious testing before pushing.

sonninnos commented 9 months ago

Please try with the new changes.

Awakened0 commented 9 months ago

Here's a video of me testing the WASAPI settings with a new build:

https://github.com/libretro/RetroArch/assets/4565863/d5c92a6a-d42a-4087-af7c-f7bdd6fbc5f7

It's much improved! I'm not noticing frame drops with the default settings, though there are still some crackles with Yoshi in BSNES (again, not there with xaudio). When I switch to Exclusive mode, I do now get audio from my default device (speakers), but the game seems to run half speed and the audio is crunchy. In the video when I turn on exclusive I guess OBS can't grab the audio, so it appears muted there. It sounds similar to when I set the Buffer length to 32 in the video, but twice as bad.

So Shared mode with the default 0 or 64 Buffer Length settings work best for my hardware.

sonninnos commented 9 months ago

There were no functional changes to exclusive mode behavior, and it is no wonder that it won't play along with recording software due to its nature. I still get normal speed and normal behavior with exclusive.

Does it not help if audio latency is increased over the default, regardless of being recorded at the same time?

Awakened0 commented 9 months ago

If I go up towards 128 or even 200 it's less crackly than at 64, but still kinda sounds like the sound is constantly cutting in and out.

Awakened0 commented 9 months ago

Tested some other cores with WASAPI Shared mode, 0 Buffer Length. Even cores that seem perfect at first will get a random crackle or pop once in awhile for me. Like in Beetle PCE, FBNeo or melonDS DS.

Could be my particular Realtek hardware or driver. But xaudio is flawless and I don't notice a latency difference between that and WASAPI, so I should probably stick to that.

bslenul commented 9 months ago

I messed with a bunch of settings and now audio sounds fine in the Phantom Hourglass intro I was using for tests. Problem is I didn't backup my retroarch.cfg before so I have no idea what setting(s?) fixed it :/ Exclusive mode still runs at ~55fps tho.

Immersion95 commented 9 months ago

Tested Wasapi Shared 0 and it's flawless for me, I'll need to test more but it was unplayable for me in some cores before (bsnes, Beetle, etc...).

I'm now changing from Xaudio to Wasapi.

Awakened0 commented 9 months ago

I tested WASAPI exclusive today with my sound output set to HDMI out from my Nvidia card instead of the 3.5mm jack on my motherboard. I didn't get any pops, clicks or hitches over that in BSNES, Mesen or any other core I tried. So those issues seemed to be tied to my Realtek onboard audio.

However, with WASAPI exclusive I do notice frame stuttering when looking at the 240p Test Suite scroll test in BSNES or BlastEm. It happens after fast forwarding or sometimes just when launching content without touching the FF hotkey. It will clear up for a bit if I bring up RetroArch's menu and dismiss it.

The frame stuttering only happens with my VRR optimized settings; 120hz refresh, swap interval 1 and Sync to Exact Content Framerate enabled. If I turn off Sync to Exact and use swap interval 2, the framerate stays smooth even after fast forwarding. xaudio is always smooth with swap 1 and Sync to Exact on.

I'm also noticing this audio distortion issue with WASAPI exclusive: https://github.com/libretro/RetroArch/issues/6927 It's particularly noticeable with Marin singing in Link's Awakening running under Sameboy. The high notes have a "warbling" to them that's not there in xaudio.

sonninnos commented 8 months ago

Please try https://github.com/libretro/RetroArch/pull/16057

Awakened0 commented 8 months ago

WASAPI shared mode with the default 0 (Audio Latency) buffer setting doesn't seem to have any hitches or pops now. No frame drops when testing scrolling with Sync to Exact Content Framerate + GSync in blastem either (they are still there in exclusive mode.) Setting buffer length to 32 still causes slowdown and popping in bsnes with Yoshi's Island. 64 in that instance is better, but there are still some hitches that aren't there compared to 0 buffer length.

Also, there is still the audio warbling that is more noticeable in high notes. It seems worse in exclusive than shared.

Comparison of Ballad of the Windfish from Link's Awakening DX, in the SameBoy core (WASAPI Shared first, then xaudio):

https://github.com/libretro/RetroArch/assets/4565863/be58fcf2-5715-4b76-b1f2-cc8d3f898d57

wasapi shared vs xaudio.zip

You should be able to hear that the notes sound much "smoother" under xaudio.

Awakened0 commented 8 months ago

Found out the warbling goes away if I disable Sync to Exact Content Framerate. Hopefully a dev who has access to a VRR display can optimize WASAPI for it at some point.

Awakened0 commented 8 months ago

So, even with Sync to Exact Content Framerate off, the warbling IS still there in WASAPI exclusive. Only goes away in shared mode. Also, in shared mode with Sync to Exact off I can hear a slight distortion if I change the buffer length to 32. And I still have the issue where if I set the length to 96 or higher I get massive slowdown and terrible audio. At least RetroArch doesn't become unresponsive anymore when I try that.

Here's a vid of me trying the different buffer length settings again:

https://github.com/libretro/RetroArch/assets/4565863/38e4c89f-f954-4eaa-9c80-390aa0512389

Awakened0 commented 8 months ago

I found out the exclusive mode warbling is affected by Dynamic Audio Rate Control under Synchronization settings if Sync to Exact Content Framerate is off. If you increase it, the warbling gets worse, and if you decrease it down to 0.000, it goes away. So maxing it out to 0.020 is a good way to make the problem more obvious for testing.

Immersion95 commented 1 month ago

Tested Wasapi Shared 0 and it's flawless for me, I'll need to test more but it was unplayable for me in some cores before (bsnes, Beetle, etc...).

I'm now changing from Xaudio to Wasapi.

Edit : It works perfectly.

The only problem is with VRR + Sync to exact framerate + Dolby Atmos on Windows