First off, thank you again Calamity for all your awesome work on GroovyMAME/CRT Emudriver. After years of fiddling with Linux, I'm never, ever going back.

After a bit of clean-up, here's the preliminary GM+BASSASIO patch, with a great big wall of text over it. Keep in mind that the patch is EXPERIMENTAL and UNFINISHED. It has also only been tested on two computers (they were both using Windows 7 and the kX driver, more on that below). With that said, it can sound really good if run under the right circumstances (fast computer, sober QPC and the right -asio_cal_freq, more about that in the next section and in _Usage).
_Introduction
I've decided to release the patch without any buffer management tricks in the implementation (like for instance forcibly try to keep a specified number of samples in the buffer for underrun mitigation). This will clutter the code less, and make it easier to understand if others want to mess around with it. The downside is that underruns can be more frequent. Overruns should be very infrequent, if the game speed is consistent, the QPC is sober, and -asio_cal_freq (see _Usage) is set correctly, -audio_latency is set to 5 (more info in _Usage), and nothing besides GM is running (with -nosleep and -priority 1).
_Steps to getting things running
* Acquire an ASIO-capable card and install its ASIO driver, or install ASIO4ALL and try that
* Build (see _Building)
* Use batool (GM root dir\batool) to get an estimate of the callback frequency (more info in _Usage)
- IMPORTANT ISSUES WITH BATOOL/QPC: I have noticed that the calibrated value WILL differ if the QPC frequency changes. On my i3-4130, the QPC frequency is set on boot, and changes on almost every boot (even with SpeedStep disabled). I currently work around this by using the platform clock (bcdedit /set useplatformclock yes), see the thread Calamity linked earlier for more info on this. For a really good measurement, you should probably leave batool running for an hour or two, so make absolutely sure you're getting a consistent QPC frequency in order to not have to redo the measurement. I'd recommend something like 20 mins/pass, 9 passes. This long measurement time will need to be fixed eventually, since it's pretty ridiculous.
* Run and specify the callback frequency with -asio_cal_freq
* If you want to know what's really going on, use -asio_log and read the _Usage section carefully
_ASIO4ALL info
As of rev2, ASIO4ALL support has been fixed. Depending on the sound card used, excellent results can be achieved. My Realtek ALC887 seems to be able to provide a latency of about 100, and my Realtek ALC889 seems to provide a latency of 78! The device to be used and latency is configured by using the ASIO4ALL tray icon (make sure to install with 'Use offline settings' checked) that appears when running GM, so run it with -window, and configure everything. I'll post better instructions later on.
_kX info
The cheapest way to get an ASIO capable card (if ASIO4ALL does not work satisfactorily) is to use an old Sound Blaster Live!/Audigy etc with the kX project driver, available at
http://www.kxproject.com . This is what has been used during development (Audigy 2 ZS and Live!). I highly recommend driver version 3551, found at
http://www.hardwareheaven.com/community/threads/3551-alpha-released.206609/ . If ASIO won't work after installing the driver, follow the guidelines in this post:
http://www.hardwareheaven.com/community/threads/no-asio-driver-under-windows-7-32bit.218926/#post-1470886 . Simply doing the regsvr32-trick solved it for me. If using 64-bit, make sure to register both C:\Program Files (x86)\kX Project\kxasio.dll and C:\Program Files\kX Project\kxasio.dll to enable both the 32- and 64-bit driver.
Also, you hopefully won't need to use a buffer size of anything other than 64. Specify ASIO buffer size with the -asio_latency setting, when everything's up and running. If you'd like to access the ASIO control panel (to configure the kX driver latency), and the kX tray icon won't let you, you can use batool (info below) with the --cp switch to access it.
If no sound is being output but everything else seems to work, try another jack on the sound card.
I've tested the official Sound Blaster ASIO driver, which seems to work (Audigy 2 ZS, Windows 7). The kX driver delivers far superior results though.
ASIO4ALL does not work._Building
With MinGW, only 32-bit builds are supported. So make sure you're using the 32-bit MinGW toolchain.
Only the mingw-mame-20121207.exe package has been tested. mingw-mame-20140905.exe works and should be used.
Before building, apply all GroovyMAME (0.154/0.155) patches, then apply asio_rev*.patch.
Download BASSASIO from here
http://www.un4seen.com/download.php?bassasio13 . Create a directory in the GM root directory (same as makefile) called 'bassasio' and extract the contents of the archive into this directory.
Now you should be able to compile as normal. I build with the following options:
-j5 TARGETOS=win32 TARGET=mame OSD=windows ARCHOPTS=-march=pentiumpro NOWERROR=1
As of rev2, 64-bit builds are supported with the MSVC compiler (VS2013), however, I had to make three hackish changes to GM. Make sure you have a working MSVC setup and use the following switches to build.
MSVC_BUILD=1 NOWERROR=1 DIRECTINPUT=8 PTR64=1
_Usage
To get good results you need a fairly fast computer (I'm using an i3-4130, testing has also been done on a i5-2500K), also make sure you have next to nothing running in the background. So, disable unnecessary services etc, this is especially important if using -asio_log (more info below).
The frequency of the BASSASIO callback must be measured for proper operation. Use batool to do this (root dir\batool), and the GM command line switch -asio_cal_freq to specify the value. My Audigy 2 ZS apparently runs at about 47998 Hz and my Live! at about
47999.4 Hz 47998.65 (with platform clock enabled). If not compensated for, this will cause the audio to drift. The QPC clock can (amongst other things) affect the measurement, this will need to be investigated further.
Only DirectDraw has been tested. Using the -v option gives useful debug information. The options used during testing are the ones below.
mame -v -waitvsync -syncrefresh -nosleep -priority 1 -monitor generic_15 -video ddraw -asio_latency 64 -asio_log -audio_latency 5 -asio_cal_freq <calibrated value>
The -audio_latency parameter does not work the same way as with DirectSound, it merely sets the size of the intermediary buffer. If lots of underruns are shown in the log, try setting -audio_latency 5 and -asio_holdoff 1152.
If run with -asio_log, a log will be output to 'asio.log'. The easiest way to use this log is probably with Octave (or better, MATLAB, if you have it). Octave can be downloaded from
http://mxeoctave.osuv.de . After installing, start up the command line version and paste
data = csvread('<path to asio.log>'); subplot(3, 1, 1), plot(data(:,8), data(:,1)), subplot(3, 1, 2), plot(data(:,8), data(:,3) - data(:,4)), subplot(3, 1, 3), plot(data(:,8), data(:,2));
to plot recorded speed against audio update count (top), incoming minus outgoing samples at each audio update (middle), and the internal buffer count (of channel 0) against audio update count (bottom). This is an almost invaluable tool when debugging. Also, it's possible that the first time plotting, Octave will be a bit slow. Subsequent plots should be faster. All of this fiddlery should eventually be replaced with an under-/overrun counter message in the GM log.
_Problems
Currently, the game needs to be running at a very consistent speed.
Sometimes, the left and right channels fall out of sync. This creates interesting effects.
The in-game volume control doesn't work.
No sound for the first three seconds.
-audio_latency won't affect the latency the same way as the DirectSound implementation.
Fastforward and pause won't work.
Actual latency may vary.
QPC variations can cause problems. Not sure what to do about this at present.
There are possible bugs in the intermediary buffer implementation.
Lots of other stuff I've forgotten to mention/don't know about.
With all this said, I will do the best I can to help out with any issues that arise.
rev0: Initial release
rev1: minor fix for the log/debug info, diff is made against 0.155!
rev2: 64-bit support with MSVC, fixes to batool, channel desync should be a lot less frequent, preliminary ASIO4ALL support
rev3: (very) preliminary buffer management stuff. DirectSound with soundsync can be used with -sound dsound
pa0: corresponds to pre-alpha 0