forum

Keypress-to-hitsound delay

posted
Total Posts
8
Topic Starter
Devocub
Keypress-to-hitsound delay
I just need a place to post it

OS: Windows 10 64-bit 1803
Audio driver: Realtek R2.79 and Windows HD Audio
Sound card: Realtek ALC892 (built-in in mainboard)
Sample rate: 24 bit, 192kHz
FPS in osu!: <1ms (1000+ fps)

Map:
- Download: https://yadi.sk/d/CgFWzldP3aWjnS
2 difficulties:
- CBR 192kbit-s - audio for this difficulty was encoded with using Constant Bitrate mode (192 kbit/s)
- VBR50 - audio for this difficulty was encoded with using Variable Bitrate mode (50% quality)
VBR brings higher music quality compared to CBR. After encoding in CBR i have 37 ms of silence before music starts. VBR are matching source. Encoding was done by Sony Vegas 13.

Skin:
- Download: https://yadi.sk/d/ttOftk-H3aWk5L
In this skin "drum-hitnormal.wav" looks like this
When you hit a circle this hitsound will be played.

Recording this process we can measure keypress-to-hitsound delay. Let's begin.
Set volume on your headphones to max, change music volume to 0, set fps lock to unlimited (because many of things in osu! tied to fps), enable NoFail, turn on audio recording on your smartphone (i guess you can record using your PC but to decrease potential delays i use independent device), put everything near, start beatmap (CBR difficulty) and hit the circles. Example: https://youtu.be/cJ0EQf5s3Zk
After opening recording in sound editor you'll see:
in this case it is 39 ms.

