Naev

Module audio

Lua bindings to interact with audio.

Functions

__eq (a1, a2) Compares two audios to see if they are the same.
__gc (audio) Frees a audio.
__tostring (audio) Gets a string representation of an audio file.
clone (source) Clones an existing audio source.
getAttenuationDistances () Gets the attenuation distances for the audio source.
getDuration (source[, unit="seconds"]) Gets the length of a source.
getPitch (source) Gets the pitch of a source.
getPosition (source) Gets the position of a source.
getRolloff () Gets the rolloff factor.
getVelocity (source) Gets the velocity of a source.
getVolume ([source]) Gets the volume of a source.
isLooping (source) Gets the looping state of a source.
isPaused (source) Checks to see if a source is paused.
isStopped (source) Checks to see if a source is stopped.
new (data[, Either="static"]) Creates a new audio source.
pause (source) Pauses a source.
play (source) Plays a source.
rewind (source) Rewinds a source.
seek (source, offset[, unit="seconds"]) Seeks a source.
setAttenuationDistances (ref, max) Sets the attenuation distances for the audio source.
setEffect (name, params) Sets effect stuff, behaves different if the first parameter is a source or not.
setGlobalAirAbsorption ([speed=3443[, absorption=-1]]) Allows setting the speed of sound and air absorption.
setGlobalDopplerFactor (factor) Sets the doppler effect factor.
setGlobalEffect ([name]) Sets a global effect.
setLooping (source, enable) Sets a source to be looping or not.
setPitch (source, pitch) Sets the pitch of a source.
setPosition (source, x, y, z) Sets the position of a source.
setRelative (relative) Sets whether a source is relative or not.
setRolloff (rolloff) Sets the rollof factor.
setVelocity (source, x, y, z) Sets the velocity of a source.
setVolume (source, vol, ignorevol) Sets the volume of a source.
soundPlay (s[, pos[, vel]]) Plays a sound.
stop (source) Stops a source.
tell (source[, unit="seconds"]) Gets the position of a source.


Functions

__eq (a1, a2)
Compares two audios to see if they are the same.

Parameters:

  • a1 Audio Audio 1 to compare.
  • a2 Audio Audio 2 to compare.

Returns:

    boolean true if both audios are the same.
__gc (audio)
Frees a audio.

Parameters:

  • audio Audio Audio to free.
__tostring (audio)
Gets a string representation of an audio file.

Parameters:

  • audio Audio Audio to get string representation of.

Returns:

    string String representation of the audio.
clone (source)
Clones an existing audio source.

Parameters:

  • source Audio Audio source to clone.

Returns:

    Audio New audio corresponding to the data.
getAttenuationDistances ()
Gets the attenuation distances for the audio source. Set to 0. if audio is disabled.

Returns:

  1. number Reference distance.
  2. number Maximum distance.
getDuration (source[, unit="seconds"])
Gets the length of a source.

Parameters:

  • source Audio Source to get duration of.
  • unit string Either "seconds" or "samples" indicating the type to report. (default "seconds")

Returns:

    number Duration of the source or -1 on error.
getPitch (source)
Gets the pitch of a source.

Parameters:

  • source Audio Source to get pitch of.

Returns:

    number Pitch of the source.
getPosition (source)
Gets the position of a source.

Parameters:

  • source Audio Source to get position of.

Returns:

  1. number X position.
  2. number Y position.
  3. number Z position.
getRolloff ()
Gets the rolloff factor.

Returns:

    number Rolloff factor or 0. if sound is disabled.
getVelocity (source)
Gets the velocity of a source.

Parameters:

  • source Audio Source to get velocity of.

Returns:

  1. number X velocity.
  2. number Y velocity.
  3. number Z velocity.
getVolume ([source])
Gets the volume of a source.

Parameters:

  • source Audio Source to get volume of. (optional)

Returns:

    number Volume the source is set to.
isLooping (source)
Gets the looping state of a source.

Parameters:

  • source Audio Source to get looping state of.

Returns:

    boolean Whether or not the source is looping.
isPaused (source)
Checks to see if a source is paused.

Parameters:

  • source Audio Source to check to see if is paused.

Returns:

    boolean Whether or not the source is paused.
isStopped (source)
Checks to see if a source is stopped.

Parameters:

  • source Audio Source to check to see if is stopped.

