Skip to content

Instantly share code, notes, and snippets.

@tdrjnr
Forked from Francesco149/osu_on_linux_overhaul.md
Created February 4, 2018 02:54
Show Gist options
  • Select an option

  • Save tdrjnr/ea155222174fe20731f9595e7d6aa8ae to your computer and use it in GitHub Desktop.

Select an option

Save tdrjnr/ea155222174fe20731f9595e7d6aa8ae to your computer and use it in GitHub Desktop.
Ultimate guide to low-latency osu on linux

I've decided to rewrite this to make it as simple as possible.

This guide was made and tested in a linux mint sarah live-cd and should be compatible with ubuntu xenial. I personally use gentoo and deviate quite a bit from this guide in my setup, but this is what I would do if I used mint or ubuntu.

Example video of the final results: https://www.youtube.com/watch?v=zkqzQoeOGfU

With touchscreen: https://www.youtube.com/watch?v=GcIrlorWmaQ

The guide covers:

  • Various tips about video drivers
  • Setting up high refresh-rate gaming monitors and lightboost.
  • Installing the best wine version for osu and configuring it for low latency sound.
  • Installing osu and setting up shortcuts to run it.
  • Disabling mouse acceleration and changing mouse polling rate.
  • Configuring Huion and Wacom tablets and changing the area.
  • Configuring touchscreens.
  • Installing obs-studio for gameplay recording and streaming.

Each step is verbosely commented so you understand what it does and why we do it.

My hardware is:

  • CPU: Intel i7-4790k
  • RAM: 16gb
  • GPU: ATI r9 270x

And I get around 3000fps (0.33ms) with this setup and much less micro stuttering than I used to get on windows (most likely because open-source radeon drivers are better).

I have ~25ms local offset, which is around the minimum latency my sound card can achieve on pulse, but other linux players such as ThePooN have achieved lower latencies. The 25ms doesn't bother me at all, in fact the sound doesn't even sound delayed, I just have +25 offset on every map and my accuracy is at its peak.

NOTE: if you are on ubuntu you might need to do "sudo apt-get install" instead of "apt install", or just create your own apt alias for "sudo apt-get".

Video drivers

If you have a AMD graphics card, mint should come with the open-source drivers preinstalled. DO NOT INSTALL FGLRX / PROPRIETARY DRIVERS. They are outdated slow and buggy. On ubuntu you can check from additional drivers that the open-source radeon driver is indeed installed.

If you have a NVIDIA graphics card, you will definitely want to install the proprietary nvidia drivers which outperform the open-source ones by a lot, so do so from "Driver Manager" (or "Additional Drivers" on ubuntu). I don't have a nvidia card so I can't personally test this, but if your graphics card is supported you can also try the latest beta drivers as explained in this video that I found on google: https://www.youtube.com/watch?v=tjG3j4iyXd4 .

For integrated graphics, mint should come with the drivers and ubuntu should have them under "additional drivers".

Once you have your drivers set up, make sure that it's actually working by checking for hardware acceleration.

Open a shell and run:

glxinfo | grep render

You should get something like (the important part being the first line):

direct rendering: Yes
    GLX_MESA_multithread_makecurrent, GLX_MESA_query_renderer, 
    GLX_MESA_multithread_makecurrent, GLX_MESA_query_renderer, 
Extended renderer info (GLX_MESA_query_renderer):
OpenGL renderer string: Gallium 0.4 on AMD PITCAIRN (DRM 2.43.0, LLVM 3.8.0)
    GL_ARB_conditional_render_inverted, GL_ARB_conservative_depth, 
    GL_NV_conditional_render, GL_NV_depth_clamp, GL_NV_packed_depth_stencil, 
    GL_ARB_conditional_render_inverted, GL_ARB_conservative_depth, 
    GL_NV_blend_square, GL_NV_conditional_render, GL_NV_depth_clamp, 
    GL_OES_element_index_uint, GL_OES_fbo_render_mipmap, 

Another thing you can use to test is

vblank_mode=0 glxgears

