Sound

From SRB2 Wiki
Jump to: navigation, search
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 file, see Sound and music tutorial.

Sounds are used by Objects to play back sound effects when certain events happen. Every type of Object has five sound slots that can be occupied for this purpose, and there are specific actions that can be used to play them. Unlike most other SOC elements, sounds are structured in a very simple way and contain few parameters apart from the sound effect itself.

Called sounds

Objects have five sound slots that can be activated when certain events happen. Like with states, these conditions 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.

Attributes

NoteIcon.png 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.
  • 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.

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}
  Sonic Object Configuration [view]
General ClearMainCfg
Objects ObjectStateSoundFreeslot
Unlockable content EmblemExtraEmblemUnlockableConditionSet
Miscellaneous WipesCharacterLevelCutscene / SceneHudItem
Related links ActionsConstantsObject creation tutorial