Make SPU audio single-buffered (audio latency improvement) #2286
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why this PR exists
Since commit 05b94ef, audio produced by the emulated SPU has been double-buffered (2x2048 samples, 128 ms/~7.7 frames latency). Adding on top the output latency (another 1024 samples/~21ms/1.4 frames) gives a maximum output latency of just under 150(!) ms (>10 frames) of audio lag. This makes some games (in particular rhythm games) feel very unresponsive to input compared to real hardware.
What this PR does
This pull request does the following:
AudioLock
mutex) and reduces the buffer size back to 1024 (what it was before commit 05b94ef). This improves total audio latency to a maximum ~53 ms (~3.2 frames), which greatly improves responsiveness of the emulated software.audioBufSize
). This (along withaudioFreq
) should be made configurable in a future release (I might give it a go at some point).Notes
PascalCase
for my variable name, but I usedcamelCase
instead (since that's what the previous person did, so I copied them without reading the contribution guidelines before commiting my work :/). Should I change this (along with variable type to e.g.s32
)?EDIT: fixed latency calculations (I accidentally used 48 KHz for SPU buffer latency calculations when it should've been ~32 KHz...)