Skip to content

audio: Accurate audio output timing. #1986

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

Merged
merged 3 commits into from
Dec 31, 2024

Conversation

squidbus
Copy link
Collaborator

Implements accurate timing for audio output, using a single-buffer queue same as the actual audio out library and a thread to manage audio timing.

This also removes cubeb for now at least as with this fix, SDL seems to be working just as well, and debugging is simpler if we just have to worry about one audio backend configuration. We can re-add this in the future if needed but for some Windows users it seems to be resulting in strange crashes.

Needs testing with various OSes and games to make sure this works for all audio systems, as the timing might be tight. From my testing it seems to work pretty well on Mac.

@squidbus
Copy link
Collaborator Author

This should fix #1717 for everyone

@squidbus squidbus force-pushed the audio-timing branch 2 times, most recently from f8ce208 to 3ed5149 Compare December 31, 2024 00:37
@squidbus
Copy link
Collaborator Author

Satisfied with the handling of SDL queue stalling now. This can occur if the audio device changes, for example, causing frames to back up within the queue and latency to grow if left unchecked.

@squidbus
Copy link
Collaborator Author

Please check again.

@VasylBaran
Copy link
Contributor

@squidbus I can confirm that after your changes in this build sound works properly for me. Thank you so much! ;-)

@georgemoralis
Copy link
Collaborator

this seems to work fine. I am really sorry about cubeb removal only ;/

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 31, 2024

this seems to work fine. I am really sorry about cubeb removal only ;/

The code is still in history so we can bring it back later if we need it, but I don't see a point in having it currently if there's no differences and some people report random crashes or hangs.

@georgemoralis georgemoralis merged commit 48c51bd into shadps4-emu:main Dec 31, 2024
10 checks passed
@sam20112011
Copy link

Well, the difference is in the volume. The sdl is much quieter compared to the cubeb.

@squidbus
Copy link
Collaborator Author

Well, the difference is in the volume. The sdl is much quieter compared to the cubeb.

I've never noticed a difference on my system but if this is an issue it can probably be fixed for SDL.

@Hermiten
Copy link
Collaborator

It's an issue already reported yes

@sam20112011
Copy link

Here's a demonstration of the two sound systems https://youtu.be/6Pe7JuQOjTg
Maybe in other games, there is no difference.

@EliEron
Copy link

EliEron commented Dec 31, 2024

I've also experienced the SDL being abnormally quiet issue, and for me it affect all games.

So it's not Bloodborne specific.

@rharish101
Copy link

rharish101 commented Dec 31, 2024

Just wanted to note down my experiences on PipeWire + Wayland + Arch Linux. I previously had audio issues with Bloodborne (CUSA03173) on the SDL backend, which were fixed by the cubeb backend. Now, after testing the latest main branch (i.e. after this PR was merged), there are no audio issues for me on the SDL backend.

@morten71
Copy link

morten71 commented Jan 1, 2025

I'm using gentoo linux with pulseaudio. Before this was merged I hadn't had audio troubles. When cubec was introduced, I noticed increased audio lag, but otherwise no problems.
Now most times I start Bloodborne, I have no sound, and the terminal output is filled with "audio queue backed up" messages like this:

[Lib.AudioOut] <Warning> sdl_audio.cpp:Output:71: SDL audio queue backed up (32768 queued, 32768 threshold), clearing.

Very rarely I do get sound, and no "audio queue backed up" lines at all. This seems to happen randomly.

This is my shad_log file:
shad_log_a76e8f02.txt.zip

diegolix29 added a commit to diegolix29/shadPS4 that referenced this pull request Jan 22, 2025
@squidbus squidbus deleted the audio-timing branch January 27, 2025 12:53
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Feb 27, 2025
This reverts commit 48c51bd.

# Conflicts:
#	src/common/config.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants