Android Audio Smoothness: Performance Analysis and Optimization Guide
This guide helps Android audio developers understand and eliminate stutter, pop noise, and other glitches by examining audio formats, pipeline components, CPU scheduling, common failure cases, and offering concrete optimization steps such as proper thread priorities, reduced API blocking, and efficient frame‑count configuration.
This document targets Android audio developers and focuses on improving audio smoothness by analyzing and mitigating audio stutter and noise issues.
1. Introduction
The goal is to provide a reference for developers to understand the causes of audio glitches such as buffer underruns, pop noises, and background‑thread scheduling delays.
2. Audio Formats
Human hearing ranges from 20 Hz to 20 kHz. Typical PCM parameters include channel count (mono, stereo, 5.1, 7.1), bit depth (16‑bit, 32‑bit), and sample rate (8 kHz–384 kHz). The document lists common configurations and shows how frame size is calculated (e.g., 16 bit × 2 ch = 4 bytes per frame).
3. Common Noise Types
Pop noise (breaks in data continuity, often seen during fast‑forward or variable‑speed playback)
Zero‑padding (inserting zeros when data production lags)
Clipping (signal exceeds encoding range)
Beeps, howling, environmental background noise, and random white noise
4. Audio Pipeline Basics
The Android audio stack consists of AudioTrack/AudioRecord entry points, AAudio, OpenSL ES, FastMixer, Low‑Latency, and ULL paths. AAudio uses shared memory (mmap) to minimise copy overhead and supports three performance modes: NONE, LOW_LATENCY, and POWER_SAVING.
5. Audio and CPU Scheduling
The document explains Linux task states (R, S, D, T, X, Z) and scheduler classes (STOP, DEADLINE, RT, CFS, IDLE). It details how Android assigns audio threads a high‑priority nice value (≈101) and how cgroup migration and timerslack affect background playback.
6. Performance Case Studies
APP playback thread priority too low (nice 120) causing buffer starvation.
Game audio thread using FastMixer with insufficient priority.
NativeThread priority mis‑set, leading to severe stutter.
Blocking audio APIs (e.g., isBluetoothScoOn) on critical threads.
Calling AudioTrack.start() on the render thread causing 580 ms block.
Improper FrameCount settings (too large → silence, too small → stutter).
Excessive audio‑related Binder calls exhausting the system thread pool and triggering device reboot.
7. Joint Optimization Recommendations
Set audio‑related threads to at least nice 104 (preferably 101).
Avoid time‑consuming AudioManager calls in high‑priority threads.
Run playback logic inside a foreground Service to keep timerslack low.
Minimise frequent audio‑state queries.
8. References
Links to Apple Audio Toolbox, Windows Multimedia Class Scheduler Service, and several Chinese technical articles.
OPPO Kernel Craftsman
Sharing Linux kernel-related cutting-edge technology, technical articles, technical news, and curated tutorials
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.