The Big Picture: Sound Cannot Wait
A video can drop a frame and you hardly notice. Audio is much less forgiving. A speaker needs a steady stream of samples, 48,000 every second, with no gaps. Even a gap of a few milliseconds is heard as a click, pop or crackle.
But a PC is a busy place. The CPU switches between hundreds of threads (see Chapter 10 — Threads). The audio code cannot be sure it will run at exactly the right moment. The answer is a buffer.
6.1 The Audio Buffer's Role (Smoothing Playback)
What it is: A buffer is a short stretch of memory that holds samples waiting to be played. Think of a water tank between a tap and a hose. The tap (the software) may drip a bit unevenly. The hose (the hardware) needs a steady flow. As long as the tank never runs dry, the flow stays smooth.
Software ──fills──► [ buffer in RAM ] ──DMA reads──► codec ──► speaker
(CPU, uneven) ▒▒▒▒▒▒▒▒░░░░░░░ (steady, never waits)
full part empty part
How the hand-off works in practice. The buffer is split into small pieces (or is a ring, as in Chapter 4, Section 4). While the hardware plays piece A, the software fills piece B. When A is finished, the hardware moves on to B, raises an interrupt, and the software refills A. They take turns, like two people passing buckets.
time ─► 0 ms 5 ms 10 ms 15 ms 20 ms
hardware: [ play A ] [ play B ] [ play A ] [ play B ] ...
software: [ fill B ] [ fill A ] [ fill B ] [ fill A ] ...
(The 5 ms pieces here are only an example. Real sizes vary with the driver and mode.)
What goes wrong: underrun. If the software is late and the hardware reaches the end of the buffer before new samples arrive, it has nothing to play. This is a buffer underrun (also called a glitch or dropout). You hear a click, a stutter, or a burst of crackle.
6.2 Latency Trade-offs (Buffer Size vs Glitching)
What it is: Latency is the delay between something happening and you hearing it. For audio it includes how long samples wait in buffers.
A buffer holding N samples at a given rate adds delay:
delay = number of samples in the buffer ÷ sample rate
480 samples ÷ 48,000 per second = 0.010 s = 10 ms
So a 10 ms buffer holds 480 samples at 48 kHz. Now the trade-off:
| Small buffer | Large buffer | |
|---|---|---|
| Delay | Low (good) | High (bad) |
| Risk of glitches | Higher: the software must refill very often and on time | Lower: lots of safety margin |
| CPU work | More interrupts per second | Fewer interrupts |
| Good for | Music making, gaming voice chat, live monitoring | Playing music or video where a delay does not matter |
Typical numbers (they vary a lot, so treat them as rough):
| Path | Rough extra delay |
|---|---|
| Windows shared mode | roughly 10 to 30 ms, depending on the driver and settings |
| Exclusive mode or a pro driver such as ASIO | can be a few milliseconds |
| Bluetooth headphones | often 100 ms or more, because of compression and radio buffering |
Why does it matter? When you press a key on a virtual piano and hear the note 200 ms later, it feels broken. When you play a song, 50 ms of delay is irrelevant.
6.3 Why Audio Crackles, and Why Lip-Sync Drifts
Crackle from slow drivers. Remember from Chapter 4, Section 3 that the audio hardware's interrupt starts a quick ISR, and the real work runs in a DPC. If some other driver keeps the CPU busy in its own ISR or DPC for too long (a "DPC hog"), the audio driver cannot refill the buffer in time, and you hear crackle. Also, a heavily loaded system where audio threads are starved of CPU time (Chapter 10) does the same. Tools such as LatencyMon (free, third-party) can point at the slow driver. Fixes are usually to update or remove that driver.
Lip-sync drift. In a video, picture and sound must match. The player keeps a clock and tries to show frames at the right time compared with the sound that is actually playing. Delay in the audio path (a long buffer, or Bluetooth delay) means you hear the sound later than the picture is ready. Good players ask Windows how much delay exists and delay the picture by the same amount. Bluetooth headphones may still be slightly off, and an audio delay setting in the player can fix it.
Checklist for crackle:
| Check | Why |
|---|---|
| Is the CPU at 100%? | Audio threads may be starved |
| Any odd driver (Wi-Fi, graphics, antivirus filter) hogging DPCs? | DPC hog |
| Try a different sample rate in the Advanced tab | Some codecs glitch at certain rates |
| Turn off enhancements (effects) | A bad APO can take too long |
| Update or roll back the audio driver | Section 2 |
| Bluetooth: move closer, reduce interference | Radio dropouts act just like underruns |
Summary
| Term | Plain meaning |
|---|---|
| Buffer | Short memory area holding samples waiting to be played |
| Underrun (glitch) | The hardware ran out of samples, so you hear a click or crackle |
| Latency | Delay between the action and the sound you hear |
| Delay of a buffer | Samples in buffer ÷ sample rate (480 ÷ 48,000 = 10 ms) |
| Small buffer | Low delay, higher risk of glitches |
| Large buffer | Safe, but more delay |
| Shared mode delay | Roughly 10 to 30 ms (varies) |
| Bluetooth delay | Often 100 ms or more |
| DPC hog | A driver running too long, so the audio buffer is refilled late |
| Lip-sync drift | Sound and picture out of step because of audio delay |