Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS2 Delayed Audio - Pipewire #3283

Closed
kodatarule opened this issue Sep 28, 2023 · 91 comments
Closed

CS2 Delayed Audio - Pipewire #3283

kodatarule opened this issue Sep 28, 2023 · 91 comments

Comments

@kodatarule
Copy link

Your system information

Operating System: EndeavourOS
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.10
Kernel Version: 6.5.3-273-tkg-bmq (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5800X3D 8-Core Processor
Memory: 31,3 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 3090/PCIe/SSE2

Please describe your issue in as much detail as possible:

Firstly the game requires a launch command in order to get audio to work under pipewire and second it has a good between 2-5 seconds delay, you see the action on screen and after that you hear the audio.
For CS GO neither of those issues were present.

Steps for reproducing this issue:

  1. Just try to play the game using pipewire( launch command -sdlaudiodriver pipewire required otherwise game would be without audio)
@jnvsor
Copy link

jnvsor commented Sep 28, 2023

I had this occur but only after playing for a few hours. It went away after a game restart but it does happen

Edit: Yeah it seems to slowly desync and get later and later from what I've seen

@ZeroYamaoka
Copy link

ZeroYamaoka commented Sep 28, 2023

I had same isuee i changed default sound device in game option to my Soundcard that i use and it fixed the problem for me (Well maybe it will help)

@stealingudc
Copy link

This hack reduced the audio delay to up to a second for me on Debian 12 with pipewire-pulse. Even so, it's still barely playable.

valve, pls fix

@JacKeTUs
Copy link

Guys, can you retest please if latency will still build up on latest update without any workarounds?

@JacKeTUs
Copy link

JacKeTUs commented Sep 29, 2023

I tried retest it with latest update - latency is still building up.

My method of testing:

  • Microphone
  • CS2
  • Audacity
  • Carla

Launch Audacity, set Recording Device - cs2 app. Press record in stereo. In Carla reroute your mic capture to PortAudio device - that's our Audacity. So left channel in Audacity records cs2 and right channel is my mic. I click the mouse and then hear cs2 gunshots. I measure latency between start of a click and start of sound from CS2.

Initially right after map was loaded, before mouse click and sound of a gun i had ~90-100ms (of course my system latency / recording software latency/etcetc will affect it, but i didn't change it through tests, nor restart the game / sound system / audacity, etc)
After 10-15 minutes - about 110-120ms latency
Another 10 minutes - about 140ms latency
Another 10 minutes - about 170ms, already noticeable with eyes
Another 10 - about 200ms, already unplayable
Another 15 - about 230-240ms, unplayable indeed

So latency did build up for me.

image

image

image

image

@JacKeTUs
Copy link

JacKeTUs commented Sep 29, 2023

cs2latency.zip
I exported project to .ogg file, you can try to import it in audacity. Original aup3 is 145Mb, quite big for github
Timestamps:
0s - 48s - right after loading the game
48s - 1m21s - after ~10minutes
1m22s - 2m04s - after another ~10 minutes
2m05s - 2m55s - after another ~10 minutes
2m55s - 3m33s - after another ~10 minutes

My system information: https://gist.github.com/JacKeTUs/d36b8e75a78f96160fd9c12eeccab18b
Pipewire 0.3.80, config: https://gist.github.com/JacKeTUs/abc72942af8e96a47a7eba4430fc5643

@JacKeTUs
Copy link

May be it's the Pipewire issue, but i definitely didn't have that desync problem with csgo and other games (osu!lazer for example, rhythm game where sound latency even +-20ms is critical)

@szmarczak
Copy link

I can confirm that the latency builds up (flatpak steam, pipewire).

@szmarczak
Copy link

szmarczak commented Sep 29, 2023

Changing the audio device also fixes the latency issue (you have to actually change the device by selecting it from the menu, and change it back to the old one). The changes takes a few hundred ms to take effect, so binding this to a key like W or MOUSE1 won't be ok :(

@NiSchie
Copy link

NiSchie commented Sep 29, 2023

Can confirm latency buildup.

Operating System: Arch
XFCE Version 4.18
GTK Version: 3.24.38
Qt Version: 5.15.10
Kernel Version: 6.5.5-arch1-1
Graphics Platform: X11
Processors: AMD Ryzen 5 3600
Memory: 16 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 1660 Ti
Sound server: pipewire

@jpgay
Copy link

jpgay commented Sep 29, 2023

Latency buildup also occurs with PulseAudio.
System info: https://gist.github.com/jpgay/a6f3f51e590652eef96c91216b1e7e96

@itouchdennis
Copy link

Having the same problem on pipewire.

Did someone test it with alsa ?

Yesterday I tried the workaround with the .asoundrc, timings where on point for the time I tested it, but unfortunately my sound got stuttering and cracking after a short while so I did not test it one or two matchmaking games, just for some short deathmatches.

My console got also following output while using the .asoundrc file:

[SoundSystemLowLevel] Audio device starved 512 samples

Which could indicate a too huge bitrate and a too small buffersize - might take a look this evening to check if I could lower the sample rate and maybe increase a bit the buffer size (I assume the buffer size should not be that huge, as it could also cause delay).

@JacKeTUs
Copy link

JacKeTUs commented Sep 29, 2023

Some tinkering:
Game tries to use pulseaudio by default, and on my system it defaults to pipewire-pulse bridge. On pw-top i can see that game asks for 256 quantum and 48000 rate by default

Forced pipewire does not help.
PULSE_LATENCY_MSEC=60 and PIPEWIRE_LATENCY=128/48000 added to launch command did not help. My thoughts was "if i set constant latency, issue will be fixed".

Also - latency increases even if game is staying in background

edit: forced pipewire tested

@JacKeTUs
Copy link

@icculus, i believe that you could help us here, maybe?
Tell us please, how can we test this more throughfully?

@Jerroder
Copy link

Jerroder commented Sep 29, 2023

I have the exact problem jnvsor described... but I'm on windows 10

I tried reinstalling windows and it didn't fix it. One idea I have is that I can change my USB sound card's buffer size, but even when trying with lower or higher values it doesn't fix it.

@itouchdennis
Copy link

itouchdennis commented Sep 29, 2023

I tested a quick deathmatch with the update today, sound works but seems a bit delayed.

I added the start option
-dxvk
And retested a quick deathmatch, sound was crisp on point, I will play later some games and see if a delay builds up or this would work, might be related to the vulkan build(?)

Might be placebo, need to test more

@Spacefish
Copy link

Pipewire on ubuntu 23.10 here, i have up to a second delay. Latest public CS2 version. If i shoot i see the 3-4th shot and then the sound starts playing..

@xstaticxgpx
Copy link

xstaticxgpx commented Sep 30, 2023

I think I was able to make a noticeable improvement by doing this - so it might be worth trying different values to see what works best for your setup? I use a S24LE/96khz USB DAC so this may not work for everyone...

Launch options:

env PULSE_LATENCY_MSEC=30 %command% -vulkan -novid -nojoy +exec autoexec.cfg

Seems like you can confirm the change with pw-mon looking for application.name = cs2

Before

        properties:
                client.api = "pipewire-pulse"
                pulse.server.type = "unix"
..
                application.process.binary = "cs2"
                application.name = "cs2"
..
                node.rate = "1/96000"
                node.latency = "512/96000"

After

node.rate = "1/96000"
node.latency = "720/96000"

(or look at the QUANT column in pw-top - it seems like usual applications show 1024 or 2048 🤷‍♂️)

This still seems hacky because the application should probably be coordinating better with the pipewire/whatever daemon... this is a random selection of chromium/firefox/mpv/cs2 all playing audio:

S   ID  QUANT   RATE    WAIT    BUSY   W/Q   B/Q  ERR FORMAT           NAME                                                                
S   28      0      0    ---     ---   ---   ---     0                  Dummy-Driver                                                        
S   29      0      0    ---     ---   ---   ---     0                  Freewheel-Driver
S   36      0      0    ---     ---   ---   ---     0                  Midi-Bridge     
R   42    512  96000  82.4us  17.7us  0.02  0.00    0    S24LE 2 96000 alsa_output.usb-NuForce__Inc._NuForce___DAC_2-01.analog-stereo
R   52   1024  96000  18.0us  11.1us  0.00  0.00    0    F32LE 2 96000  + Chromium                                                   
R   65   2646  44100  30.2us  26.7us  0.01  0.00    0    S16LE 2 44100  + mpv                                                              
R   58   3600  48000  58.2us  11.8us  0.01  0.00    0    F32LE 2 48000  + Firefox Developer Edition
R   71    720  96000  70.8us   4.3us  0.01  0.00    0    F32LE 2 96000  + cs2                                                              

PULSE_LATENCY_MSEC=60 and PIPEWIRE_LATENCY=128/48000 added to launch command did not help. My thoughts was "if i set constant latency, issue will be fixed".

@JacKeTUs I think the 128 seen in your second envvar there might have prevented the first from working properly.

PULSE_LATENCY_MSEC=60 works even better for me, very crisp - most noticeable with pistols for whatever reason.

@JacKeTUs
Copy link

@xstaticxgpx, i tried first with pulse-pipewire bridge, without any arguments and only PULSE_LATENCY_MSEC, and later with forced pipewire with only PIPEWIRE_LATENCY added. With both methods i still had build-up latency issue
How long you've been testing the game? Because at first yeah, sound is on point, but later, like 30-40 minutes - it's becoming more and more delayed

@xstaticxgpx
Copy link

xstaticxgpx commented Sep 30, 2023

I previously had the same behavior where after ~30min it was unplayable because of the sound delay - now with PULSE_LATENCY_MSEC=60 I can play for at least ~2 hours with zero noticeable delay. FWIW, as described here: https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/FAQ#pipewire-buffering-explained

Note that PIPEWIRE_LATENCY= does nothing for PulseAudio clients.

So that probably does nothing here for cs2, so maybe you guys just need to try different values?

@JacKeTUs Did you mean "forced pipewire" with this? SDL_AUDIODRIVER=pipewire ?

@JacKeTUs
Copy link

Yes, but with -sdlaudiodriver pipewire.
Without any other args game defaults to Pulseaudio, and on my system there is pulse-pipewire bridge, which imitates Pulseaudio api. Without any args i tried PULSE_LATENCY_MSEC, and got similar results with increasing latency over time. For tests i also tried to set comically high latency like 2 seconds - it worked, and latency still would build itself up lol

Later i tried with forced pipewire with -sdlaudiodriver=pipewire - PULSE_LATENCY_MSEC stopped working, and i needed to set PIPEWIRE_LATENCY instead. Sadly it didn't help at all

@xstaticxgpx
Copy link

xstaticxgpx commented Sep 30, 2023

Yea something is still messed up here, there is less delay and it doesn't seem to get much worse as quickly, I'm thinking it's related to the number of sounds played and so testing in a bot match vs public deathmatch it manifests differently 🤔

Starting a bot match after extended pub deathmatch play with the sound delay and checking console:

> sv_cheats true
> snd_report_verbose_error true
[AI BT]: Unable to buy after multiple attempts.
[Developer] Failed to find ui preference 'spec_autodirector_cameraman'
[ResourceSystem] Failed loading resource "panorama/images/_small_png.vtex_c" (ERROR_FILEOPEN: File not found)
[Shooting] sv: Lag comp - full interp info doesn't match target time, using target time instead.
[Shooting] sv: Lag comp - full interp info doesn't match target time, using target time instead.
[Shooting] sv: Lag comp - full interp info doesn't match target time, using target time instead.
[AI BT]: Unable to buy after multiple attempts.
[AI BT]: Unable to buy after multiple attempts.
[AI BT]: Unable to buy after multiple attempts.
[AI BT]: Unable to buy after multiple attempts.
[Shooting] sv: Lag comp - full interp info doesn't match target time, using target time instead.
Achievements disabled: cheats turned on in this app session.
[Shooting] sv: Lag comp - full interp info doesn't match target time, using target time instead.
[Shooting] sv: Lag comp - full interp info doesn't match target time, using target time instead.

Maybe that's helpful to Valve?

Also trying:

Remove all envvars, use -sdlaudiodriver alsa - see pw-top:

S   ID  QUANT   RATE    WAIT    BUSY   W/Q   B/Q  ERR FORMAT           NAME                                                                
I   28      0      0   0.0us   0.0us  0.00  0.00    0                  Dummy-Driver
S   29      0      0    ---     ---   ---   ---     0                  Freewheel-Driver
S   36      0      0    ---     ---   ---   ---     0                  Midi-Bridge
R   46   2048  96000  71.1us  48.4us  0.00  0.00    0    S24LE 2 96000 alsa_output.usb-NuForce__Inc._NuForce___DAC_2-01.analog-stereo
R   84   1024  44100   9.3us  47.2us  0.00  0.00    0    F32LE 2 44100  + ALSA plug-in [cs2]

EDIT:
Well.. using alsa fixes the audio delay for me but now causes crackling/popping audio and this seen in console:

[SoundSystemLowLevel] Increased audio mix latency to 8 buffers
[SoundSystemLowLevel] Audio device starved 512 samples
...

Which is a similar issue in DOTA2 apparently: ValveSoftware/Dota-2#2425

No amount of SDL_AUDIO_ALSA_SET_PERIOD_SIZE and/or SDL_AUDIO_ALSA_SET_BUFFER_SIZE seems to help there.

@candreacchio
Copy link

Unsure if this is related, but if i play a few games, or leave cs open for a while, it starts to become more and more out of sync

@icculus
Copy link
Collaborator

icculus commented Oct 2, 2023

Did you mean "forced pipewire" with this? SDL_AUDIODRIVER=pipewire ?

(It's SDL_AUDIO_DRIVER, extra underscore, in SDL3. SDL_AUDIODRIVER is ignored.)

@szmarczak
Copy link

Tested the latest update, the issue is still present.

@Cutaneus
Copy link

Cutaneus commented Oct 3, 2023

I have the same problem on Kubuntu 22.04 (Ryzen 5600x, AMD Radeon 6700XT, flatpak steam)
If the sound has started to lag, then switching sound devices in the game settings helps (choose another sound card, then back)

@simifor
Copy link

simifor commented Nov 12, 2023

I haven't noticed audio getting delayed in the past few days, it's possible that it's fixed at least in some configuration, or perhaps it now takes longer for the delay to become noticeable. But at least for me, the experience has improved.

@Mershl
Copy link

Mershl commented Nov 12, 2023

The issue is still present. Became very noticeable at the end of two premier matches (~70 minutes total).

@af7567
Copy link

af7567 commented Nov 12, 2023

I just tested with the default pipewire settings (48000 Hz rate) and still have this issue, noticeable after 10 rounds. So it still needs the pipewire default rate forcing to 44100.

@meklu
Copy link

meklu commented Nov 17, 2023

ptt

One of the workarounds mentioned elsewhere was to enable streamlined push-to-talk, where the input audio device is constantly read. I also enabled playing audio in the background. This seems to more or less fix the issue with my PulseAudio setup with (by default) 48000Hz rate and f32 sample format. Without the workaround I was getting really bad audio delay after less than half an hour of gameplay.

@gonX
Copy link

gonX commented Nov 18, 2023

Worth noting that Pipewire users can use the env var PIPEWIRE_RATE to force a specific sample rate for an application. However, this seems to also require using the ALSA sound driver.

Changing my launch options to the following fixed all the sound delay issues I had that are caused by non-44KHz sample rate usage:

SDL_AUDIO_DRIVER=alsa PIPEWIRE_RATE=1/44100 %command%

Tested with Pipewire 0.3.84 on the Nov 17 15:25 build of CS2.

@danir-de
Copy link

SDL_AUDIO_DRIVER=alsa PIPEWIRE_RATE=1/44100 %command%

This works perfectly! Thanks!

@fir3-1ce
Copy link

fir3-1ce commented Nov 25, 2023

Replying to #3283 (comment)

This works somewhat, but I had to switch the audio devices back and forth a few times for the sound to start working. I also just experienced a crash after playing a couple matches where my audio interface is no longer detected, even after exiting the game. I also lost control of my keyboard for some reason.

@af7567
Copy link

af7567 commented Nov 25, 2023

It doesn't sound right that PIPEWIRE_RATE would make any difference to the alsa driver. Unless alsa is using pipewire as the default output - but then using the pipewire driver instead would remove the alsa->pipewire layer so should work better?
Using alsa without any other env vars always worked for me as long as nothing else had the output device locked. Though I haven't tested that for a while since changing my default pipewire rate to 44100 has been good.

@idarlund
Copy link

idarlund commented Nov 29, 2023

Thanks for the workaround @ipaqmaster !

I wanted to not remember to push a button all the time. Shooting or moving keys are out of the question because the workaround stops sound for a couple of ms. So I decided to add it when showing score board. This has been working flawlessly for a couple of matches now.

Added this to autoexec.cfg (and +exec autoexec.cfg to launch options ofc):
alias +scorensound "sound_device_override Source2SDLDefaultDevice; sound_device_override MDR-1000X; +showscores";
alias -scorensound "-showscores";
bind tab "+scorensound";

And as @ipaqmaster pointed out; check your sound_device_override fist so you know what to put in that last sound_device_override command.

As a sidenote; when doing this I'm seeing this in the console: [Developer] Failed to find ui preference 'spec_autodirector_cameraman
I don't know what this means, but maybe the developers have an idea :)

@boustrophedon
Copy link

boustrophedon commented Dec 1, 2023

This seems to be fixed? I just noticed I had left my game open for several hours and when I came back the audio wasn't delayed. I have -sdlaudiodriver pipewire in my launch settings.

EDIT: nevermind, see below

@icculus
Copy link
Collaborator

icculus commented Dec 1, 2023

To be clear, I think everyone was leaning towards this not being a Pipewire thing, but rather a very-high-sample-rate thing, so I'd like to hear if this is working for the 192,000Hz crowd.

@nadanke
Copy link

nadanke commented Dec 1, 2023

To be clear, I think everyone was leaning towards this not being a Pipewire thing, but rather a very-high-sample-rate thing, so I'd like to hear if this is working for the 192,000Hz crowd.

Just tested.

Without -sdlaudiodriver pipewire or SDL_AUDIO_DRIVER=alsa PIPEWIRE_RATE=1/44100 I'm still getting very noticeable delay after only a few minutes.

With -sdlaudiodriver pipewire I didn't notice any delay after a few minutes of playing.

SDL_AUDIO_DRIVER=alsa PIPEWIRE_RATE=1/44100 also fixed it for me, but I haven't retested that with the latest update.

@fir3-1ce
Copy link

fir3-1ce commented Dec 1, 2023

SDL_AUDIO_DRIVER=alsa PIPEWIRE_RATE=1/44100 stopped working for me after the latest update... I can't get any sound at all with that launch option. They added an "ALSA default output" option to the audio devices, which does nothing for me. They also removed my interface, which is what I would select before to get the sound picked up

-sdlaudiodriver pipewire gives me no audio devices to choose from. It only says "Sound disabled"

@boustrophedon
Copy link

boustrophedon commented Dec 1, 2023

To be clear, I think everyone was leaning towards this not being a Pipewire thing, but rather a very-high-sample-rate thing, so I'd like to hear if this is working for the 192,000Hz crowd.

I just ran pw-metadata -n settings 0 clock.force-rate 96000 and am testing currently.

My audio interface seems to support 192000 but running the above command with 192000 doesn't seem to work, when I relaunched CS it was only at 96000.

Here's what I'm seeing in pactl list for CS

        Driver: PipeWire
        Owner Module: n/a
        Client: 22876
        Sink: 63
        Sample Specification: float32le 2ch 96000Hz
        Channel Map: front-left,front-right
        Format: pcm, format.sample_format = "\"float32le\""  format.rate = "96000"  format.channels = "2"  format.channel_map = "\"front-left,front-right\""
        Corked: no
        Mute: no
        Volume: front-left: 39799 /  61% / -13.00 dB,   front-right: 39799 /  61% / -13.00 dB
                balance 0.00
        Buffer Latency: 0 usec
        Sink Latency: 0 usec
        Resample method: PipeWire
        Properties:
                media.type = "Audio"
                media.category = "Playback"
                media.role = "game"
                application.name = "SDL Application"
                node.name = "Audio Stream"
                device.description = "Audio Stream"
                node.latency = "2048/96000"
                node.rate = "1/96000"
                node.always-process = "true"
                node.dont-reconnect = "true"
                target.object = "alsa_output.usb-Schiit_Audio_Schiit_Unison_Modius-00.analog-stereo"
                media.name = "Audio Stream"
                stream.is-live = "true"
                node.autoconnect = "true"
                node.want-driver = "true"
                media.class = "Stream/Output/Audio"
                adapt.follower.spa-node = ""
                object.register = "false"
                factory.id = "7"
                clock.quantum-limit = "8192"
                factory.mode = "split"
                audio.adapt.follower = ""
                library.name = "audioconvert/libspa-audioconvert"
                client.id = "249"
                object.id = "130"
                object.serial = "22877"
                module-stream-restore.id = "sink-input-by-media-role:game"

Everything seems fine so far but I've only been playing for maybe 20 minutes.

@boustrophedon
Copy link

I left the game open for several hours at 96000 and the delay is back. I'm on pipewire 1.0.0, which was released a few days ago (but is api/abi compatible with 0.3)

@nadanke
Copy link

nadanke commented Dec 3, 2023

Replying to #3283 (comment)

Okay with -sdlaudiodriver pipewire I still get delay, but it builds up less fast than it does without it (on 192khz)

@simifor
Copy link

simifor commented Dec 15, 2023

has anyone had the delay bug recently? I had the game open for 3 hours and didn't notice a delay. No special launch parameters, system uses pipewire 1.0

@ipaqmaster
Copy link

I haven't noticed it because I forced my DAC rate to 44100 to work around this problem long ago.

What is your sample rate set to? If it's higher than 44100 then your evidence is valid.

@kodatarule
Copy link
Author

I still experience the same delay, it's just very random, sometimes it comes fast, other times it takes some time to be in-game to trigger it.

@simifor
Copy link

simifor commented Dec 15, 2023

@ipaqmaster 48KHz in my case and I used to have the issue in the past but seemingly not anymore. Though clearly there are still people affected.

@rLy07
Copy link

rLy07 commented Dec 16, 2023

I just played like 5 matches and had no issue at all. I didn't use any of the workaround mentioned here.

@ZeroYamaoka
Copy link

ZeroYamaoka commented Dec 17, 2023

Well played some casual matches and didnt notice the problem on 96 KHz good job devs but maybe at least you mention that you fixed the problem in patch notes ?

I use pipewire with SoundBlaster Z SE card

@af7567
Copy link

af7567 commented Dec 17, 2023

I just tested playing a couple of games using the default pipewire settings on my Slackware system instead of forcing it to 44100 and didn't notice any delay, so seems to be fixed for me too, either by a cs2/SDL update or pipewire 1.0.
In my case the default rate is 48000 and I confirmed that the soundcard playback rate was 48000 in the alsa info.

@kisak-valve
Copy link
Member

Closing per the last several comments.

@MatiasPViecho
Copy link

Just got a pair of bluetooth headphones and i'm having the same issue, doesn't seem like any of the solutions provided here works for me :(

@simifor
Copy link

simifor commented May 9, 2024

@MatiasPViecho bluetooth tends to have poor latency, so it's likely that and not the game causing the delay. You probably have a delay with other games as well.

@MatiasPViecho
Copy link

@MatiasPViecho bluetooth tends to have poor latency, so it's likely that and not the game causing the delay. You probably have a delay with other games as well.

Hey! Quite late to answer but i tested it and yeah, I didn't notice the delay on other games, music and tv shows until you mentioned it, its just that in CS audio is so important that i just happened to notice it there haha

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

No branches or pull requests