12 i_sound: Sound and Music Abstraction
This tour covers DOOM’s sound and music system through the i_sound
module.
We’ll examine the interface (i_sound.h
) and Unix/Linux implementation (i_sound.c
) for:
- Sound initialization
- Channel management
- Sound effect playback
- Audio mixing
- Music control
12.1 🧩 Sound Interface (i_sound.h
)
12.1.1 📄 File: i_sound.h
(lines 40–48)
Functions managing the sound system lifecycle: initialization, mixing, playback, and cleanup.
12.1.2 📄 File: i_sound.h
(lines 54–60)
Channel and lump utilities: - I_SetChannels
builds pitch/volume tables
- I_GetSfxLumpNum
maps SFX name to WAD lump
12.1.3 📄 File: i_sound.h
(lines 62–79)
Sound FX control interface for: - Starting/stopping sounds
- Checking status
- Updating parameters
12.1.4 📄 File: i_sound.h
(lines 93–113)
Music interface: - I_InitMusic
, I_ShutdownMusic
- I_RegisterSong
, I_UnRegisterSong
- I_PlaySong
, I_StopSong
, I_PauseSong
, I_ResumeSong
- I_SetMusicVolume
12.2 ⚙️ Sound Implementation (i_sound.c
)
12.2.1 📄 File: i_sound.c
(lines 768–776)
I_InitSound
: Opens/configures the sound device (e.g., /dev/dsp
).
12.2.2 📄 File: i_sound.c
(lines 414–423)
I_SetChannels
: Builds pitch and volume lookup tables.
12.2.3 📄 File: i_sound.c
(lines 451–456)
I_GetSfxLumpNum
: Resolves raw sound sample location in the WAD.
12.3 🔊 Runtime Sound FX Control
12.3.1 📄 File: i_sound.c
(lines 491–497)
I_StartSound
: Starts playback via addsfx
, returns handle.
12.3.2 📄 File: i_sound.c
(lines 505–514)
I_StopSound
: Stub — channel system not implemented.
12.3.3 📄 File: i_sound.c
(lines 517–521)
Handles are treated as expiry tics, not channel IDs.
12.4 🎚️ Mixing and Output
12.4.1 📄 File: i_sound.c
(lines 585–593)
I_UpdateSound
: Mixes active SFX into a stereo buffer.
12.4.2 📄 File: i_sound.c
(lines 617–622)
Clamps output to 16-bit signed range.
12.4.3 📄 File: i_sound.c
(lines 666–670)
I_SubmitSound
: Sends mixed audio to the sound device.
12.4.4 📄 File: i_sound.c
(lines 674–680)
I_UpdateSoundParams
: Stub for changing sound parameters mid-playback.
12.4.5 📄 File: i_sound.c
(lines 703–710)
I_ShutdownSound
: Sound cleanup is unimplemented (FIXME).
12.5 🎵 Music Control
12.5.1 📄 File: i_sound.c
(lines 875–879)
I_RegisterSong
: Stub — discards song data.
12.5.2 📄 File: i_sound.c
(lines 841–846)
I_PlaySong
: Schedules music to stop after 30 seconds.
12.5.3 📄 File: i_sound.c
(lines 860–867)
I_StopSong
: Stops music by clearing relevant flags.
12.5.4 📄 File: i_sound.c
(lines 884–889)
I_QrySongPlaying
: Checks if music is still playing or looping.
The i_sound
module provides DOOM’s audio abstraction layer, handling sound effects and mixing.
Music functionality is largely stubbed out for future platform-specific expansion.