Returns:

    boolean Whether or not the source is stopped.
new (data[, Either="static"])
Creates a new audio source.

Parameters:

  • data string or File Data to load the audio from.
  • Either string "static" to load the entire source at the start, or "stream" to load it in real time. (default "static")

Returns:

    Audio New audio corresponding to the data.
pause (source)
Pauses a source.

Parameters:

  • source Audio Source to pause.

Returns:

    boolean True on success.
play (source)
Plays a source.

Parameters:

  • source Audio Source to play.

Returns:

    boolean True on success.
rewind (source)
Rewinds a source.

Parameters:

  • source Audio Source to rewind.
seek (source, offset[, unit="seconds"])
Seeks a source.

Parameters:

  • source Audio Source to seek.
  • offset number Offset to seek to.
  • unit string Either "seconds" or "samples" indicating the type to seek to. (default "seconds")
setAttenuationDistances (ref, max)
Sets the attenuation distances for the audio source.

Parameters:

  • ref number Reference distance.
  • max number Maximum distance.
setEffect (name, params)
Sets effect stuff, behaves different if the first parameter is a source or not.

Parameters:

  • name string Name of the effect.
  • params table or boolean Parameter table of the effect if not applied to the source, or whether or not to enable it on the source otherwise.

Returns:

    boolean true on success.

Usage:

  • audio.setEffect( "reverb", { type="reverb" } )
    
  • source:setEffect( "reverb" )
    
setGlobalAirAbsorption ([speed=3443[, absorption=-1]])
Allows setting the speed of sound and air absorption.

Parameters:

  • speed number Air speed. (default 3443)
  • absorption number Air absorptuion for all sources. Has to be a value between 0 and 10. If negative, value is ignored. (default -1)
setGlobalDopplerFactor (factor)
Sets the doppler effect factor.

Defaults to 0.3 outside of the nebula and 1.0 in the nebula.

Parameters:

  • factor number Factor to set doppler effect to. Must be positive.
setGlobalEffect ([name])
Sets a global effect. Will overwrite whatever was set. Does not affect sources created in Lua.

Parameters:

  • name string Name of the effect to set or nil to disable. (optional)
setLooping (source, enable)
Sets a source to be looping or not.

Parameters:

  • source Audio Source to set looping state of.
  • enable boolean Whether or not the source should be set to looping.
setPitch (source, pitch)
Sets the pitch of a source.

Parameters:

  • source Audio Source to set pitch of.
  • pitch number Pitch to set the source to.
setPosition (source, x, y, z)
Sets the position of a source.

Parameters:

  • source Audio Source to set position of.
  • x number X position.
  • y number Y position.
  • z number Z position.
setRelative (relative)
Sets whether a source is relative or not.

Parameters:

  • relative boolean Whether or not to make the source relative or not.
setRolloff (rolloff)
Sets the rollof factor.

Parameters:

  • rolloff number New rolloff factor.
setVelocity (source, x, y, z)
Sets the velocity of a source.

Parameters:

  • source Audio Source to set velocity of.
  • x number X velocity.
  • y number Y velocity.
  • z number Z velocity.
setVolume (source, vol, ignorevol)
Sets the volume of a source.

Parameters:

  • source Audio Source to set volume of.
  • vol number Volume to set the source to with 0.0 being silent and 1.0 being full volume.
  • ignorevol boolean Don't modify volume based on master.
soundPlay (s[, pos[, vel]])
Plays a sound.

by default, the sound is played at player's current position

Parameters:

  • s string Name of the sound to play
  • pos Vec2 Position of the source (optional)
  • vel Vec2 Velocity of the source (optional)

Usage:

  • audio.soundPlay( "hail" ) -- Plays the hail sound
    
  • audio.soundPlay( "hail", pos ) -- Plays the hail sound at position pos
    
  • audio.soundPlay( "hail", pos, vel ) -- Plays the hail sound at
    position pos with velocity vel
    
stop (source)
Stops a source.

Parameters:

  • source Audio Source to stop.
tell (source[, unit="seconds"])
Gets the position of a source.

Parameters:

  • source Audio Source to get position of.
  • unit string Either "seconds" or "samples" indicating the type to report. (default "seconds")

Returns:

    number Offset of the source or -1 on error.
generated by LDoc 1.5.0 Last updated 2025-05-08 17:02:59