So guys, how to play with minimal latency
0) Remove pulseaudio. No shit.
1) Dealing with alsa buffers.
If you have a sound card without hardware mixing (all internal cards and cheap external ones), then all the mixing is done by alsa in the plugin called dmix. We should tune this to achieve overall minimal application->sound card latency.
All we need is to set period_size and buffer_size as minimal as it can be for out sound card. To get current numbers run your favourite audio player with your favourite track and run:
cat /proc/asound/card0/pcm0p/sub0/hw_params (card0, pcm0p and sub0 may vary).
Now we should determine minimal period_size. Create /etc/asound.conf:
Make sure nobody uses audio device (cat /proc/asound/card0/pcm0p/sub0/hw_params should output "closed"), run your audio player and execute:
cat /proc/asound/card0/pcm0p/sub0/hw_params
again. You should hear cracking sound, so don't worry.
Now it's time to deal with buffer_size. 512 is a good value to start with. Set it in your /etc/asound.conf as well. Open your player, listen to some music a bit, you should hear clear sound without cracklings. If you head cracking sound, increase you buffer_size, but , it should be multiple of period_size.
My values are 32 and 640.
2) Tuning directsound buffers.
Osu! uses directsound for audio output and it has own buffers too. It can be configured via wines' regedit.
Run regedit and navigate to HKEY_CURRENT_/Software/Wine/DirectSound.
By default buffer size is 65536 and sound queue is 10.
Firstly, decrease sound queue. Create string parameter(REG_SZ) named "SndQueueMax" and set it to 3 for example, then run osu!. It should start and you definitely will hear that latency has become lower. Close the game.
Now, create key named "HelBuflen" — it's directsound buffer size. Set it to 16384 and then run the game. If you hear cracking sound, increase buffer twice.
3) Patching winealsa.drv
For the best latency, you can change buffers in dlls/winealsa.drv/mmdevdrv.c wine source file, then recompile it.
Values to change:
DefaultPeriod, MinimumPeriod, EXTRA_SAFE_RT. I have it 20000/20000/10000. With this values you can set directsound buffer size even lower.
0) Remove pulseaudio. No shit.
1) Dealing with alsa buffers.
If you have a sound card without hardware mixing (all internal cards and cheap external ones), then all the mixing is done by alsa in the plugin called dmix. We should tune this to achieve overall minimal application->sound card latency.
All we need is to set period_size and buffer_size as minimal as it can be for out sound card. To get current numbers run your favourite audio player with your favourite track and run:
cat /proc/asound/card0/pcm0p/sub0/hw_params (card0, pcm0p and sub0 may vary).
[23:16:07] valdikss@valtop ~/games/osu! $ cat /proc/asound/card0/pcm0p/sub0/hw_params6000+18000 = 24000 / 1000 = 24ms! Quite a big number.
access: MMAP_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 6000
buffer_size: 18000
Now we should determine minimal period_size. Create /etc/asound.conf:
pcm.!default {
type plug
slave.pcm "dmixer"
}
pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:0,0"
period_size 1
buffer_size 1
}
}
Make sure nobody uses audio device (cat /proc/asound/card0/pcm0p/sub0/hw_params should output "closed"), run your audio player and execute:
cat /proc/asound/card0/pcm0p/sub0/hw_params
again. You should hear cracking sound, so don't worry.
access: MMAP_INTERLEAVEDAs for me, minimal period_size is 32. Set this value into your /etc/asound.conf.
format: S16_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 32
buffer_size: 64
Now it's time to deal with buffer_size. 512 is a good value to start with. Set it in your /etc/asound.conf as well. Open your player, listen to some music a bit, you should hear clear sound without cracklings. If you head cracking sound, increase you buffer_size, but , it should be multiple of period_size.
My values are 32 and 640.
2) Tuning directsound buffers.
Osu! uses directsound for audio output and it has own buffers too. It can be configured via wines' regedit.
Run regedit and navigate to HKEY_CURRENT_/Software/Wine/DirectSound.
By default buffer size is 65536 and sound queue is 10.
Firstly, decrease sound queue. Create string parameter(REG_SZ) named "SndQueueMax" and set it to 3 for example, then run osu!. It should start and you definitely will hear that latency has become lower. Close the game.
Now, create key named "HelBuflen" — it's directsound buffer size. Set it to 16384 and then run the game. If you hear cracking sound, increase buffer twice.
3) Patching winealsa.drv
For the best latency, you can change buffers in dlls/winealsa.drv/mmdevdrv.c wine source file, then recompile it.
Values to change:
DefaultPeriod, MinimumPeriod, EXTRA_SAFE_RT. I have it 20000/20000/10000. With this values you can set directsound buffer size even lower.