Build Your Own Arcade Controls Forum

Main => Software Forum => Topic started by: GaryMcT on August 04, 2009, 02:45:33 am

Title: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 04, 2009, 02:45:33 am
This isn't a slam-dunk fix.  You will still see a bit of tearing now and again, but it's a good compromise for when you are having audio sync problem with triple-buffering enabled.  I haven't made this configurable yet. . I'll do that later. 

The initial version is a patch off of 133u1 sources.  It doesn't looks like the code that I'm changing has changed much lately, so it'll likely work with other recent versions:

http://home.comcast.net/~g.mctaggart/0133u1_garymct_d3d_triple_buffer_fix.diff (http://home.comcast.net/~g.mctaggart/0133u1_garymct_d3d_triple_buffer_fix.diff)

Here's the MameDev page on how to apply patches to the source code for Mame:

http://mamedev.org/updates.html (http://mamedev.org/updates.html)

I'd be happy to get feedback on this.  I'll likely fix the problems with the pixel not lining up perfectly in D3D mode and put that here too.

I don't think this patch is appropriate for Mame proper since there will be some tearing.

Gary
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: Ginsu Victim on August 04, 2009, 09:47:39 am
Thanks for your contribution!
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: zmartin34 on August 04, 2009, 12:45:00 pm
Is this only for D3D Gary?
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 04, 2009, 12:51:14 pm
D3D-only for now. I'll see if it is possible with ddraw, but I'm more likely to take the time to make D3D pixel-accurate since I know how to do that.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 04, 2009, 02:27:14 pm
The more I think about it the more I think that this is a big hack.  I'll look at getting the sound to work properly with triple buffering without tearing.  This is a good short-term solution though.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: ahofle on August 04, 2009, 03:06:05 pm
but I'm more likely to take the time to make D3D pixel-accurate since I know how to do that.

That would be lovely.  I know there is a patch out there by 'wpcmame' for so-called clean-stretch with D3D, but it was rejected for whatever reason by mamedev.  Not sure if that patch has been kept up to date with the latest MAME releases.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 04, 2009, 03:09:51 pm
but I'm more likely to take the time to make D3D pixel-accurate since I know how to do that.

That would be lovely.  I know there is a patch out there by 'wpcmame' for so-called clean-stretch with D3D, but it was rejected for whatever reason by mamedev.  Not sure if that patch has been kept up to date with the latest MAME releases.


Are you the arcade ambiance guy?  If so, would you be interested in some quadraphonic recordings of a real arcade that I recorded down at Ground Kontrol a few weeks ago?  I don't know when I'm going to get a chance to do anything with them.

On a related note, they were playing your track out the front door to entice people in. :)
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: ahofle on August 04, 2009, 03:31:50 pm
Are you the arcade ambiance guy?  If so, would you be interested in some quadraphonic recordings of a real arcade that I recorded down at Ground Kontrol a few weeks ago?  I don't know when I'm going to get a chance to do anything with them.

Yes and yes please!  :) 
What kind of equipment did you use to record that?

Quote
On a related note, they were playing your track out the front door to entice people in. :)

Neat!
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 04, 2009, 04:36:02 pm
Are you the arcade ambiance guy?  If so, would you be interested in some quadraphonic recordings of a real arcade that I recorded down at Ground Kontrol a few weeks ago?  I don't know when I'm going to get a chance to do anything with them.

Yes and yes please!  :) 
What kind of equipment did you use to record that?

Quote
On a related note, they were playing your track out the front door to entice people in. :)

Neat!

I borrowed a friend's Zoom H2 field recorder.  I'll put the files up sometime soon for you and send you a link.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 05, 2009, 01:11:32 am
Did some more digging tonight.  It looks like the sound hitching with triple buffering is always the case that the rendering is going too fast.  I'm assuming that when you aren't vsyncing or triple-buffering, there is a manual timer in there somewhere to throttle everything. . . maybe that isn't happening with triple buffering and it should be happening.  Going to dig some more.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: Ginsu Victim on August 05, 2009, 11:05:59 am
Keep digging!  :applaud:
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: cboy on August 10, 2009, 06:41:02 pm
any luck on this?  :cheers:
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: bent98 on August 10, 2009, 06:57:22 pm
This fix should already be Incorporated in Cabmame.
You can also download .diff separately and compile your own version.


