Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Mame patch for working around sound sync problems with triple buffering  (Read 10532 times)

0 Members and 1 Guest are viewing this topic.

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
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

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

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
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


Ginsu Victim

  • Yeah, owning a MAME cab only leads to owning real ones. MAME just isn't good enough. It's a gateway drug.
  • Trade Count: (+10)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10092
  • Last login:June 28, 2025, 10:45:55 pm
  • Comanche, OK -- USA
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #1 on: August 04, 2009, 09:47:39 am »
Thanks for your contribution!

zmartin34

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 120
  • Last login:December 26, 2011, 09:22:42 pm
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #2 on: August 04, 2009, 12:45:00 pm »
Is this only for D3D Gary?

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #3 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #4 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


ahofle

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 4544
  • Last login:August 30, 2023, 05:10:22 pm
    • Arcade Ambience Project
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #5 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.

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #6 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. :)
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


ahofle

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 4544
  • Last login:August 30, 2023, 05:10:22 pm
    • Arcade Ambience Project
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #7 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!

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #8 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #9 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


Ginsu Victim

  • Yeah, owning a MAME cab only leads to owning real ones. MAME just isn't good enough. It's a gateway drug.
  • Trade Count: (+10)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10092
  • Last login:June 28, 2025, 10:45:55 pm
  • Comanche, OK -- USA
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #10 on: August 05, 2009, 11:05:59 am »
Keep digging!  :applaud:

cboy

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 120
  • Last login:October 07, 2012, 02:09:29 am
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #11 on: August 10, 2009, 06:41:02 pm »
any luck on this?  :cheers:

bent98

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 477
  • Last login:February 02, 2019, 03:35:00 pm
  • Hyperspin Moderator
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #12 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


GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #13 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #14 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #15 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


ahofle

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 4544
  • Last login:August 30, 2023, 05:10:22 pm
    • Arcade Ambience Project
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #16 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.

zmartin34

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 120
  • Last login:December 26, 2011, 09:22:42 pm
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #17 on: August 28, 2009, 07:59:20 pm »
Gary any update??

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #18 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


DeLuSioNal29

  • Global Moderator
  • Trade Count: (+6)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 4779
  • Last login:July 11, 2025, 09:17:44 am
  • Build the impossible -"There is no Spoon"
    • DeLuSioNaL's YouTube Videos
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #19 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
Stop by my Youtube channel and leave a comment:

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #20 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. 
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


Encryptor

  • Trade Count: (+34)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1287
  • Last login:December 21, 2023, 08:01:18 pm
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #21 on: February 10, 2010, 05:38:15 am »
What are you using on your cabs instead of MAME?

Encryptor

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #22 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 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.
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


Encryptor

  • Trade Count: (+34)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1287
  • Last login:December 21, 2023, 08:01:18 pm
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #23 on: February 10, 2010, 06:37:41 pm »
It sounds very interesting. Are you doing coding for this?

Encryptor

GaryMcT

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 745
  • Last login:September 24, 2014, 11:19:27 am
    • GaryMcT's arcade blog
Re: Mame patch for working around sound sync problems with triple buffering
« Reply #24 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.)
My blog on learning how to develop FPGA versions of arcade boards: http://garymct.blogspot.com


krick

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2006
  • Last login:May 23, 2025, 03:48:36 am
  • Gotta have blue hair.
I was wondering if you've tried GroovyMAME to see if it works any better for you.
Hantarex Polo 15KHz
Sapphire Radeon HD 7750 2GB (GCN)
GroovyMAME 0.197.017h_d3d9ex
CRT Emudriver & CRT Tools 2.0 beta 13 (Crimson 16.2.1 for GCN cards)
Windows 7 Home Premium 64-bit
Intel Core i7-4790K @ 4.8GHz
ASUS Z87M-PLUS Motherboard