A_PlaySound

From ZDoom Wiki
Jump to: navigation, search

A_PlaySound (string soundname[, int slot[, float volume[, bool looping[, float attenuation]]]])


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, ATTN_NORM, ATTN_IDLE, ATTN_STATIC. 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_WEAPON - 1
  • CHAN_VOICE - 2
  • CHAN_ITEM - 3
  • CHAN_BODY - 4 (the default, for historical reasons)

As of (development version 94c4f38 only), slots 5 - 7 also have constants:

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

Examples

 ...
 states
 {
 Spawn:
   BLAH A 0    // functions in the first frame of the Spawn state are never called
   BLAH A 5 A_PlaySound ("play/sound")
   BLAH BCD 6
   BLAH E -1
   stop
 ...
 }


See also