Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixed latency setting and cleaned-up OpenAL backend #5631
Before these changes each unit of latency was actually 5ms, with a minimum latency of ~10 ms. If it was set to 4 ms on the UI, the actual latency was 10 ms + 5 ms (for each buffer, 256 samples at 48kHz) * 4 ms = 30 ms.
I also renamed all variables to the current coding standard, renamed some variables to better represent what they really are, removed a redundant conversion from short to floating point when playing back stereo and swapped all C-style arrays to std::array.
This PR is partially based on PR# 5191 and PR# 5235. Some changes I believe are particularly important (such as the removal of the redundant conversion from short to float) so I want to move it from PR# 5235 which will only be merged when I manage to discover why FreeSurround causes glitches on Ubuntu 16.04.
Just did some experiments with this PR and OpenAL Soft. If we set the latency to 15 ms and reduce the period size in its config file to 128 we get the same audio latency as XAudio2
I also investigated why commenting out the Wait() event allows lower latencies.
Luckily as OpenAL is in sync with the mixer (as it plays samples at the same rate it receives them) changing Wait() to sleep_for brings only advantages.
Just reduced the default from 30 ms to 20 ms (latency between 14 and 20 ms). I could reduce it further to 10ms (latency between 7 and 10 ms), but it only works well if we edit OpenAL Soft's configuration file and set period_size to 128 samples (the default is 1024).
Of course with a X-Fi we can set it to 6ms and it works fine (latency between 4 to 6 ms).
Before these changes each value of latency were actually 5ms, with a minimum latency of ~10 ms. If it was set to 4 ms on the UI, the actual latency was 10 + 5 * 4 = 30 ms. Now 30 ms on the UI means 30 ms on the backend.
It seems to make no difference besides allowing lower latencies and more stability on hardware OpenAL cards. Maybe the Wait() call waits for too long, causing buffers underruns.