tonioni / WinUAE

WinUAE Amiga emulator
http://www.winuae.net/
552 stars 90 forks source link

Automatic sound emulation switching problems #279

Closed johnnovak closed 9 months ago

johnnovak commented 10 months ago

Automatic sound switching causes problems in games that don't have continuous background music but only play sound effects sporadically. What happens is the auto-switching disables the sound output after about 2 seconds, which causes a loud pop (very noticeable in good quality headphones). Then when the next sound effect plays, there is usually another loud pop when the sound is re-enabled, and frequently there is some "stuttering" at the start of the sounds. Needless to say, this is quite jarring and far from great.

I've been experiencing this for years now in games that mostly only feature sound effects (e.g., Eye of the Beholder I and II, Maniac Mansion, etc.) and always thought this was a game bug, but no -- this is introduced by the auto switching. I'm glad that I finally found the reason, but I imagine most people would run into this and most won't find out how to fix it.

With auto switching disabled (so sound always on), the problem is 100% gone in all problematic games.

I highly suggest to do the following two things:

  1. Default to sound always enabled in the Quickstart configs. Enabling cycle accurate emulation but doing this trickery with the audio makes little sense. I don't think sound always on adds significant CPU overhead in the grand scheme of things.

  2. When auto switching is enabled, I assume you disengage the sound at the sound API level (in other words, stop feeding the buffer because sound output is paused). From my own personal experience, don't do that, as that will invariably will result in clicks and pops and some stuttering when engaging/disengaging the sound generation. Never pause the sound output at the API level, so never stop feeding the buffer with data, keep the audio running all the time. Just feed it with zeroes when the sound is disabled at the emulation level. This is practically what all audio software do; they always feed the buffer with zeroes, even when the playback is stopped at the application level and there should be no sound output. Otherwise you'll end up in stutter and click & pop hell when you stop and restart the playback. That's just the way it is with audio APIs on practically all platforms (not just Windows).

If you do 2), I guess you can continue to enable auto switching in the Quickstart configs if you really want to as the problem will be gone.

johnnovak commented 10 months ago

Extra info: the problem is because some games leave the audio output in a "constant DC offset" state when there is no sound. Then when you abruptly turn off the sound, it causes a click. One possible solution would be to fade the output over a few milliseconds to silence, as opposed to abruptly stopping it when the auto-switching kicks in.

johnnovak commented 9 months ago

Defaulting to no auto switching in 5.2.0 b7 fixes this, thanks.