PCSX2 / pcsx2

PCSX2 - The Playstation 2 Emulator
https://pcsx2.net
GNU General Public License v3.0
11.64k stars 1.61k forks source link

[BUG]: Amplitude in-game video not synchronised to audio (Linux, PipeWire) #9120

Open Tatsh opened 1 year ago

Tatsh commented 1 year ago

Describe the Bug

Audio is off by about -250 ms, meaning the audio is playing slightly before the corresponding video.

I tried to change settings a bit but nothing has really changed the behaviour.

Reproduction Steps

  1. Use version 1.7.46524 with PulseAudio support, on X11.
  2. Set settings to no audio synchronisation (allow skipping).
  3. Set latency to minimal.
  4. Play Amplitude

Expected Behavior

Game should be in sync, or there should be a better way to fix this since there is no in-game option to fix synchronisation.

As far as I can tell, there is currently no simple way to tell the video to delay by some amount, or to tell the audio to jump ahead. Or vice versa.

PCSX2 Revision

1.7.4624

Operating System

Linux (64bit) - Specify distro below

If Linux - Specify Distro

Gentoo

CPU

i9-11900K

GPU

RTX 3080 Ti

GS Settings

No response

Emulation Settings

No response

GS Window Screenshots

2023-06-29_12-18-11-00:00:14 817-0001

Video

If you play the video with an audio delay of -250ms, this is how it should look when playing.

Logs & Dumps

No response

refractionpcsx2 commented 1 year ago

And what if you set the audio synchronisation to timestretch? I mean I'm not sure why you expect the audio to be synced when forcefully turning off the synchronisation...

Tatsh commented 1 year ago

Just to note, I exited Easy Effects before running this.

Latency settings:

image

(Lots of crackling with above settings.)

With these settings, it is off by a single beat. The audio is running about 6 frames behind.

image

refractionpcsx2 commented 1 year ago

Can you do the same comparison with your PS2? does the game have latency adjustment?

Tatsh commented 1 year ago

This game unfortunately does not have adjustment. It's predecessor FreQuency also does not. Some games feature this, but most of them do not go far enough in terms of negative offset. And most of the time they do not show what the numbers on their adjustment scale actually mean.

I run my PS2 through RetroTINK 5x-Pro via SCART RGB and optical audio and I set my receiver to Direct audio mode for most music games (removes 7.1 emulation, runs stereo only, no/minimal processing). With this setup, the sync is not perfect but it's close enough to be usable. It's basically minimal lag given the circumstances of not using a CRT.

Would like to see PCSX2 do the same or better, plus it has graphics enhancements I can't do on my real PS2 or RetroTINK 5x-Pro. In the past, PCSX2 would have random speed changes that made the audio sync change while the game was running. But with recent versions PCSX2 audio seems stable, so the only thing needed is a fixed delay.

refractionpcsx2 commented 1 year ago

Just for comparisons sake, it would be nice to see/hear a recording from both so we can see exactly how different it is, cos obviously we're never going to get better than the PS2, and there will be some measure of delay since we can't do audio at the same time like the PS2 has, and as your configuration says, it will be about 40ms, which is about 2.5 frames worth of lag, and if you're already crackling, trying to lower that is going to be a problem.

Tatsh commented 1 year ago

Here is a video I recorded on my phone but it's stable although slightly sideways.

Video

Based on my inputs vs the TV, it seems like my setup is off by about 3 frames at best, 6 frames at worse.

In the previous post I said it was 6 frames behind in PCSX2 but I meant to say 12 (~400 ms). If you set this video to play with a -400 ms audio delay in mpv or similar, it will be the same as the PCSX2 video.

Edit: Use yt-dlp if you want to see the 4K version of the video. At least for me it won't give me the option in my browser.

stenzek commented 1 year ago

What does the log report the minimum latency as? This might be unique to Linux.

Tatsh commented 1 year ago
 $ rg laten
