precisazione importante sul funzionamento di GroovyMAME
Inviato: 06/09/2011, 20:24
purtroppo è in inglese, ma se qualcuno la vuol tradurre...ben venga!
What follows is only valid for GroovyMame starting from 12o. Older versions work slightly different. Regular Mame is another story (we've somewhat modified the way -syncrefresh, -waitvsync, -triplebuffer are implemented).
Well basically we try to calculate modelines with a refresh that matches the game's original fps. But that's not always possible, due to the usual limitations of monitors that can only sync at some ranges of hfreq. So, what actually determines which frequencies we can produce is the monitor type option we select mame.ini.
If you leave the default "cga" monitor, all 240 lines resolutions will be fine, but you won't be able to set a video mode of i.e. 400x256@60, it will only reach around 400@256@57. So for a game like 1942 that runs at 60 Hz, GroovyMame by default will disable sync to vertical retrace, and you'll have tearing.
We can force to sync to vertical retrace by enabling -syncrefresh. Inmediately, the game 1942 will reduce its speed to 95% (57/60). Scroll will be perfectly smooth. As sound is processed separately, it still thinks we are running at 100%, so periodically it will have to stop to let the game catch with the sound. In order to force sound to also sync with our rendering speed, we need to enable the -soundsync option. Obviously this only can be achieved by modifying its frequency by the same factor, so there will be a clear difference in pitch. But this is the only possible and less bad thing you can do if you really want have perfect scrolls without sound stuttering when your refresh doesn't match the game's fps.
If you really can't bear with the slow down or it's too bad for a particular game, then there's still a way you can have your game run at 100% without any tearing: the -triplebuffer option. As we'll run at the original speed, we don't need any sound trick here. Of course, there is a catch: tearing is removed as triplebuffer enables page flipping, but we won't have perfect scrolls any more, as the game action will not be synchronized with our vertical refresh. Page flipping however is still synchronized to vertical retrace, that's why tearing doesn't happen.
Depending on the game -triplebuffer method will be better than the other, so for pacman it's good as there's no scrolling and -syncrefresh would affect its speed badly, but for 1942 you'll notice the scroll has some small hiccups, which you can tolerate or not. Triplebuffering (as it's currently done in Mame/GroovyMame) has an additional drawback: it will add some input lag. However, this won't be so bad if you always use -multithreading (on by default). That's why for gameplay,-triplebuffer is less desirable than -syncrefresh.
If you enable -triplebuffer, then -syncrefresh is automatically disabled, so you if you enable both of them only -triplebuffer will be used. If you are going to use -triplebuffer for some game, it's a good idea to create an ini for it so you don't use that option all the time.
You may wonder what's -waitvsync used for now. In GroovyMame, -waitvsync is used internally by the program, so any value that you set to this option will be overriden. So, if you leave the options by default, -waitvsync will be enabled/disabled internally to perform synchronization when required. By enabling -syncrefresh, what you do is to tell GroovyMame to always force -waitvsync, whatever the refresh is. (Notice that in regular Mame, -syncrefresh/-waitvsync are exactly the same option, they do the same, as the mainstream code is implemented).
Now, back to the monitor type option, if you are positive your monitor accepts a wider range of frequencies than the default "cga" template, you can either choose some of the predefined monitors or create your custom settings that fit your particular monitor. There is a potencial risk to damage your monitor when messing with this stuff, it's never bad to remind this.
So, what I do is to choose my model: h9110. With this monitor, I have a way wider range than using the cga one, so I'll be able to generate i.e. 400x256@60Hz modeline, and thus run 1942 at 100% without forcing things. As you see, usually the monitor option is what most directly affects final game speed (if we want to sync to vertical retrace), and most issues with stuttering sound are produced by trying to sync to wrong refresh rates rather than needing more cpu power.
Finally, there some games that really are too much for our cpu: most 3D games for instance. The problem here is that usually, the right refresh is achieved, so GroovyMame will automatically enable -waitvsync. By doing this, our fps can be dramatically cut off by 50%, because most of our cpu time is wasted just waiting for vertical retrace. Again, the -triplebuffer option comes in handy here, as it will revert the -waitvsync mechanism and let the game engine run freely while our frames are flipped independently at the refresh speed. As GroovyMame has no way to guess if your cpu is going to be enough for a given game, -triplebuffer here needs to be added manually by you when required.
What follows is only valid for GroovyMame starting from 12o. Older versions work slightly different. Regular Mame is another story (we've somewhat modified the way -syncrefresh, -waitvsync, -triplebuffer are implemented).
Well basically we try to calculate modelines with a refresh that matches the game's original fps. But that's not always possible, due to the usual limitations of monitors that can only sync at some ranges of hfreq. So, what actually determines which frequencies we can produce is the monitor type option we select mame.ini.
If you leave the default "cga" monitor, all 240 lines resolutions will be fine, but you won't be able to set a video mode of i.e. 400x256@60, it will only reach around 400@256@57. So for a game like 1942 that runs at 60 Hz, GroovyMame by default will disable sync to vertical retrace, and you'll have tearing.
We can force to sync to vertical retrace by enabling -syncrefresh. Inmediately, the game 1942 will reduce its speed to 95% (57/60). Scroll will be perfectly smooth. As sound is processed separately, it still thinks we are running at 100%, so periodically it will have to stop to let the game catch with the sound. In order to force sound to also sync with our rendering speed, we need to enable the -soundsync option. Obviously this only can be achieved by modifying its frequency by the same factor, so there will be a clear difference in pitch. But this is the only possible and less bad thing you can do if you really want have perfect scrolls without sound stuttering when your refresh doesn't match the game's fps.
If you really can't bear with the slow down or it's too bad for a particular game, then there's still a way you can have your game run at 100% without any tearing: the -triplebuffer option. As we'll run at the original speed, we don't need any sound trick here. Of course, there is a catch: tearing is removed as triplebuffer enables page flipping, but we won't have perfect scrolls any more, as the game action will not be synchronized with our vertical refresh. Page flipping however is still synchronized to vertical retrace, that's why tearing doesn't happen.
Depending on the game -triplebuffer method will be better than the other, so for pacman it's good as there's no scrolling and -syncrefresh would affect its speed badly, but for 1942 you'll notice the scroll has some small hiccups, which you can tolerate or not. Triplebuffering (as it's currently done in Mame/GroovyMame) has an additional drawback: it will add some input lag. However, this won't be so bad if you always use -multithreading (on by default). That's why for gameplay,-triplebuffer is less desirable than -syncrefresh.
If you enable -triplebuffer, then -syncrefresh is automatically disabled, so you if you enable both of them only -triplebuffer will be used. If you are going to use -triplebuffer for some game, it's a good idea to create an ini for it so you don't use that option all the time.
You may wonder what's -waitvsync used for now. In GroovyMame, -waitvsync is used internally by the program, so any value that you set to this option will be overriden. So, if you leave the options by default, -waitvsync will be enabled/disabled internally to perform synchronization when required. By enabling -syncrefresh, what you do is to tell GroovyMame to always force -waitvsync, whatever the refresh is. (Notice that in regular Mame, -syncrefresh/-waitvsync are exactly the same option, they do the same, as the mainstream code is implemented).
Now, back to the monitor type option, if you are positive your monitor accepts a wider range of frequencies than the default "cga" template, you can either choose some of the predefined monitors or create your custom settings that fit your particular monitor. There is a potencial risk to damage your monitor when messing with this stuff, it's never bad to remind this.
So, what I do is to choose my model: h9110. With this monitor, I have a way wider range than using the cga one, so I'll be able to generate i.e. 400x256@60Hz modeline, and thus run 1942 at 100% without forcing things. As you see, usually the monitor option is what most directly affects final game speed (if we want to sync to vertical retrace), and most issues with stuttering sound are produced by trying to sync to wrong refresh rates rather than needing more cpu power.
Finally, there some games that really are too much for our cpu: most 3D games for instance. The problem here is that usually, the right refresh is achieved, so GroovyMame will automatically enable -waitvsync. By doing this, our fps can be dramatically cut off by 50%, because most of our cpu time is wasted just waiting for vertical retrace. Again, the -triplebuffer option comes in handy here, as it will revert the -waitvsync mechanism and let the game engine run freely while our frames are flipped independently at the refresh speed. As GroovyMame has no way to guess if your cpu is going to be enough for a given game, -triplebuffer here needs to be added manually by you when required.