Perfect Audio Video Synchronization

Behold a small guide/faq of the sync options in retroarch for silky smooth console experience.

Preface

A game console is always in perfect sync with the TV (usually CRT) because the console itself generates the video signal, meanning NTSC games are native in 59.94Hz (audio & video) and that is exactly what the console outputs to the TV.
Emulators on the other hand do NOT have control over the refresh rate of the TV because the GPU of your device generates the video timing and it might not be perfect 59.94Hz as the console outputs.
Lets assume the GPU runs the desktop in 60.01Hz but NTSC games are still 59.94Hz, as you can see there is our problem we are trying to fix.

There are two ways we can run the emulation:

  1. In sync with NTSC audio which will be in perfect pitch in 59.94Hz but the video will be out of sync and stutter.
  2. In sync with the GPU refreshrate but the audio will be out of sync and crackle when the drift is to large.

Since the refreshrate in HZ of the GPU timting is fixed we want to synchronize the NTSC game to it (vsync) thus making the game run several 1/100 of Hz faster, and then fix the resulting audio crackling.
The way retroarch fixes the audio crackling is by changing the NTSC game audio pitch by dynamically adjusting/stretching the audio pitch to be in sync with the GPU refreshrate.
This audio stretching from 59.94HZ to 60.01Hz is roughly 0.1% change in pitch which is inaudible to us but fixes the sync issues.

So let’s begin.

Guide

First thing, make sure the monitor that you’ll be playing Retroarch is the PRIMARY monitor in windows and IN-FOCUS (mouse click it), if you are using multiple monitor setup.
Experience shows that this is the biggest factor in stuttering in retroarch.
I use a 15kHz CRT as an extended monitor with a VGA->ScartRGB cable from my PC, so I make sure it is set to be Primary BEFORE I run Retroarch.

Every monitor has a personal vertical sync timing that should be calibrated first in retroarch.
Go to the Settings -> Video menu.

Windowed Fullscreen Mode -> Off
Vertical Sync (VSync) -> On
Hard GPU Sync -> On
Vertical Refresh Rate.
Estimated Screen Framerate.

Press the “Space” or “Start” key when on “Estimated Screen Framerate” and wait till the counter reaches 2048 smaples.
Now press “Enter” or “X” (dualshock) or “A” (xbox) when still standing on “Estimated Screen Framerate” to update “Vertical Refresh Rate”.
That’s it, you calibrated the vertical sync to your monitor and you can do this procedure as often as you think you need.

This initial calibration is very important since all Audio synchronization and stretching in retroarch rely on this measured “Vertical Refresh Rate” value, so make sure you do it.

Now that we calibrated the screen refreshrate, let’s understand the Audio settings and how they affect perfect sync.
Go to Settings -> Audio, there are three not so obvious options we need to understand.

  1. Audio Sync.
  2. Dynamic Audio Rate Control.
  3. Audio Maximum Timing Skew.

The guide is intended for NTSC games on 60Hz screen, but to explain these options in a clearer way lets assume we are playing a 50Hz PAL game on a 60Hz monitor to learn what corrections retroarch does.

  • Audio Maximum Timing Skew:
    This one is first because it only takes effect when a game is loaded.
    When a game is loaded this option allows retroarch to ‘stretch’ the audio pitch of the game to your monitor refresh rate you set in “Vertical Refresh Rate” thus creating perfect audio sync but the audio will also be slightly higher in pitch as a result of stretching from 50Hz to 60Hz (in this example) which is 17% speedup.
    To allow correct 50->60 sync we need to set this slightly above 0.17 (17%), say 0.18 or 0.2.
    Everything below 20% will also sync, as this setting is the maximum allowable stretching percent.
    Note that if you set it too low (say 0.15) it will not take effect at all if the game needs 0.17 or more.
    Once again, this option takes effect only when you freshly start a game, not even a reset command will do, you have to close content for new settings to take effect.
    As you understand, this option is primary as the other audio options come after this one did its job.
    If you play mostly NTSC games on a 60Hz monitor (as you should), keep the default setting of 0.05.

  • Audio Sync:
    When ON, the game will sync to audio and play audio smoothly without crackling, but the video may stutter as the game audio runs in sync to the “Vertical Refresh Rate” which is a measured estimate of the screen real refresh rate.
    When OFF, the video will be in perfect sync (no video stuttering), the game will speed/slow to your real screen vsync, but audio may crackle if “Vertical Refresh Rate” is not close enough to the real refresh rate of the screen.
    If you properly done the “Estimated Screen Framerate” calibration, then the default ON should give you no trouble.

  • Dynamic Audio Rate Control:
    Unlike “Audio Maximum Timing Skew” which only takes effect at start, this one is constantly updating on-the-fly and fixing minor (or major) deviations in sync between audio and video.
    Basically this one will keep the audio/video experience silky smooth like a console would, but the pitch correction is of lesser quality than of “Audio Maximum Timing Skew” because it works in real time.
    Don’t assume you will ever hear these pitch corrections as they are very small and swift, but will keep you in perfect sync.
    If you want retroarch to behave like other emulators without this option, set it to 0.000.

UPDATE:

To further clarify the relationship between “Audio Sync”, “Dynamic Audio Rate Control”, “Vertical Refresh Rate” and “Hard GPU Sync”;

