Library sounds

Sound functions. Plays and manipulates sounds, optionally attaching them to an entity.

Functions

create( entity, path ) Creates a sound and attaches it to an entity.
duration( path ) Returns the duration of the sound in seconds.
emitEntity( entity, path, soundLevel, pitch ) Plays a sound from an entity.
emitWorld( origin, path, soundLevel, pitch ) Plays a sound from a fixed point in the world.
exists( path ) Checks if the given sound path exists.
playFile( path, flags, callback ) Plays a file from the given file path using IGModAudioChannel.
playURL( url, flags, callback ) Plays a sound from the given URL.
stop( entity, scriptName ) Stops a sound started by emitEntity() on the given entity.

Fields

GMOD_CHANNEL_STOPPED GMOD_CHANNEL_STOPPED
GMOD_CHANNEL_PLAYING GMOD_CHANNEL_PLAYING
GMOD_CHANNEL_PAUSED GMOD_CHANNEL_PAUSED
GMOD_CHANNEL_STALLED GMOD_CHANNEL_STALLED
FFT_256 FFT_256
FFT_512 FFT_512
FFT_1024 FFT_1024
FFT_2048 FFT_2048
FFT_4096 FFT_4096
FFT_8192 FFT_8192
FFT_16384 FFT_16384
FFT_32768 FFT_32768


Functions

sounds.create( entity, path )
Creates a sound and attaches it to an entity. You need to do sound:play() before the sound will play however. Requires the PLAY_CLIENT_SOUNDS permission when used on the client side.

Environment:

Shared

Parameters:

  • entity: Entity playing the sound
  • path: Filepath to the sound file.

Return value:

    (Sound) The sound object. Keep this around to ensure it isn't GC'd (and thus stopped) before it is done playing.
sounds.duration( path )
Returns the duration of the sound in seconds. Only works on .wav files, and there are other issues as well.

Environment:

Shared

Parameters:

  • path: The file path to get the duration for.

Return value:

    (number) The duration of the sound (in seconds).
sounds.emitEntity( entity, path, soundLevel, pitch )
Plays a sound from an entity. Quick alternative to sounds.create if you don't need the extra bit of control. Requires the PLAY_CLIENT_SOUNDS permission when used on the client side.

Environment:

Shared

Parameters:

  • entity: The entity to emit the sound from.
  • path: The name of the sound to emit (either a file name, or a sound script name).
  • soundLevel: (Optional) The sound level (in decibels), between 10 and 511.
  • pitch: (Optional) Pitch percent, from 0 to 255.
sounds.emitWorld( origin, path, soundLevel, pitch )
Plays a sound from a fixed point in the world.

Environment:

Server

Parameters:

  • origin: The position in the world to emit the sound from.
  • path: Filepath to the sound file.
  • soundLevel: (Optional) The sound level (in decibels), between 10 and 511.
  • pitch: (Optional) Pitch percent, from 0 to 255.
sounds.exists( path )
Checks if the given sound path exists.

Environment:

Shared

Parameters:

  • path: The path to check.

Return value:

    (boolean) True if the given sound path exists, false otherwise.
sounds.playFile( path, flags, callback )
Plays a file from the given file path using IGModAudioChannel. This has a few distinct advantages over traditional sounds, including FFT data, playback rate adjusting, time seeking and more. Requires the PLAY_CLIENT_SOUNDS permission.

Environment:

Client

Parameters:

  • path: The filepath to the sound you want to play.
  • flags: Space separated flags. Any of: "3d", "mono", "noplay", "noblock".
  • callback: Function to run when the audio channel is ready to play. Receives the channel, and if an error occurred, an error ID and error name.
sounds.playURL( url, flags, callback )
Plays a sound from the given URL. Requires the PLAY_URL_SOUNDS permission.

Environment:

Client

Parameters:

  • url: The URL pointing at a valid sound file or stream.
  • flags: Space separated flags. Any of: "3d", "mono", "noplay", "noblock".
  • callback: Function to run when the audio channel is ready to play. Receives the channel, and if an error occurred, an error ID and error name.
sounds.stop( entity, scriptName )
Stops a sound started by emitEntity() on the given entity. Note that this only works for sound scripts. Requires the PLAY_CLIENT_SOUNDS permission when used on the client side.

Environment:

Shared

Parameters:

  • entity: The entity to stop the sound on.
  • scriptName: The name of the sound script to stop (that was previously started with emitEntity()).

Valid XHTML 1.0!