Sound

From SRB2 Wiki
Jump to navigation Jump to search
This article or section is outdated and has not been fully updated to reflect the current version of SRB2.

Please help the Wiki by correcting or removing any misinformation, as well as adding any new information to the page.

To do
Mention captions.
This article is about the definition and format of sounds. For a list of sounds that are used in SRB2, see List of sounds. For how to insert sound files into a WAD or PK3 file, see Sound and music tutorial.

Sounds, or sound effects, are used for a variety of different purposes in SRB2. Aside from sound effects that are hardcoded into the game, such as the menu sounds, there are also ways to play back sounds that can be customized for use in addons, for example through SOC, Lua or linedef executors. SRB2 currently includes 409 sounds as well as 1600 free slots for custom sounds.

Format

SRB2's sounds are stored as lumps in the Sounds/ folder of srb2.pk3. SRB2 recognizes a large number of sound formats; see Sound and music tutorial > Accepted sound formats for a full list. The lump name for a sound is in all-uppercase and begins with the DS prefix. Following this prefix is a unique name for the sound, which consists of up to six characters. For example, the sound used by the Alarm has the unique name alarm and is therefore stored in the lump DSALARM.

Internally, SRB2 stores each sound in a slot with a unique slot number. There are 2009 sound slots in SRB2, of which 409 are occupied by the sounds used in SRB2 itself and the other 1600 are freeslots which can be used by custom sounds. SOC and Lua provide special constants that can be used as synonyms for slot numbers: These constants have the form of the sfx_ prefix followed by the sound name in all-lowercase. For example, the alarm sound, which is stored in slot 23, can be identified by the constant sfx_alarm. Additionally, SOC also recognizes the lump names for sounds as constants, e.g., DSALARM can be used equivalently to sfx_alarm.

To assign a custom sound to one of the freeslots and create an sfx_ constant for it, a freeslot declaration has to be created in SOC or Lua. See Freeslots > Declaring freeslot names for more information.

See Sound and music tutorial > Sounds for an explanation of how to add custom sounds to SRB2.

Attributes

Sounds have several attributes that can be set via a SOC block or by writing to the sfxinfo table in Lua:

  • Priority: This decides which sounds to play when all sound channels are in use. Sounds with a higher priority value are favored over sounds with a lower priority value.
  • Singular: If this is set to 1, the sound can be played only once at a time on any sound channel, no matter which Object started the sound. If an attempt is made to play this sound while another instance of it is still playing, the one already playing will be interrupted and then restarted.
  • Flags: These flags are used for special playback settings. To set several flags at once, perform the bitwise OR operator (|) on them. For example, to set the flags SF_NOMULTIPLESOUND, SF_OUTSIDESOUND and SF_X4AWAYSOUND, write Flags = SF_NOMULTIPLESOUND|SF_OUTSIDESOUND|SF_X4AWAYSOUND in the sound's SOC block. The functions of the flags are as follows:
Decimal Hexadecimal Flag name Description
1 0x01 SF_TOTALLYSINGLE An Object can only play one sound with this flag at a time. If a second one is played, the one already playing is interrupted and the new one is played instead (cannot be combined with any other flags).
2 0x02 SF_NOMULTIPLESOUND The sound can only be played once at a time on any sound channel, no matter which Object started the sound. Attempting to play the sound more than once at the same time has no effect and the one already playing is not interrupted. This overrides the Singular parameter.
4 0x04 SF_OUTSIDESOUND The volume of the sound depends on how close the player is to an "outside area" (any sector with F_SKY1 as its ceiling flat). The closer the player is, the louder the volume. This is used by the rain sound, for example.
8 0x08 SF_X4AWAYSOUND The sound can be heard from four times the regular distance.*
16 0x10 SF_X8AWAYSOUND The sound can be heard from eight times the regular distance.*
32 0x20 SF_NOINTERRUPT The sound does not interrupt other sounds; if it is attempted to be played in a situation where it would be interrupting another sound, it is not played. This does not work in combination with the Singular parameter, use the SF_NOMULTIPLESOUND flag instead.
64 0x40 SF_X2AWAYSOUND The sound can be heard from two times the regular distance.*

* You can combine the flags SF_X2AWAYSOUND, SF_X4AWAYSOUND and SF_X8AWAYSOUND to further increase the hearing distance. For example, combining all three flags makes the distance increase equal to 2 × 4 × 8 = 64.

Note
An Object cannot play the same sound twice at the same time. For example, if an Object is playing sfx_alarm and then attempts to play the same sound again without letting the previous playback finish, the sound is interrupted and then restarted.

SOC definition

This is an example of a sound definition written with SOC and the syntax it uses.

Sound sfx_rumble
Singular = 0
Priority = 64
Flags = SF_X4AWAYSOUND|SF_X8AWAYSOUND

Lua definition

This is an example of a sound definition written with Lua. Note that all attributes are written in all-lowercase.

Longhand definition

sfxinfo[sfx_rumble] = {
        singular = false,
        priority = 64,
        flags = SF_X4AWAYSOUND|SF_X8AWAYSOUND
}

Shorthand definition

This requires all the fields to be filled out. The order of the fields follow the longhand definition above.

sfxinfo[sfx_rumble] = {false, 64, SF_X4AWAYSOUND|SF_X8AWAYSOUND}

Playing sound effects

SRB2 offers several ways to play sound effects, most of which can be customized for addons:

Object sound slots

Objects have five sound slots that can be called when certain events happen. Like with states, the conditions in which these sounds are played vary depending on the type of Object and the actions it uses. Some of the names of the sound slots correspond to a state slot, and these sounds are often, but not always, called simultaneously with the corresponding states. There are also specific actions that can be used to play back these sounds. Listed below are the five available sound slots and their most common usages:

  • SeeSound is usually played when the SeeState is executed. A_PlaySeeSound is made specifically to call this sound.
  • AttackSound is usually played by certain attack actions for enemies. The action A_PlayAttackSound is made specifically to call this sound.
  • PainSound is usually played when the PainState is executed. The action A_Pain is made specifically to call this sound.
  • DeathSound is usually played when the DeathState is executed. The action A_Scream is made specifically to call this sound.
  • ActiveSound is used for miscellaneous sounds that are part of an Object's animation. A_PlayActiveSound is made specifically to call this sound.

Finally, the action A_PlaySound can play any specified sound, even if it is not in one of the actor's sound slots.

Others

  • Lua can access several functions related to playing sounds, including functions to start playing a sound, stop playing a sound or check if a certain sound is currently being played. See Lua/Functions > S_Sound for a list of available functions.
  • Linedef type 414 is a linedef executor that can be used to play a sound when a dynamic event happens in a map.
  • Ambient sound effects are invisible, intangible Objects that can be placed in a map in order to continually play a background sound effect.
  • The soundtest console command and the Sound Test unlockable can play a specified sound effect.
  SOC [view]
General ClearMainCfg
Objects ObjectStateSoundSprite2SpriteInfoSprite2InfoFreeslot
Unlockable content EmblemExtraEmblemUnlockableConditionSet
Miscellaneous WipesCharacterLevelCutscene / ScenePromptMenuHudItem
Related links ActionsConstantsCustom Object tutorial