osu-framework
osu-framework copied to clipboard
Add ASIO/WASAPI drivers to Reduce Audio Latency
Opening an issue for discussion since this is something that should be included in the official distribution.
osu! uses default BASS procedures, which use DirectSound on Windows, causing large latencies due to high latency software mixing in Windows Vista and Windows 7 (as I've tested). I get 70ms latency on average using 240FPS on both my Windows 7 64-bit PC and Windows Vista 32-bit laptop. This may be less of a problem on Linux since BASS defaults to the ALSA driver, which is a low-level & low-latency driver, but I have not tested it fully.
The BASS API has extensions for ASIO and WASAPI support under the same licenses. We can effectively (hopefully) reduce the latency to less than 4ms on ASIO, and a worse case on WASAPI (Exclusive).
BASS does not unify their main API with ASIO and WASAPI APIs for some reason, so some changes and additions to audio code will be needed. These APIs are very easy to work with, and pretty much the same as using their main API once you've got them initialised. We have to set up a BASS MIXER and load sounds and music as BASS STREAMS, instead of SAMPLES. The STREAMS are connected to the MIXER and the MIXER feeds audio data to the ASIO/WASAPI event procedures. BASS CHANNEL procedures can be used with streams just like samples.
We will also need to add options for sound drivers in the options menu. It will simply list available drivers depending on your platform. A simple drop-down box can be created after detecting available drivers. Options could be "Default", "ASIO", "WASAPI (Shared)", and "WASAPI (Exclusive)". A note should be added to WASAPI (Exclusive) and ASIO since they take exclusive access of an audio device, so only osu! can be playing sound from that device.
Linux does not use ASIO, so this will not affect Linux. WASAPI is Windows-exclusive, but does not achieve lower latencies compared to ASIO.
This will also add some dynamic-link dependencies and the use of add-ons from ManagedBass. BASSMIX, BASSASIO, and BASSWASAPI will be used.
I can work on the code for ASIO & WASAPI support, but some minor design changes may be required.
The latency you describe is not inherent to windows audio mixing. I've had many sound cards, and for most of them there was no perceptible delay, even through DirectSound and an active audio mixer. Therefore, the fault can't lie with windows' audio pipeline. Seems to me like the fault lies with the hardware / driver and not DirectSound.
Of course, if you have a sound card where ASIO / WASAPI actually makes a difference (on all the ones I had, if there was a delay, then it persisted with ASIO / WASAPI; believe me, I tried hard to get rid of it, as I also find it annoying), then feel free to implement it. Design changes can be discussed as they come up.
I felt my conclusion is fact because I've worked on and compared low latency code myself and there was significant improvement when using ASIO or WASAPI. I conducted my tests by recording with a microphone and a click input and measured the space between both sounds. Sure enough there was 2ms latency using ASIO and a large 70ms when using DirectSound. The delay is easily noticeable if you're one who makes taps after hearing the instrument and getting that feedback.
I'm not claiming your setup doesn't exhibit delay. As I said, feel free to implement ASIO / WASAPI. I'm just saying, that it's most likely a specific problem with your setup (I had similar issues with my old Xonar Essence STX and a bunch of onboard sound cards), and not that of the windows audio mixer. I've got multiple working setups that prove that the latency with DirectSound and the audio mixer turned on can be (and should be) close to none.
Hi, I'm a chronic sufferer from audio latency. While it was possible for me to fix my setup, it was EXTREMELY difficult to do so, having to try out many different drivers and rebooting many times, and sometimes the driver only works under specific circumstances (if I unplug my external monitor and use the laptop monitor, it suddenly stops working!) and sometimes the driver will decide to uninstall itself (I don't have automatic updates enabled, I don't know what's uninstalling it...)
If ASIO / WASAPI is going to remove all this pain, it doesn't actually matter if it's possible to fix my setup or not, because it would actually fix my setup, and save a decent number of players some grief.
@posesix It'd be great if you could submit a PR for this, else I don't think much can be done ^^;
+1 To this. I've been through 6 months of reinstalls, multiple sound cards, custom drivers, and more. My headphones are connected directly to the sound card so there's definitely no hardware problem. Basically, I've dragged myself through hell to play without latency and am still stuck where I was before. Prior to this I had some drivers which I somehow broke the APO on which had no latency. Obviously I haven't been able to replicate this. My hardware supports ASIO. Please please please add support.
In many cases ASIO is not implemented perfectly and can introduce issues (I've experienced this personally in the past). It should not be considered a solves-all solution but instead a fallback for users with problems.
Also please note we do not need +1 comments. We have no issue with ASIO support being added (although do note it is an extra BASS product with a separate license requirement) so feel free to PR support for this.
Audio system is switched to bassmix now, can we raise the priority of this issue?
You are welcome to give implementing this a shot at any point, if that's what you're asking!