14  Sound Mixer: Overview

This walkthrough explores DOOM’s sound mixer subsystem: how sound/music assets are defined, registered, accessed through s_sound.h, and mixed in real time via s_sound.c.


14.1 πŸ“ sounds.h

14.1.1 πŸ“„ Lines 30–62: sfxinfo_t

Encapsulates metadata and runtime state of a sound effect:
- name, singularity, priority, linked sfx, data pointer, usefulness, lump number.


14.1.2 πŸ“„ Lines 70–84: musicinfo_t

Describes a music track’s name, lump number, memory pointer, and playback handle.


14.1.3 πŸ“„ Lines 99–111: musicenum_t

Enumerates symbolic music IDs (e.g., mus_e1m1) used to index S_music[].


14.1.4 πŸ“„ Lines 177–185: sfxenum_t

Enumerates sound effect IDs (e.g., sfx_pistol, sfx_sawhit) used to index S_sfx[].


14.2 πŸ“ sounds.c

14.2.1 πŸ“„ Lines 50–60: S_music[]

Initializes the musicinfo_t array by mapping enums to WAD lump names.


14.2.2 πŸ“„ Lines 127–135: S_sfx[]

Initializes the sfxinfo_t array: each entry defines loop behavior, default volume, links, and state.


14.3 πŸ“ s_sound.h

14.3.1 πŸ“„ Lines 168–226: API Prototypes

Defines public interface:

  • S_Init, S_Start
  • S_StartSoundAtVolume(origin, sfx_id, volume)
  • S_StopSound(origin)
  • S_StartMusic, S_ChangeMusic, S_StopMusic
  • S_PauseSound, S_ResumeSound
  • S_UpdateSounds(listener)
  • S_SetMusicVolume, S_SetSfxVolume

14.4 πŸ“ s_sound.c

14.4.1 πŸ“„ Lines 93–104: channel_t

Represents a mixing channel: active sfxinfo, origin, and the I_StartSound handle.


14.4.2 πŸ“„ Lines 161–192: S_Init

Initializes sound system: - Calls I_SetChannels - Allocates channel array in zone memory - Marks all channels as free


14.4.3 πŸ“„ Lines 202–249: S_Start

Prepares audio state at level start: - Stops all sounds - Selects and starts appropriate music


14.4.4 πŸ“„ Lines 253–299: S_StartSoundAtVolume

Plays a sound effect: - Applies link overrides - Computes 3D spatial parameters - Randomizes pitch - Picks a channel - Caches data and invokes I_StartSound


14.4.5 πŸ“„ Lines 752–818: S_AdjustSoundParams

Spatializes sound: - Computes distance - Applies stereo separation - Attenuates volume with distance falloff


14.4.6 πŸ“„ Lines 822–876: S_getChannel

Finds or reclaims a sound channel: - Prefers free or same-origin channel - Otherwise kills lowest-priority one


14.4.7 πŸ“„ Lines 708–742: S_StopChannel

Stops playback: - Calls I_StopSound - Clears sfxinfo - Manages usefulness count


14.4.8 πŸ“„ Lines 519–614: S_UpdateSounds

Main per-frame update loop: - Stops finished sounds - Updates parameters - Handles single-play music stopping


14.4.9 πŸ“„ Lines 650–687: S_ChangeMusic

Switches music: - Validates and retrieves lump - Registers and starts playback via I_PlaySong(looping)


That concludes the sound mixer overview β€” from asset definitions and initialization to dynamic real-time mixing.