Glitches are breaks in the flow of audio. they sound like pops or crackle. Glitches are normally caused by a buffer underrun. Keeping more data in the buffer can reduce glitching. But the extra data adds latency. Glitches and latency are thus connected.
We have two goals:
These are normally fixed by the Android framework team before a device is shipped.
These are the most serious causes of glitches because they are not easily fixed by the audio team nor by the application developer.
In #2, the CPU scheduler is supposed to raise the CPU clock frequency when it sees that the application workload has increased. But this can take about 100 msec. If you have a 4 msec buffer then it will obviously underflow.
In #3, a core migration can make the CPU scheduler lose its knowledge of the audio task workload. This can trigger the problem in #2 even if the app has a steady workload. Setting CPU affinity to a single core can prevent this. But that can get in the way of the CPU scheduler doing its job.
The combination of #2 and #3 means that any low-latency audio task with a moderate to heavy workload can glitch. We are working with the Linux kernel teams to fix this. Luckily the glitches can be detected by the app and the latency increased to reduce the glitches. But the increase in latency can be significant.
#1452 - report of increased core migration on Android 12.
Search for glitches: https://github.com/google/oboe/issues?q=is%3Aissue+glitches