-
Notifications
You must be signed in to change notification settings - Fork 571
TechNote_WhyGlitches
... And what can I do about it?
Glitches in Audio are generally caused by underflowing an output buffer or overflowing an input buffer. Output glitches generally happen when a source of audio cannot provide data fast enough for the receiver. There are several possible causes for this including:
- Preemption by higher priority tasks
- Improperly sized buffers
- CPU running too slow for real-time
- Bugs in the audio framework or DSP
You may find that OboeTester is handy for reproducing and investigating these issues.
This document will help you diagnose some of these issues. Here are some common issues and their symptoms.
For example, it may take two seconds to generate one seconds worth of audio. So you can never run in real-time.
Symptoms include:
- Constant glitching, it never sounds right.
- Making the buffers very big does not help.
- It sounds OK a fast flagship Android device but not on a low end device.
Solutions include:
- Reducing the number of voices if you are running a synthesizer.
- Optimize your rendering code. Use -Ofast.
- Remove any heavy operations from your callback, like allocating memory or doing I/O.
Symptoms include:
- Glitches seem random or may be associated with system activity.
- Fewer glitches when in Airplane mode.
- Increasing buffer size reduces glitches.
- It sounds OK a fast flagship Android device but not on a low end device.
- In a systrace, you may be able to see other programs running when you glitch.
- getXRunCount() returns increasing numbers when there are glitches.
Solutions include:
- Try setting CPU affinity.
- Increase your buffer sizes, setBufferSizeInFrames().
This can cause AAudio to think the DSP is reading at a different position, which can lead to collisions between the DSP reads and the CPU writes in the shared buffer.
Symptoms Include:
- Disabling MMAP in OboeTester eliminates the glitches.
- getXRunCount() returns zero even when there are glitches.
- Increasing buffer size reduces glitches.
Solutions include:
- Increase your buffer sizes, setBufferSizeInFrames().
- Manufacturers should fix the reporting of the DSP position. Generate a DSP timing profile by running the dsp_timing.py script.
Symptoms include:
- It glitches when your workload suddenly increases, such as when you suddenly play a lot more notes. Then the glitches stop as you hold the notes.
- SynthMark shows a high clock ramp time.
- Tapping you finger on a blank part of the screen reduces the glitching.
Solutions include:
- Try the StabilizedCallback class.
- Manufacturers can experiment with Boost Mode or UtilClamp.
- Apps Using Oboe or AAudio
- Tech Notes
- OboeTester Instructions
- Quirks and Bugs
- Developer Notes