bsnes-emu / bsnes

bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.
Other
1.64k stars 154 forks source link

[Question/Feature Request] Display HZ calculator based on Audio Rate #248

Closed Zerowalker closed 2 years ago

Zerowalker commented 2 years ago

As bsnes values accuracy you are mostly stuck with either stuttering video or crackling audio unless you have a G/FreeSync monitor.

So if you sync to the monitor normally, the cause of crackling audio is cause it will fill up too fast or too slow, in other words the audio rate (let's say "emulator hz") is not the same as the display hz, they are not in sync.

So if i am not wrong here, the rate is constant, so the the "emulator hz" should always be the same on that particular cpu right?

If so that means if you calculate it you can figure out which display hz you need in order for them to be in sync, which means if you set your monitor to that hz (say 60.16hz) the buffer will "never" run out or fill up too fast, so you get the best of both worlds, but with manual syncing instead of having it dynamic.

So with that bad explanation out of the way i am trying to figure out how to achieve this. The source code is quite advanced for me so i can't really figure out where the audio rate is decided so i don't know where to start. If i can get some help with that i think i should be able to make something up, at least in a simplistic way.

So this "issue" is more of a feature request, but something will try do myself but need some directions i guess.

Hopefully i didn't embarrass myself too much haha.

Screwtapello commented 2 years ago

The audio playback rate depends entirely on the quartz crystal built into your sound card. Every physical crystal reverberates at a slightly different frequency, based on molecular-level imperfections in the crystal structure. Even the same crystal can change frequency over time, based on the ambient temperature. As a result, it's not practically possible to set your monitor to a particular refresh-rate that guarantees it will keep up with your audio output.

However, if you have a variable-refresh-rate monitor (as many gaming monitors are these days) then bsnes can manage the refresh-rate on its own, dynamically changing it to match.

Alternatively, for certain audio backends bsnes supports "dynamic rate control", resampling the audio to match the monitor frequency.

Both these approaches are more practical than trying to set your monitor to a "perfect" fixed frequency, and they can be used today with no code changes required.

Zerowalker commented 2 years ago

That i do know, thought it was linked to the cpu here and not the sound card for some reason. But i know they see 1 second differently, learned that the hard way when capturing from external sources.

I do know that you can't guarantee it, but if you get very close the desync can be like 10ms per hour, which is so low that crackling will occur so rare that it's really a thing. But i didn't think of the variation, i recall knowing about that before now that you brought it up, thanks. I do believe that variation is quite small when it comes to normal operation (difference within normal temperatures), but i may be wrong. As for the age that's it's kinda like calibrating your monitor, you have to redo it after a year or two if you want the same level of accuracy.

I would personally love a variable-refresh-rate monitor, but as i want a monitor with 16:10 and more towards the image quality then "gaming" quality, there simply is no monitor there. Of course that's just my own fault for being picky so not really complaining.

As for the "dynamic rate control", i have had no good luck with that, it doesn't seem to help, and after awhile the audio just goes out completely and i have to refresh the driver (in bsnes) for it to work again. No clue what that's about, if you have a clue please do tell, i haven't found anything.

I agree with you that these are more practical, and will fully work, not denying that in the slightest (especially the display one). It's just that those options aren't "available" for me, or well one is broken.

Though when you brought up the soundcard i think i know what to look at, as i have done this before to sync up external sources in a hacky way, it might just work here for me as well.

EDIT:

Okay my idea fell flat, the soundcard i use is inbuilt and as far as i can tell it's in sync with the cpu, no deviation in the timestamps when comparing them over time.