Skip to content

Low Latency Audio Sync - #14849

Open
DiscoStarslayer wants to merge 6 commits into
PCSX2:masterfrom
DiscoStarslayer:feature/low-latency-audio-upstream
Open

Low Latency Audio Sync#14849
DiscoStarslayer wants to merge 6 commits into
PCSX2:masterfrom
DiscoStarslayer:feature/low-latency-audio-upstream

Conversation

@DiscoStarslayer

Copy link
Copy Markdown

Description of Changes

Adds a new low-latency sync mode. Uses SoundTouch's RateTransposer in real-time mode to automatically resample based on a streaming feedback controller. Correction is capped to a +/-1% range so it requires full speed emulation to sound correct. Will sound incorrect outside this range. Small correction range clamp keeps the pitch variability inaudible and possible to bring minimum latency down to about 20ms end to end.

During fast-forward and slow-mo, the engine will switch to TimeStretch to not destroy the user's ears.

Also includes UI changes for the ability to reduce the slider past the minimum latency reported by cubeb. On my linux machine cubeb reports 25ms minimum with the pulse backend. That is way too conservative, and I was able use and measure a real latency of about 3ms. Cubeb was happy to be launched with values lower than the minimum and if requested latency was not possible it will clamp to the lower bound safely.

Rationale behind Changes

TimeStretch keeps pitch accurate and helps to paper over slowdowns and jitter very well. The obvious trade off is latency, even without the pcsx2 buffers, the way TimeStretch configures SoundTouch

static constexpr u16 DEFAULT_STRETCH_SEQUENCE_LENGTH = 30;
static constexpr u16 DEFAULT_STRETCH_SEEKWINDOW = 20;
static constexpr u16 DEFAULT_STRETCH_OVERLAP = 10;
means the absolute latency floor is about 40ms. This configuration can be tuned somewhat, but impossible to be able to get it to the same latency as a simple rate transposer.

People interested in titles that rely on tight audio are willing to sacrifice audio consistency for latency, especially if sub-frame latency is possible which is the case with this new sync mode.

I have tested these changes on Windows and Linux machines. I've verified it works with cubeb and SDL, and have verified the WASAPI, Winmm, pulse, and jack backends. I do not have the hardware required to verify the mac backends but I doubt there will be any issues.

With settings configured with 10ms low-latency buffer, 3ms output latency on a usb 1.0 audio DAC, I was able to complete a 2hr session of amplitude with only 42 partial buffer underruns, no full underruns.

The underruns were mostly at the beginning of emulation or around loading screens/transitions. They were not audible in my session, but obviously a larger buffer would help resolve that. I only bring this up to state that I believe the new sync method as tuned is quite reliable even with a 10ms latency goal.

Can confirm it fixes issues such as #9120

Suggested Testing Steps

Test the various backends and drivers and identify any games that do not work well with the new sync mode. As there are no real SPU changes, I doubt there will be many issues here, but I won't rule out the possibility.

Did you use AI to help find, test, or implement this issue or feature?

Yes, to help guide me through creating a test controller with gp2040-ce that would fire off inputs and a gpio bit so I can measure latency on the audio side accurately with a scope. Also used to help guide understanding and proper usage of cubeb and SoundTouch apis.

@JordanTheToaster

Copy link
Copy Markdown
Member

We do not allow new contributors to use AI please read the contribution guide on the PCSX2 website.

@DiscoStarslayer

Copy link
Copy Markdown
Author

I believe this pr meets the current contribution guidelines, otherwise I wouldn't have opened it. I guess I interpreted it incorrectly. No problem.

@DiscoStarslayer
DiscoStarslayer deleted the feature/low-latency-audio-upstream branch August 15, 2026 11:35
@GovanifY

Copy link
Copy Markdown
Member

Hey,

@DiscoStarslayer sorry for the PR closure. Regarding our contribution guidelines, we ban AI usage that ends up in the submitted contribution (commits, code, PR text etc) for new contributors.
Some bits of the code looked AI assisted to some of us despite what you said in the PR description.

Since our rule change is pretty new (and the code doesn't appear to be slop) I'll grant an exception this time.
We introduced this rule mostly because of the amount of vibecoders not understanding any of the code they submit, which has been an issue as of late, and you got caught in the crosshairs, sorry for that.

Feel free to resubmit it as I cannot reopen this PR since you deleted the branch.

@DiscoStarslayer
DiscoStarslayer restored the feature/low-latency-audio-upstream branch August 17, 2026 17:12
@DiscoStarslayer

Copy link
Copy Markdown
Author

@GovanifY no apologies necessary. I can sympathize with the pain right now of running a large public project in the current environment.

I don't mind at all, no hurt feeling on if it gets rejected still. Apologies if I made your lives a little harder.

I restored the branch, is it possible to open this PR now? If not I can open a new one.

@GovanifY GovanifY reopened this Aug 17, 2026
@StillPlay2

Copy link
Copy Markdown

This fixes the initial start-up when playing an audio cd.
No 3 second delay

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants