The Big Picture: From a File to a Vibrating Cone
You double-click song.mp3. A second later music comes out of your headphones. In that second, the sound passes through nine stages: a file, an app, a decoder, a stream, a mixer, a buffer, a driver, a converter and finally a speaker. This section puts together everything from the whole chapter into one story.
┌────────────────────────────────────────────────────────────────┐
│ 1. Media player app (a process, Chapter 9) │
│ opens song.mp3 and reads the file from the SSD │
└────────────────────────────────────────────────────────────────┘
│ compressed MP3 bytes
▼
┌────────────────────────────────────────────────────────────────┐
│ 2. Decoder (inside the app or Media Foundation) │
│ MP3 -> PCM samples, e.g. 44,100 Hz, 16-bit, stereo │
└────────────────────────────────────────────────────────────────┘
│ PCM samples
▼
┌────────────────────────────────────────────────────────────────┐
│ 3. WASAPI shared-mode stream │
│ the app writes PCM into its own stream buffer │
└────────────────────────────────────────────────────────────────┘
│ one stream per app
▼
┌────────────────────────────────────────────────────────────────┐
│ 4. Audio engine inside audiodg.exe │
│ converts to the device format, mixes with other apps and │
│ system sounds, applies volume and effects (APOs) │
└────────────────────────────────────────────────────────────────┘
│ one mixed PCM stream
▼
┌────────────────────────────────────────────────────────────────┐
│ 5. Buffer in RAM (set up by the audio driver) │
│ mixed samples wait here in small pieces │
└────────────────────────────────────────────────────────────────┘
│ buffer address given to the hardware
▼
┌────────────────────────────────────────────────────────────────┐
│ 6. Audio driver + HD Audio controller (in the chipset) │
│ the controller reads the buffer from RAM by DMA │
└────────────────────────────────────────────────────────────────┘
│ bits over the HD Audio serial link
▼
┌────────────────────────────────────────────────────────────────┐
│ 7. Codec chip: the DAC │
│ numbers -> smooth voltage wave │
└────────────────────────────────────────────────────────────────┘
│ weak analogue signal
▼
┌────────────────────────────────────────────────────────────────┐
│ 8. Amplifier -> headphone jack -> cable │
│ makes the signal strong enough to drive the speaker │
└────────────────────────────────────────────────────────────────┘
│ electric current
▼
┌────────────────────────────────────────────────────────────────┐
│ 9. Speaker cone (coil and magnet) │
│ current moves the cone, the cone pushes the air │
└────────────────────────────────────────────────────────────────┘
pressure waves in the air -> your ear
Figure 33.2 — The complete chain, top to bottom. Read the text beside each arrow as "what travels down this arrow".
(Chapter 9 showed how a program becomes a process. Chapter 13 showed how drivers reach hardware. Chapter 4 showed DMA and interrupts. This section is where they all work together.)
7.1 The Application Decodes the Audio File Format
What happens: Double-clicking song.mp3 makes Windows start the associated media player. That is a normal process (Chapter 9 — Processes). The player reads the file from the SSD (Chapter 18 — Hard Disk and SSD Internals) into RAM.
The MP3 data is compressed (Section 5), so the speakers cannot use it yet. A decoder turns the compressed frames back into PCM samples: a plain list of numbers such as "44,100 samples per second, 16-bit, stereo". The decoder may be built into the player, or the player may call Windows' Media Foundation to do it. A lossless file (FLAC) is decoded the same way; a WAV file may need almost no decoding at all.
This work uses the CPU (or sometimes dedicated hardware). It is done a little ahead of playback, so that decoded audio is always ready in time.
7.2 PCM Data Is Sent via WASAPI
What happens: The player asks Windows for an audio stream on the default endpoint (Section 4) through WASAPI (Section 3.2), normally in shared mode (Section 3.3). Older APIs such as MME or DirectSound end up at the same place. The player then writes its PCM samples into the stream's buffer, again and again, staying a little ahead of the sound.
At this point the audio is still in the player's own format. Nothing has reached the hardware yet. In Task Manager you can see the player process, and in the Volume mixer the player appears with its own slider (a session).
7.3 The Windows Audio Engine Mixes Streams
What happens: The stream arrives at the audio engine inside audiodg.exe (Section 3.1), run by the Windows Audio service (Audiosrv). The engine:
- Converts the stream to the device's shared-mode format if needed (for example 44.1 kHz to 48 kHz, 16-bit to the engine's internal format).
- Mixes it with other apps' streams and system sounds by adding the samples together.
- Applies volume (per-app, then device) and any effects (APOs): loudness equalisation, spatial sound and so on.
- Writes the mixed result as one PCM stream for the endpoint.
If you play only one song with no other sound, the "mix" has just one input, but the same steps still happen.
7.4 The Audio Driver Receives the Mixed Stream
What happens: The engine places the mixed samples into a buffer in RAM that belongs to the audio driver (Section 2). The driver tells the HD Audio controller (Section 1) where that buffer is. Now the controller takes over and reads the buffer by DMA: the CPU is not copying each sample.
The controller sends the bits to the codec over the HD Audio serial link. When it reaches the end of a piece of the buffer, it raises an interrupt. The driver's ISR and DPC run, and the engine fills the freed piece with the next samples (Section 6). This takes turns for as long as the music plays.
The timeline of buffers. Several buffers are in play at the same time. Each one is a little "ahead" of the next:
Where the samples are What happens to them
-----------------------------------------------------------------------------
In the MP3 file (SSD/RAM) waiting to be decoded (seconds ahead)
Decoded PCM in the app waiting to go to WASAPI (about 100s of ms)
Engine's buffer (shared) mixed, about to go to the driver (about 10 ms)
Driver / DMA buffer being read by the controller (a few ms)
Codec / DAC being converted right now (a few samples)
Air at your ear sound, a short delay after the click
Each stage keeps a little safety margin for the one after it. If any stage runs late and the next one runs dry, you hear a glitch (underrun, Section 6).
7.5 The DAC Converts Digital to an Analogue Signal
What happens: Inside the codec chip, the DAC (Section 5.3) takes each sample number, from 48,000 or so per second per channel, and turns it into a voltage level. A filter smooths the steps into a continuous wave. The result is a weak analogue signal. Left and right channels go to separate wires.
If the audio is on HDMI, a USB headset, or Bluetooth instead, the PC sends digital audio over that link, and the DAC lives in the monitor, headset or earbuds (Section 1).
7.6 The Speaker Converts the Electrical Signal to Sound Waves
What happens: An amplifier boosts the signal so it can drive the load. The signal then travels along the cable to the speaker. The varying current flows through a coil sitting in a magnetic field. The coil is pushed and pulled, and it moves the attached cone. The cone pushes the air in front of it. The air carries the pressure wave to your ear, where your eardrum moves, and you hear the song.
The circle is complete: numbers in a file became moving air.
7.7 Seeing the Chain on Your Own PC
Each stage leaves a trace you can find (read-only):
| Stage | Where to look |
|---|---|
| Media player process | Task Manager → Processes or Details |
| Audio engine | Task Manager → Details → audiodg.exe; Get-Process audiodg |
| Audio services | Task Manager → Services; Get-Service Audiosrv, AudioEndpointBuilder |
| Per-app stream | Volume mixer (Settings → System → Sound → Volume mixer) |
| Endpoint and format | mmsys.cpl → Playback → select device → Properties → Advanced |
| Audio driver and chip | Device Manager → Sound, video and game controllers; Get-PnpDevice -Class MEDIA |
Summary
| Stage | Who does it | What it makes |
|---|---|---|
| 1. Open the file | Player process | Compressed bytes in RAM |
| 2. Decode | Decoder (CPU) | PCM samples |
| 3. Stream | WASAPI | One stream per app |
| 4. Mix | Audio engine in audiodg.exe | One mixed PCM stream (volume and effects applied) |
| 5. Buffer | Audio driver | Samples waiting in RAM |
| 6. Move | HD Audio controller by DMA | Bits over the HD Audio link |
| 7. Convert | DAC in the codec | Analogue voltage wave |
| 8. Amplify | Amplifier and jack | Current strong enough for the speaker |
| 9. Sound | Speaker cone | Pressure waves in the air |