Which after a couple seconds should be outputting pretty high fps values (over 14'000 for me).

Refresh rate

If you have a 144hz monitor or any monitor that isn't 60Hz you will want to take advantage of that.

Open a terminal an run the following:

nano ~/.config/monitors.xml

Then identify the monitor on which you want to change the refreshrate (in my case DVI-1) and change the number in

<rate>60</rate>

to your desired refresh rate, then press CTRL+O to save, press enter to confirm and press CTRL+X to exit.

This will take effect after a reboot. You can also immediately change the refresh rate using this command (replace 1920x1080 with your resolution, 144 with your refresh rate and DVI-1 with your monitor's name from the xml file)

xrandr --output DVI-1 --mode 1920x1080 --rate 144

Lightboost for VG248QE

My vg248qe monitor support lightboost, which greatly reduces the amount of motion blur and pixel ghosting for fast moving objects. You can enable it with the following commands (only tested on the vg248qe, other monitors might have different modelines):

xrandr --newmode "1920x1080_120lb" 286.7 1920 1968 2000 2080 1080 1083 1088 1149 +HSync -VSync
xrandr --addmode DVI-1 1920x1080_120lb
xrandr --output DVI-1 --mode 1920x1080_120lb

where DVI-1 is your monitor's name (see "Refresh rate" above to get your monitor 's name).

Installing osu! and tweaking sound latency

First of all we're going to install PlayOnLinux. Why? Because wine versions newer than 1.9.10 have a pretty bad sound latency regression of about 20-25ms (discovered and tested by me and ThePooN) so we want exactly wine 1.8.3.

PlayOnLinux provides binaries for many old wine versions that are guaranteed to never get updated, unlike packages in your distro's repos.

I've tracked down the code responsible for the latency regression and made a bug report so it will hopefully get fixed in future wine versions.

A much better option would be to compile wine 1.8.3 from source, however it seems that ubuntu-based distributions make it really complicated to compile the 32-bit version of wine because they do not ship all required 32-bit libraries.

On gentoo it's much easier to get 1.8.3 as you just have to only unmask the desired version of the package and you have a nice system-wide wine 1.8.3 install without having to use the POL gui at all.

Open a terminal and type:

apt install playonlinux

Fix a paranoid kernel security thingy that will prevent dotnet45 from installing:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
echo "kernel.yama.ptrace_scope = 0" | sudo tee /etc/sysctl.d/10-ptrace.conf

Install winetricks, which we will use to install .NET and other utilities.

wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
chmod +x winetricks 
sudo mv -v winetricks /usr/local/bin

Open PlayOnLinux and click Tools -> Manage Wine Versions.

In the "Wine versions (x86)" tab, select 1.8.3 and click the ">" button.

Just click next until the install is done.

Go back to the main window and click Configure

Click "New".

Next -> 32 bits -> Next -> 1.8.3 -> Next -> name it osu -> Next until it's done.

Select "osu" in the list.

We will now set some registry keys that adjust the dsound buffer size to remove as much sound latency as possible.

Wine -> Registry Editor.

Navigate to HKEY_CURRENT_USER\Software\Wine

Right click the Wine key -> new -> Key and name it "DirectSound".

Select DirectSound in the left panel and right click on the right panel -> new -> String Value and name it "SndQueueMax".

Doubleclick SndQueueMax to edit the value and set it to 3.

Select DirectSound in the left panel and right click on the right panel -> new -> String Value and name it "HelBuflen".

Doubleclick HelBuflen to edit the value and set it to 512.

There's another tweak you can do which involves recompiling the winepulse.drv with smaller period values, however from my experience it didn't help on my soundcard and wasn't worth the effort.

You can also use pure alsa, but I personally think modern pulse latency is low enough. And besides, running pure alsa will break OBS recording & streaming, and a lot more software that depends on pulse. Using the dmixer trick from the old guide to use pulse and alsa at the same time didn't show any latency improvement either over pulse.

In the PlayOnLinux configuration window, click Miscellaneous -> Open a shell.

In the newly opened shell, set environment variables for winetricks and install .NET 4.5 and cjk fonts support:

POL_Wine_AutoSetVersionEnv
winetricks -q dotnet45 cjkfonts

Let's finally install osu (from the PlayOnLinux shell):

mkdir -v osu
cd osu
wget http://m1.ppy.sh/r/osu\!install.exe
POL_Wine osu\!install.exe

Ignore the crash message and click next.

For some weird reason, POL makes osu install in the directory from which you run the installer, that's why we create that directory. This way osu! should install to C:\osu.

Once the installation is done, osu! should start. Go into options and make sure the framerate limiter is set to unlimited and enable your fps counter.

Also, make sure the release stream is "Stable (latest)" or cuttigedge if you wish. Just make sure it's not on fallback.

You can now close the PlayOnLinux shell.

Creating a shortcut and disabling vsync

In the PlayOnLinux configuration window, click General -> Make a new shortcut from this virtual drive.

Select osu!.exe and click next twice then cancel.

You should now have a osu! shortcut on your desktop. Let's tweak it.

Open a terminal and type:

nano ~/.PlayOnLinux/shortcuts/osu\!

Then add this line, which will ensure that vsync is disabled

export vblank_mode=0

before the last two lines, then press ctrl + O (saves the file), enter to confirm and ctrl + X (exit).

Your shortcut's code should now look something like this:

#!/usr/bin/env playonlinux-bash
[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"
export WINEPREFIX="/home/mint/.PlayOnLinux//wineprefix/osu"
export WINEDEBUG="-all"
export vblank_mode=0
cd "/home/mint/.PlayOnLinux//wineprefix/osu/drive_c/./osu"
POL_Wine 'osu!.exe' "$@"

Start the game, start a song and check the fps counter to make sure it's not vsynced. The ms value should be below 1000 / your monitor's refresh rate, which would be 16.6 ms for 60Hz and 8.4 for 120Hz. It should also be hopefully lower than 4ms unless you have really bad hardware. For me it's 0.33ms with the interface disabled (shift + tab).

The first start might give you a POL crash message, but it should be gone afterwards.

If the game's framerate is still limited and you are on a radeon GPU, you can try the following which disables vsync on some old radeon GPUs:

sudo mkdir -v /etc/X11/xorg.conf.d
cat > tmp.conf << "EOF"
Section "Device"
   Identifier   "Radeon"
   Driver      "radeon"
   Option      "SwapbuffersWait"   "off"
EndSection
EOF
sudo mv tmp.conf /etc/X11/xorg.conf.d/10-radeon.conf

and reboot.

If you are on nvidia, check the proprietary driver's control panel and make sure there is no vsync anywhere enabled.

If it's still limited, doublecheck your in-game frame limiter from the options.

Additional tweaks

I like to have quick access to my osu folder, so I make a symlink to it in my home folder like so:

ln -s ~/.PlayOnLinux/wineprefix/osu/drive_c/osu ~/osufolder

I don't have desktop shortcuts and I start programs by typing their name either in the terminal or in dmenu, so I prefer making a script that runs osu and put that in /usr/bin:

cat > ~/osu.sh << "EOF"
#!/bin/sh
/usr/share/playonlinux/playonlinux --run "osu!" %F
EOF
sudo mv ~/osu.sh /usr/bin/osu
sudo chmod +x /usr/bin/osu

And now I can run osu by just typing osu.

Mouse players: polling rate and mouse acceleration

You can disable mouse acceleration by running

xset m 0 0

To check that acceleration is disabled, you can run:

xset q | grep -A 1 Pointer

which will output

Pointer Control:
  acceleration:  0/1    threshold:  0

To disable mouse acceleration on boot, open "Startup Applications", click Add -> custom command and set it up like so:

If you want to, you can adjust the mouse polling rate like so:

echo "options usbhid mousepoll=1" | sudo tee /etc/modprobe.d/usbhid.conf

Where 1 is the interval in milliseconds, meaning that 1 is 1000Hz, 2 is 500Hz and so on.

You must either reboot or "sudo rmmod usbhid && sudo modprobe usbhid" to apply changes, and if the command fails you will have no keyboard or mouse control until you reboot.

I don't recommend changing this unless you feel a clear latency or choppyness in your mouse movements, as it can increase cpu usage in xorg and firefox.

Huion H420 / osu!tablet area and monitor mapping

The mint and ubuntu kernels should support this tablet out of the box, no additional drivers required.

If you have multiple monitors and the tablet is mapped to the wrong one, you can re-map it, otherwise just skip to xinput_calibrator.

List your monitors using xrandr:

xrandr

for me it shows two monitors named DVI-0 and DVI-1:

Screen 0: minimum 320 x 200, current 3286 x 1080, maximum 16384 x 16384
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 disconnected (normal left inverted right x axis y axis)
DVI-0 connected 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
   1366x768      59.79*+
   1280x720      60.00  
   1024x768      75.08    70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   640x480       75.00    72.81    66.67    60.00  
   720x400       70.08  
DVI-1 connected primary 1920x1080+1366+0 (normal left inverted right x axis y axis) 531mm x 299mm
   1920x1080     60.00 + 144.00*  119.98    99.93    84.90    59.94  
   1680x1050     59.88  
   1280x1024     75.02    60.02  
   1440x900      59.90  
   1280x960      60.00  
   1280x800      59.91  
   1152x864      75.00  
   1280x720      60.00    59.94  
   1024x768      75.08    70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   640x480       75.00    66.67    60.00    59.94  
   720x400       70.08  
DisplayPort-1-1 disconnected
HDMI-1-1 disconnected
DVI-1-1 disconnected
DVI-1-2 disconnected

In my case, DVI-1 is my main 144Hz monitor.

Run xinput in a terminal to see the list of your input devices, mine is:

⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ ELAN Touchscreen                        	id=10	[slave  pointer  (2)]
⎜   ↳ HUION 420 Pen                           	id=11	[slave  pointer  (2)]
⎜   ↳ HUION 420 Mouse                         	id=12	[slave  pointer  (2)]
⎜   ↳ HUION 420 Consumer Control              	id=14	[slave  pointer  (2)]
⎜   ↳ SteelSeries Kana Gaming Mouse           	id=16	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Power Button                            	id=7	[slave  keyboard (3)]
    ↳ Sleep Button                            	id=8	[slave  keyboard (3)]
    ↳ USB Sound Device                        	id=9	[slave  keyboard (3)]
    ↳ HUION 420 Keyboard                      	id=13	[slave  keyboard (3)]
    ↳ HUION 420 System Control                	id=15	[slave  keyboard (3)]
    ↳ DATACOMP SteelS쀁̄Љ̒DATA            	id=17	[slave  keyboard (3)]
    ↳ DATACOMP SteelS쀁̄Љ̒DATA            	id=18	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=19	[slave  keyboard (3)]

In my case, "HUION 420 Pen" is my device name.

You can now map your tablet to your desired monitor like so (remember to use your own device name and monitor name):

xinput map-to-output "HUION 420 Pen" DVI-1

You can set this command to run at startup as explained in mouse acceleration.

If you wish to change your tablet's area (I don't), install xinput_calibrator:

apt install xinput-calibrator

Now list your devices to find out your tablet's id and name:

xinput_calibrator --list

This is what it outputs for me:

Device "ELAN Touchscreen" id=10
Device "HUION 420 Pen" id=11

Sometimes there will be two huion devices for 1 tablet, just pick the first one.

You can now run xinput_calibrator with your tablet's name (id also works). Don't do anything, just let it run to get the default area values in case you lose them.

xinput_calibrator --device "HUION 420 Pen"
Calibrating EVDEV driver for "HUION 420 Pen" id=11
	current calibration values (from XInput): min_x=0, max_x=8340 and min_y=0, max_y=4680

In my case, the default area is 0 8340 0 4680.

You can now set the area values using your device's name (replace the values with your desired values, see below on how to calculate them):

xinput set-prop "HUION 420 Pen" "Evdev Axis Calibration" 0 8340 0 4680

You can set this command to run at startup as explained in mouse acceleration.

Touchscreen

Same configuration as huion tablets. My Asus VT168N is supported out of the box and shows up as "ELAN Touchscreen". All you have to do is use map-to-output as explained in the huion section and map it to itself.

Calculating tablet area values

This is really simple maths and logic. Just read through the examples and you will get it.

Let's say I wanted an area half the size of the full area in the top left corner with the same aspect ratio as the default area.

In my case, the default area is 0 8340 0 4680.

8340 / 4680 = 1.78205128205

BottomX = 8340 / 2 = 4170 BottomY = 4170 / 1.78205128205 = 2340 The new area is 0 4170 0 2340.

Let's say I wanted to center this area. TopX = (8340 - 4170) / 2 = 2085 TopY = (4680 - 2340) / 2 = 1170 BottomX = 4170 + 2085 = 6255 BottomY = 2340 + 1170 = 3510 The new area is 2085 6255 1170 3510.

Let's say I wanted this area in the bottom right corner. TopX = 8340 - 4170 = 4170 TopY = 4680 - 2340 = 2340 BottomX = 4170 + 4170 = 8340 BottomY = 2340 + 2340 = 4680 The new area is 4170 8340 2340 4680.

If you want to achieve the same effect as "forced proportions" you can calculate the aspect ratio of your monitor and use that instead of 1.78205128205 in the above calculations. The aspect ratio for 16:9, for example, is simply 16/9 = 1.77777777778.

Mapping wacom tablets to a subregion of the screen

xsetwacom allows more advanced area configuration on wacom tablets. You can map your tablet's area to a specific region of the screen instead of an entire monitor.

xsetwacom --set <device id> MapToOutput <width>x<height>+<x>+<y>

You can get your device id with

xsetwacom --list devices

Here's some examples:

full screen:

xsetwacom --set 15 MapToOutput 1920x1080+0+0

full screen, right monitor of a dual monitor setup with 2 1920x1080 screens:

xsetwacom --set 15 MapToOutput 1920x1080+1920+0

800x600 rectangle in the top left:

xsetwacom --set 15 MapToOutput 800x600+0+0

how to calculate XY to center the area: x = (monitor width - area width) / 2 y = (monitor height - area height) / 2

note that the xy coordinates are across all screens, so for example if you have a 1024x768 monitor on the left and you want your area on the right monitor you must add 1024 to x.

Installing obs-studio for streaming and recording

As explained on the official obs site, you can install it by executing:

sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt-get update && sudo apt-get install obs-studio

Once that's done, just run OBS and set it up like you would on windows. I am using a PS3eye as a handcam which is supported out of the box on linux.

If window capture gives you a black screen, scroll down in the settings and tick "Use alpha-less texture format".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment