From ZDoom Wiki
Jump to: navigation, search

A_PlaySound (string whattoplay[, int slot[, float volume[, bool looping[, float attenuation[, bool local']]]]])

Plays the specified sound.

  • slot is the sound slot used for the sound.
  • volume is a floating point value, defaulting to 1.0. 0.0 is mute.
  • looping is a boolean, defaulting to false. Looping sounds can be stopped by using A_StopSound or playing another sound on the same channel
  • attenuation is a positive value that specifies how quickly the sound fades with distance from its source. The higher the value the quicker it fades out. The numbers are fairly low. You will notice dramatic drop off of volume with an attenuation value of just 3 or 4 and by the time you use a value of 20 you need to be within around 64 units of the sound source to hear it clearly. The following predefined constants exist: ATTN_NONE use if you want to have a sound play at the specified volume regardless of distance (anywhere on the map), ATTN_NORM use the close_dist and clipping_dist fields defined in the sound definition, ATTN_IDLE use DOOM's normal default sound attenuation behavior, ATTN_STATIC fades quickly (inaudible from 512 units).
  • local (needs description) default is false.

For example, if you want to have a sound play at the specified volume regardless of distance (anywhere on the map), use ATTN_NONE.

Sound slots

ZDoom has eight sound channels, indexed from 0 to 7. Playing a sound on a channel overrides any sound playing on the same channel, except for 0 (aka CHAN_AUTO), which first searches for a free channel, starting from 7 and decreasing until a free channel is found. If none of the channels are free, the sound is played on slot 0, overriding any sound playing there. The following constants can be used for sound slots with A_PlaySound:

  • CHAN_AUTO - 0
  • CHAN_VOICE - 2
  • CHAN_ITEM - 3
  • CHAN_BODY - 4 (the default, for historical reasons)
  • CHAN_5 - 5
  • CHAN_6 - 6
  • CHAN_7 - 7

These constants can also be represented as numbers, such as: A_PlaySound ("sound/name", 5). The slot-parameter can be further combined (using the '|' sign) with the following modifier flags:

  • CHAN_LISTENERZ (8): Sound is played from the listener's Z-height. (Needs verifying)
  • CHAN_MAYBE_LOCAL (16): Sound is subject to compat_silentpickup and will not play if the sound is made by an actor other than the local player's camera when compatibility flag is enabled.
  • CHAN_UI (32): Sound is considered an interface sound and is not recorded into savegames.
  • CHAN_NOPAUSE (64): Sound is not paused by menus and will play through time-stopping powerup effects.
  • CHAN_LOOP (256): Sound loops.

Note: Flag 128 is CHAN_AREA, which is specific to sector sounds and cannot be used with A_PlaySound.


   BLAH A 5 NoDelay A_PlaySound("play/sound")
   BLAH E -1

See also