Deep Dive into Kotlin Flow Buffering and Execution Models Using Real-Time Audio Processing
summary
A Kotlin/Android talk examines replacing a manual MediaCodec loop with a Kotlin Flow pipeline (Producer/Intermediate/Consumer) for real‑time audio. It shows a concrete bug where shareIn creates a SharedFlow with a default 64‑entry buffer while an internal ring buffer has 30 slots, causing upstream to run ahead and audio frames to be overwritten so background music plays faster; the talk reproduces this by capturing PCM from AudioTrack and gives fixes: use a zero‑buffer SharedFlow (or set buffer 0 before shareIn) and adjust Channel send/tryReceive timing to match device AudioTrack buffer sizes.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 4:48Audio processing overview
- 9:45Producer and consumer roles
- 13:18Ring buffer basics
- 19:25Cold vs hot flows
- 27:40Shared flow buffering
- 32:12Fast-forward issue in BGM
- 34:43Summary