emuLog.txt
130:(Cubeb) Minimum latency: 25.00 ms (1200 audio frames)
131:(Cubeb) Minimum latency is above requested latency: 1200 vs 960, adjusting to compensate.
1184:(Cubeb) Minimum latency: 25.00 ms (1200 audio frames)
1185:(Cubeb) Minimum latency is above requested latency: 1200 vs 960, adjusting to compensate.
stenzek commented 1 year ago

Might be game specific then.

Edit: I guess one way to determine that is to remove the output from the equation. Create a video capture within PCSX2 (not with an external tool), enabling both video and audio capture. See if it's out of sync there.

Tatsh commented 1 year ago

https://youtu.be/VyScQmPi9q4

The recorded video from PCSX2 is close enough to synced.

stenzek commented 1 year ago

Interesting. I guess it's getting delayed somewhere in the output then.

None synchronization definitely will cause issues, and once it lags behind, never catches up. But timestretch should stick to the target latency.

Maybe it's happening somewhere else in the pipeline. Need to get someone to check Windows and see if it manifests there.

stenzek commented 1 year ago

Seems fine on Ubuntu 23.04 from what I can tell (using default audio settings). I'm not great at discerning input/audio lag, but there's definitely no multi-hundred-millisecond delay.

Tatsh commented 1 year ago

I can try this out on my other machine to see what happens.

Tatsh commented 1 year ago

I tried this on another machine with a near-identical setup (Gentoo, same build) and the audio syncing was still about the same. I did the test with the laptop's built-in speakers and left settings to default. The system has maximum refresh rate of 60 so now I know I cannot blame the 144 Hz display on my other system.

Tatsh commented 1 year ago

Also tried the Flatpak build and got similar results.

Tatsh commented 1 year ago

Seems fine on Ubuntu 23.04 from what I can tell (using default audio settings). I'm not great at discerning input/audio lag, but there's definitely no multi-hundred-millisecond delay.

I would imagine you're seeing the same result as me with my second machine, where it's closer but still not right.

Mrlinkwii commented 10 months ago

Can this be checked on latest nightly ?

Tatsh commented 10 months ago

I have nightly v1.7.5214. Is that recent enough?

Tatsh commented 10 months ago

On v1.7.5214 I am still getting the same issue as described above.

stenzek commented 10 months ago

Wonder if it's something funky with the Pulse wrapper. I've seen all kinds of strange audio behaviour when using pulse with VMWare.

If I have time/remember, might see about adding a pipewire API to cubeb. Have to do this ourselves, because cubeb has gone down the meme language path for any new backends, which makes it unusable for us.

Edit: I guess that's something you can try - switch the backend from pulse to alsa in settings.

Tatsh commented 10 months ago

Video is playing too ahead of the sound is the main issue. If there was a way to delay the video that would be amazing.

I reset all settings and set the output backend to ALSA. I also used a wired controller and wired headphones to eliminate all sources of lag as much as possible.

image

It's very close but just not right.

Edit: Of course with the above latency settings there is a lot of clipping.

stenzek commented 10 months ago

Set it to timestretch. "None" synchronization should never be used, because any speed fluctuation is going to add extra delay in the buffer, and it makes no attempt to reduce it once the delay gets added.

Mrlinkwii commented 9 months ago

as of v1.7.5380 , seems fine here with defaults

Mrlinkwii commented 4 months ago

@Tatsh can this be rechecked

Tatsh commented 4 months ago

Tested 1.7.5835 and it's the same. Using defaults besides upping graphics quality. Software mode also acts the same.

I also tried without Bluetooth and this definitely brings the timing closer but it's still not close enough. The difference is about -0.12 seconds, meaning the audio is behind by this much.

Reference video recorded with PCSX2:

https://github.com/PCSX2/pcsx2/assets/724848/d71bd39c-9ed5-4311-8de2-807d06df0c55

To see the correct output, play this in mpv or VLC with the delay set to -0.12 (mpv: --audio-delay=-0.12). You will hear a metronome ticking in the background and when the correct audio delay is applied, the circle indicators will align near-perfectly with the targets.

Perhaps a cheat/patch can fix the timing but I don't know enough about that subject.