http://community.arcadeinfo.de/showthread.php?t=9555

Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 10, 2009, 07:37:38 pm
This fix should already be Incorporated in Cabmame.
You can also download .diff separately and compile your own version.


http://community.arcadeinfo.de/showthread.php?t=9555



Really?  I'm running cabmame and have this problem. 

Oh, you must be talking about the pitch-shifting stuff to fix the problem.  I don't care for the results of that.  The problem should be fixable without resorting to degrading audio quality.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 10, 2009, 07:40:51 pm
In more detail, with triple buffering, you should be able to run the frame loop at a different rate than the refresh rate of your display without having problems.  The only exception is that D3D doesn't let the hardware get more than 3 frames behind the app, which is what I think is happening with Mame.  I suspect hat early on in the app run a ton of frames are getting sent down to D3D and it is never allowed to get "caught up".  I have some more digging to see if I can fix it.  I haven't had a lot of time lately.  A similar fix or the same fix may apply to ddraw as well.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 11, 2009, 03:55:15 am
I think I might know what it is.  Haven't tested it out yet though.

Since D3D/DDraw doesn't have a triple buffer mode that throws away frames (I don't think), there needs to be something like autoframeskip, but for when the GPU is behind, not the CPU.  Pacman has been my test case, and the original runs at ~60.60 Hz and my monitor is running at 60Hz.  The game will need to skip rendering of some frames (or at least swap of those frames) so that the GPU can catch up.  If the GPU isn't allowed to catch up, the CPU will be forced to block once the app gets more than 3 frames behind.

I don't have much time to work on this now, but if someone wants to test the theory, see if all games that have sound skipping problems in triple buffer mode have an original refresh rate that is higher than the refresh rate that your monitor is running at.  You can run with -verbose on the mame command-line to see what resolution you are actually running at, and look in the tab menu under "game information" to see what the original resolution was.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: ahofle on August 12, 2009, 11:09:33 am
Wow, if you can truly fix this without any sound warping, screen tearing, or audio glitches you will be a HERO.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: zmartin34 on August 28, 2009, 07:59:20 pm
Gary any update??
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on August 28, 2009, 08:03:05 pm
Not yet. I have a plan, but finishing up the game that I'm working on at work and adding modifier key support to mame has taken higher priority.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: DeLuSioNal29 on February 09, 2010, 09:52:22 pm
Found this topic interesting, since I've just noticed that I having been running my cab with the triple buffer option on.  With it enabled I get occasional sound stutter.

Any progress on this?

D
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on February 10, 2010, 12:33:45 am
Found this topic interesting, since I've just noticed that I having been running my cab with the triple buffer option on.  With it enabled I get occasional sound stutter.

Any progress on this?

D

Sorry. I've totally flaked on this since I've stopped using Mame for arcade cabs. 
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: Encryptor on February 10, 2010, 05:38:15 am
What are you using on your cabs instead of MAME?

Encryptor
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on February 10, 2010, 02:57:03 pm
What are you using on your cabs instead of MAME?

Encryptor

I'm using a combination of the original PCBs (Defender, Omega Race, Asteroids Deluxe, Centipede), the JROK fpga mult-williams board for all the early Williams stuff, and I'm learning how to write code for fpga devices so that I can work on getting more games that I care about working (http://fpgaarcade.com (http://fpgaarcade.com) has good info on this process).  I also have Pac-Man from fpgaarcade.com working on an arcade monitor. . works great!

I'm extremely sensitive to latency, and the Windows version of Mame didn't feel responsive enough to me.  It's Window's fault, not Mame's fault from what I can tell.  It would make sense to get modern Mame working on Linux on modern hardware with all the correct refresh rates and resolutions (like Advance Mame did), but that feels too much like work for me to work on that, so I'm going to work on the longer term fpga thing.  It's going to take me a while to get to the point where I can implement a whole PCB/game though.
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: Encryptor on February 10, 2010, 06:37:41 pm
It sounds very interesting. Are you doing coding for this?

Encryptor
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: GaryMcT on February 10, 2010, 07:02:07 pm
It sounds very interesting. Are you doing coding for this?

Encryptor

I haven't submitted anything, but I'm learning how to do this.  It may take a while since I'm new with hardware (I'm a software guy.)
Title: Re: Mame patch for working around sound sync problems with triple buffering
Post by: krick on July 18, 2012, 05:03:16 pm
I was wondering if you've tried GroovyMAME to see if it works any better for you.