First, “Vertical Refresh Rate” has nothing to do with the real vsync of your monitor, it is simply an estimation by retroarch software so that “Audio Sync” has an estimate of your screen refresh rate.
So “Audio Sync” and “Audio Maximum Timing Skew” will sync to the estimated/calibrated refreshrate not the true vsync of your display.

Displays have some minor timing instabilities because of heat and other environmental factors.
The DELTA in % between “Vertical Refresh Rate” and the real hardware fluctuating Display refresh rate is what “Dynamic Audio Rate Control” fixes in real time.
Please re-read these two sentence till you clearly understand them.

I remind again to set the monitor you’ll be playing retroarch on as Primary, as I found it is the biggest factor of macro (big) stuttering. I recommend a small soft called “Monitor Profile Switcher”, it can switch monitor profiles with hotkeys, very handy.

8 Likes

Would you say that the default settings are an ‘all around’ good general setting?

I ask because my entire setup is on a portable drive that I plug into various computers wherever I go.

Also, good to know about the FF setting. I use that so much I keep trying to do the gamepad combo in modern games hahaha

Yes the defaults should suffice but make sure you do the “Estimated Screen Framerate” calibration each time you change monitors as it is a major factor for perfect sync.

Also there is this official information about getting optimal vsync performance:

I am a tweaker so it is nice to actually know what all the fancy options are doing. :blush:

1 Like

UPDATE:

EDIT: Moved to first post.

The phrasing of the post suggests this is heavily geared towards PAL games. Would love a similar guide for people whose games are all NTSC (or MAME, which I guess is a fringe case with every game having its own refresh rate).

BTW this site is useful for getting a precise v-sync refresh rate if you run Retroarch fullscreen windowed liked I do:

https://www.vsynctester.com/index.html

Tick the ‘Use rAF time arg as frame time’ box, then wait for the number to stop moving (takes a couple of minutes) for a precise refresh to six digits. Paste that into Retroarch’s cfg file.

Absolutely not, the guide is intended for NTSC games on 60Hz screen.
I intentionally used a PAL game on a 60Hz screen to clearly see and understand what every option does. If I used an NTSC game on 60Hz monitor I would never see/hear thus understand what every option does.

1 Like

@James-F this looks like a comprehensive guide. I may get this added to the documentation if thats fine with you and @hunterk or @anon24419061 feel it fits the scope of that site?

1 Like

If not good for docs maybe @James-F could copy this into the guides section of the forum before it gets burried away in threads

Feel free to link this thread or move it to another sub-forum, but copy-pasting is not a good idea because I constantly update it.

1 Like

Maybe tag me when you think its done.

I do think it would better for things like this to be in the guides section. As a whole it would be nice to see that new section build some content

Alright.
If I can edit in the guide section, you can move it there now.

Thank you so much for this guide! :smiley:

It would be great to see this become part of the documentation, either because @James-F is pushing commits to github or someone helps periodically updates a version in the docs that links to this thread for users that want the best and latest info.

I think a lot of people are looking for this information in the docs and not finding enough to get them started. Your work is a great step forward even as it is now.

Do you think one of those concepts makes sense in the paradigm for your work on this issue? I wouldn’t want to slow you down from working on the project right here in the thread regardless of any docs!

Are you sure about that? Every time I’ve heard this option discussed it’s been in the context of lowering input lag, not actually performing v-sync operations. In fact, I’ve turned it off and experienced no tearing whatsoever. So I’m pretty sure that isn’t accurate.

You are right, I’ve corrected the guide.
But for some strange reason when I tested it there was stuttering when “Hard GPU sync” was Off, and no stuttering with it On.
I cannot re-create this now, but something probably caused this issues…

The easiest way to see stuttering is to enable temporarily “Black Frame Insertion” even on 60Hz screen, this way it is much more visible when the video is not smooth or stuttering.

I updated the guide.

Removed the Audio Sync=Off nonsense, is should be On if “Estimated Screen Framerate” is properly calibrated.
I added and emphasized the importance of Retroarch being played on the PRIMARY monitor, as in my experience it is the biggest factor in macro stuttering and vsync loss.

I recently purchased few retro consoles (Genesis, Super Famicom) with their flashcarts from krikzz (Mega Everdrive X5 & SD2SNES), to have the real hardware to compare retroarch with.
The most noticeable factors are the feel of the controllers and how smooth the gameplay is.
I view smooth, stutter-free audio/video as a huge part of a good emulation experience.

Having said that, retroarch can give an excellent retro console experience and much more convenient on a CRT when properly set, so much so I choose to play Retroarch with my CRT even though the real consoles are right beneath the TV and also have quality RGB scart cables.

heh, yeah, same here. I have all of the consoles and CRTs, etc., but I usually just emulate via RetroArch for convenience.

Btw, what’s the adviced audio driver for the guide? Xaudio / DSound?

XAudio (default).


Hello all. The problem here is that, if we take the example of R-Type arcade, which has a frequency of 55hz / fps, when synchronizing at 60hz / 60fps, the game works significantly faster than in its original version so ,in my opinion, it breaks the experience. In addition to blocking the vsync of the rom and our screens, we need a speed selector (and/or automation) to adjust (to lower in this case) the speed percentage of the game. I hope you understand what I mean, and sorry for my english, its not my native language.