Low Latency Audio Sync - #14849
Conversation
|
We do not allow new contributors to use AI please read the contribution guide on the PCSX2 website. |
|
I believe this pr meets the current contribution guidelines, otherwise I wouldn't have opened it. I guess I interpreted it incorrectly. No problem. |
|
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. Since our rule change is pretty new (and the code doesn't appear to be slop) I'll grant an exception this time. Feel free to resubmit it as I cannot reopen this PR since you deleted the branch. |
|
@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. |
|
This fixes the initial start-up when playing an audio cd. |
Description of Changes
Adds a new low-latency sync mode. Uses SoundTouch's
RateTransposerin 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
pcsx2/pcsx2/Host/AudioStreamTypes.h
Lines 71 to 73 in ca03806
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.