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.