I have
Logitech G102 Prodigy 1000 hz mouse with ~5ms lag (for movement) (according to: https://www.overclock.net/forum/375-mice/1607990-click-latencies-compiled.html)
125 hz USB mechanical keyboard (Steelseries 6GV2) and USB->PS/2 adapter.
I did repeat tests multiple times times. CBR difficulty by default. Results:
Realtek R2.79 driver

Steelseries 6GV2 - USB (125 Hz)
Median: 45 ms
Average: 44.707 ms
Dispersion: 40-50 ms
Number of tests: 41
Each
36
37
39
39
40
40
40
40
40
41
41
42
42
42
43
43
43
44
44
44
45
45
45
46
46
47
47
47
48
48
49
49
49
49
50
50
50
50
50
50
53
---------------------

Steelseries 6GV2 + USB -> PS/2 Adapter
Median: 40 ms
Average: 39.872 ms
Dispersion: 36-45 ms
Number of tests: 39
Each
35
35
36
36
36
36
36
37
37
37
37
37
38
38
39
39
39
39
39
40
40
40
40
40
41
41
42
42
42
42
43
43
44
44
44
45
45
45
46
---------------------

Logitech G102 (1000 hz)
Median: 40 ms
Average: 40.442 ms
Dispersion: 37-44 ms
Number of tests: 43
Each
36
37
37
37
37
37
37
37
38
38
38
38
38
39
39
39
39
39
39
40
40
40
40
41
41
41
41
41
42
42
42
42
43
43
44
44
44
44
44
44
45
46
46
---------------------

Windows HD Audio driver (without REAL)
If you didn't install audio drivers on your system then you have standard Windows HDAudio drivers, i didn't test them much but seems to be there the same delay.
Logitech G102 (1000hz)
Median: 41 ms
Average: 40.824 ms
Dispersion: 36-46 ms
Number of tests: 51
Each
36
36
36
36
36
37
37
37
37
37
38
38
38
39
39
39
39
39
39
40
40
41
41
41
41
41
41
42
42
42
42
42
42
43
43
43
43
43
43
43
44
44
44
44
44
44
44
45
45
46
46
---------------------
Auto
Here's we need precisingly mapped beatmap because lag will be measured compared to music. In this case osu! knows when the hitsound should be played.
For auto (CBR difficulty) lag is 33 ms. For auto (VBR difficulty) lag is 30 ms. Same for editor at 100% speed.


Windows HD Audio driver (with REAL)
There are a nice program called REAL (https://osu.ppy.sh/forum/t/790157) which works with Windows HD Audio driver. It doesn't work with Realtek audio drivers (i tested).

Logitech G102 (1000 hz)
Median: 26 ms
Average: 25.923 ms
Dispersion: 21-31 ms
Number of tests: 52
Each
21
21
22
22
22
22
22
22
22
23
23
23
23
23
24
24
24
24
24
25
25
25
25
26
26
26
26
27
27
27
27
27
27
27
28
28
28
28
28
29
29
29
29
29
29
29
29
30
30
30
31
31
---------------------

Steelseries 6GV2 + USB -> PS/2 Adapter
Median: 27 ms
Average: 26.6 ms
Dispersion: 21-31 ms
Number of tests: 50
Each
20
20
21
21
21
21
22
22
23
23
24
24
24
24
24
25
25
25
25
26
26
26
26
27
27
27
27
28
28
28
28
29
29
29
29
29
29
29
29
29
30
30
30
31
31
31
31
31
33
33
---------------------


Auto
For auto (CBR difficulty) lag is 33 ms. For auto (VBR difficulty) lag is 30 ms.


Summary

For players and mappers:
  1. Universal global offset affects only music. For example -10 ms global offset will make music play 10 ms earlier relatively hitobjects (circles, sliders and spinners). +10 ms and music will be playing 10 ms later.
  2. Local offset affects only hitobjects on current beatmap. For example +10 ms local offset will shift them to 10 ms later.
  3. There are no offset settings for hitsounds.
  4. What only you can do with hitsounds - delay them by editing skin hitsound files.


For players:
  1. Be careful with USB audio, it can have additional latency (but usually it's 8 ms).
  2. Sound effects can add audio latency.
  3. According to this video (https://youtu.be/eEswl6kZq5k) 1000 Hz keyboards are most fastest. But keep in mind that keyboards are different.
  4. If you have 125 Hz keyboard then USB->PS/2 adapter will be useful to decrease hit latency.
  5. High chance that wireless = +lag.
  6. Linux brings very low latencies (like 10 ms) https://blog.thepoon.fr/osuLinuxAudioLatency
  7. Keyboards have debounce time - delay to make sure that key was actually pressed. Usually it's not over 10 ms. Shoutouts to Razer for a good picture: https://d4kkpd69xt9l7.cloudfront.net/sys-master/images/h90/hb5/9018448609310/razer-opto-mechanical-performance2-usp-desktop-v2.jpg
    Wiki: https://en.wikipedia.org/wiki/Keyboard_technology#Debouncing
  8. Mice clicks are debounced too.


For mappers:
  1. Ranking criteria for bitrate: https://osu.ppy.sh/help/wiki/Ranking_Criteria#rules.4
  2. Use VBR, it brings higher quality. VBR quality setting 70-75 will give near 192 kbit/s result.
  3. Reencode only if source file have higher than 192 kbit/s bitrate, else do nothing.
  4. Test your beatmap on few real players.
  5. Don't use 25%, 50%, 75% speeds in editor to find right offset, it screw ups the music: https://i.imgur.com/0pZVxMs.jpg
  6. If you need to put objects to first ~0.2s (200 ms) of map then you'll better add silence to mp3 to avoid some problems. For example if you have a hitobject at 50 ms of audio and user will set global offset, for example, to -100 ms then it will be impossible to hit it.
  7. If you did same tests (for auto) as I and got same result, then you can adjust global offset and play map with auto to hear roughly same what i will hear when i will play this map without auto.


If you want to do the tests
  1. Post your results here
  2. Audacity - free and open source audioeditor https://www.audacityteam.org/download
  3. For Sony Vegas users:
  4. - Vegas can't open my aac lol. Converter your aac/m4a from phone to wav https://audio.online-convert.com/convert-to-wav
    - File → Properties → Ruler → Ruler time format → Time. And you'll see everything in ms instead of frames.
    - Options → Disable Quantize to frames (Alt+F8). And you will not be tied to frames.
  5. Script to count average, etc. Can run here http://sandbox.onlinephpfunctions.com


Script
<?php

function calculate_median($arr) {
$count = count($arr); //total numbers in array
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
if($count % 2) { // odd number, middle is the median
$median = $arr[$middleval];
} else { // even number, calculate avg of 2 medians
$low = $arr[$middleval];
$high = $arr[$middleval+1];
$median = (($low+$high)/2);
}
return $median;
}

function calculate_average($arr) {
$total = 0;
$count = count($arr); //total numbers in array
foreach ($arr as $value) {
$total = $total + $value; // total value of array numbers
}
$average = ($total/$count); // get average value
return $average;
}

$t = '
40
41 put your results here
42
43
';

$ar = explode("\n", trim($t));

sort($ar);

$new = [];
foreach ($ar as $v) {
$new[] = trim($v);
echo trim($v)."\n";
}

echo "Median: ".calculate_median($new)." ms \n".
"Average: ".round(calculate_average($new),3)." ms \n".
"Dispersion: ms\n".
"Number of tests: ".count($new)."\n";



Where do latency came from?
I don't know, ask experts.
Uncertain information because i'm not expert: https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/low-latency-audio#span-idwindowsaudiostackspanspan-idwindowsaudiostackspanspan-idwindowsaudiostackspanwindows-audio-stack
I think best and easiest solution is custom audio driver.
From 0 to 10 ms of delay comes from BASS library (audio engine in osu!), it's possible(?) to reduce this value to 0-5 ms.
Roughly 5 ms in average comes from debouncing algorithms from your keyboard (or mice). This value can be up to 10 ms, depends of keyboard.

How to reduce latency?
I don't know how but i want to.
- Use REAL (https://osu.ppy.sh/forum/t/790157) with Windows HD Audio driver (https://i.imgur.com/wQhxTUa.jpg)
- Avoid listening to sound through USB, because it's always passes through your device-specific audiocard, which can have decent latency. But casual values for USB audio devices is 8 ms.
- Avoid using any sound effects.
- peppy need(?) to change BASS update period in osu! source code to minimal 5 ms instead of current 10 ms (https://www.un4seen.com/doc/#bass/BASS_CONFIG_UPDATEPERIOD.html)

For programmers:
Maybe it will help in decreasing audio latency
https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/custom-audio-drivers
https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/low-latency-audio
https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/stream-latency-during-playback
https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/roadmap-for-developing-wdm-audio-drivers
https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/sample-audio-drivers
https://github.com/Microsoft/Windows-driver-samples/tree/master/audio/sysvad
https://github.com/CHEF-KOCH/GamingTweaks#sound
https://github.com/alanfox2000/realtek-universal-audio-driver

--------
Update 1
ALC1150 - Realtek drivers - delay is 60-70 ms

If you have problems with too low sound volume even at 100% after switching to Microsoft HDA drivers then run Realtek R2.82 audio drivers installer, it will suggest to you to delete old Realtek drivers, reboot and install new. After reboot kill installer process and deleting installer folder from "Program files" or "Program files (x86)".
Windows 10 also have automatic installation of drivers, so you might need to temporary disable it - google "automatic drivers install disable".
mixa_zxc
Жесть тебе заняться нечем, братан :(
miniant
Thanks for the skin and the map, they'll really come in handy with latency testing!

Could you add more tests, this time with REAL enabled?

EDIT:
Tested on my setup with Windows 10 HDAudio driver. Average results over 30 measurements:
Without REAL: 40.3ms
With REAL: 31ms

You should always expect to have up to 10ms deviation in individual tests because osu! uses default audio buffer size of 10ms.
Topic Starter
Devocub
For some reason i can't edit my post

-------------
osu!lazer (2019.1205.0) 05 november 2019
osu!lazer with REAL (44100 Hz, 24 bit, audio buffer 10.159 ms -> 2.54 ms)

Median: 42 ms
Average: 41.457 ms
Dispersion: 36-47 ms
Number of tests: 35
Each
34
35
36
36
36
37
37
37
38
39
39
40
40
40
41
41
42
42
42
42
42
42
43
43
43
44
44
45
45
46
46
47
47
48
52
---------------------
osu!lazer without REAL (44100 Hz, 24 bit, audio buffer default 10.159 ms)

Median: 56 ms
Average: 55.844 ms
Dispersion: 50-60 ms
Number of tests: 45
Each
48
49
49
50
50
51
52
52
52
52
53
53
53
54
54
55
55
56
56
56
56
56
56
57
57
57
57
57
57
57
58
58
58
59
59
59
59
59
59
60
60
60
60
64
64
---------------------


----------------------------

osu! stable Win 7
(44100 Hz, 24 bit), default microsoft audio drivers
no REAL because win 7 doesn't support it

CBR
Median: 47 ms
Average: 47.821 ms
Dispersion: 43-54 ms
Number of tests: 39
Each
38
42
42
42
43
43
43
43
44
44
44
45
45
46
46
46
46
46
47
47
47
49
50
50
50
50
50
51
51
51
52
52
53
54
54
54
54
55
56
---------------------

VBR
Median: 47 ms
Average: 47.875 ms
Dispersion: 43-55 ms
Number of tests: 40
Each
42
42
42
43
43
43
44
44
45
45
45
45
45
45
46
46
46
46
46
47
47
48
48
48
49
49
49
49
50
50
50
51
52
52
54
54
55
56
56
58
---------------------
miniant
I've always wondered why lazer feels way worse to play than stable but never actually made effort to test the audio latency. Thanks for doing the hard work and publishing results!
Frs4ken
Did some testing today.
Here are the results.


ALC1220(gigabyte z390 pro wifi)
Glorious model o- 4ms debounce
aux headphones plugged in back panel

I thought the new WASAPI implementation reduced the audio latency but my testing shows otherwise.
Also tested the audio latency on my laptop and also did not see an improvement using wasapi instead of compatibility mode(directsound)
Topic Starter
Devocub
latency for osu compatibile mode

and default mode (wasapi)


wasapi+real


mcosu wasapi build shared (not exclusive) mode

and exclusive mode
Isshiki Kaname
The buffer is there because not all hardware can do low latency audio without dropping out and causing distortions.
peppy doesn't want to have people complain about audio freaking out. I do believe it should be un-hardcoded, but then clueless people who don't understand shit will be a headache to peppy.
Please sign in to reply.

New reply