naev 0.12.6
nlua_audio.c File Reference

Bindings for Special effects functionality from Lua. More...

#include "nlua_audio.h"
#include "AL/efx.h"
#include "array.h"
#include "nlua_file.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "nopenal.h"
#include "ntracing.h"
#include "sound.h"
Include dependency graph for nlua_audio.c:

Go to the source code of this file.

Data Structures

struct  LuaAudioEfx_t
 Handles the OpenAL effects that have been set up Lua side. More...

Functions

static int stream_thread (void *la_data)
static int stream_loadBuffer (LuaAudio_t *la, ALuint buffer)
 Loads a buffer.
static int audio_genSource (ALuint *source)
 Tries to generate a single openal source, running GC if necessary.
static int audioL_tostring (lua_State *L)
 Lua bindings to interact with audio.
static int audioL_gc (lua_State *L)
 Frees a audio.
static int audioL_eq (lua_State *L)
 Compares two audios to see if they are the same.
static int audioL_new (lua_State *L)
 Creates a new audio source.
static int audioL_clone (lua_State *L)
 Clones an existing audio source.
static int audioL_play (lua_State *L)
 Plays a source.
static int audioL_pause (lua_State *L)
 Pauses a source.
static int audioL_isPaused (lua_State *L)
 Checks to see if a source is paused.
static int audioL_stop (lua_State *L)
 Stops a source.
static int audioL_isStopped (lua_State *L)
 Checks to see if a source is stopped.
static int audioL_rewind (lua_State *L)
 Rewinds a source.
static int audioL_seek (lua_State *L)
 Seeks a source.
static int audioL_tell (lua_State *L)
 Gets the position of a source.
static int audioL_getDuration (lua_State *L)
 Gets the length of a source.
static int audioL_setVolume (lua_State *L)
 Sets the volume of a source.
static int audioL_getVolume (lua_State *L)
 Gets the volume of a source.
static int audioL_setRelative (lua_State *L)
 Sets whether a source is relative or not.
static int audioL_setPosition (lua_State *L)
 Sets the position of a source.
static int audioL_getPosition (lua_State *L)
 Gets the position of a source.
static int audioL_setVelocity (lua_State *L)
 Sets the velocity of a source.
static int audioL_getVelocity (lua_State *L)
 Gets the velocity of a source.
static int audioL_setLooping (lua_State *L)
 Sets a source to be looping or not.
static int audioL_isLooping (lua_State *L)
 Gets the looping state of a source.
static int audioL_setPitch (lua_State *L)
 Sets the pitch of a source.
static int audioL_getPitch (lua_State *L)
 Gets the pitch of a source.
static int audioL_setAttenuationDistances (lua_State *L)
 Sets the attenuation distances for the audio source.
static int audioL_getAttenuationDistances (lua_State *L)
 Gets the attenuation distances for the audio source. Set to 0. if audio is disabled.
static int audioL_setRolloff (lua_State *L)
 Sets the rollof factor.
static int audioL_getRolloff (lua_State *L)
 Gets the rolloff factor.
static int audioL_setEffect (lua_State *L)
 Sets effect stuff, behaves different if the first parameter is a source or not.
static int audioL_setGlobalEffect (lua_State *L)
 Sets a global effect. Will overwrite whatever was set. Does not affect sources created in Lua.
static int audioL_setGlobalAirAbsorption (lua_State *L)
 Allows setting the speed of sound and air absorption.
static int audioL_setGlobaDopplerFactor (lua_State *L)
 Sets the doppler effect factor.
static int audioL_soundPlay (lua_State *L)
 Plays a sound.
static int audioL_isBool (lua_State *L, ALenum param)
 Checks to see a boolean property of a source.
static int audioL_isState (lua_State *L, ALenum state)
 Checks to see the state of the source.
int nlua_loadAudio (nlua_env env)
 Loads the audio library.
LuaAudio_tlua_toaudio (lua_State *L, int ind)
 Gets audio at index.
LuaAudio_tluaL_checkaudio (lua_State *L, int ind)
 Gets audio at index or raises error if there is no audio at index.
LuaAudio_tlua_pushaudio (lua_State *L, LuaAudio_t audio)
 Pushes a audio on the stack.
int lua_isaudio (lua_State *L, int ind)
 Checks to see if ind is a audio.
void audio_cleanup (LuaAudio_t *la)
void audio_clone (LuaAudio_t *la, const LuaAudio_t *source)
static void efx_setnum (lua_State *L, int pos, ALuint effect, const char *name, ALuint param)
static void efx_setint (lua_State *L, int pos, ALuint effect, const char *name, ALuint param)
static void efx_setbool (lua_State *L, int pos, ALuint effect, const char *name, ALuint param)
static int audioL_setEffectGlobal (lua_State *L)
static LuaAudioEfx_taudio_getEffectByName (const char *name)

Variables

static LuaAudioEfx_tlua_efx = NULL
 List of effects handled by Lua. These are persistent throughout game runtime.
static const luaL_Reg audioL_methods []

Detailed Description

Bindings for Special effects functionality from Lua.

Definition in file nlua_audio.c.

Function Documentation

◆ audio_cleanup()

void audio_cleanup ( LuaAudio_t * la)

Definition at line 341 of file nlua_audio.c.

◆ audio_clone()

void audio_clone ( LuaAudio_t * la,
const LuaAudio_t * source )

Definition at line 608 of file nlua_audio.c.

◆ audio_genSource()

int audio_genSource ( ALuint * source)
static

Tries to generate a single openal source, running GC if necessary.

Definition at line 445 of file nlua_audio.c.

◆ audio_getEffectByName()

LuaAudioEfx_t * audio_getEffectByName ( const char * name)
static

Definition at line 1658 of file nlua_audio.c.

◆ audioL_clone()

int audioL_clone ( lua_State * L)
static

Clones an existing audio source.

Lua function parameter: Audio source Audio source to clone. Lua return parameter: Audio New audio corresponding to the data.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: clone

Definition at line 664 of file nlua_audio.c.

◆ audioL_eq()

int audioL_eq ( lua_State * L)
static

Compares two audios to see if they are the same.

Lua function parameter: Audio a1 Audio 1 to compare. Lua function parameter: Audio a2 Audio 2 to compare. Lua return parameter: boolean true if both audios are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 433 of file nlua_audio.c.

◆ audioL_gc()

int audioL_gc ( lua_State * L)
static

Frees a audio.

Lua function parameter: Audio audio Audio to free.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __gc

Definition at line 418 of file nlua_audio.c.

◆ audioL_getAttenuationDistances()

int audioL_getAttenuationDistances ( lua_State * L)
static

Gets the attenuation distances for the audio source. Set to 0. if audio is disabled.

Lua return parameter: number Reference distance. Lua return parameter: number Maximum distance.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getAttenuationDistances

Definition at line 1352 of file nlua_audio.c.

◆ audioL_getDuration()

int audioL_getDuration ( lua_State * L)
static

Gets the length of a source.

Lua function parameter: Audio source Source to get duration of. Lua function parameter:[opt="seconds"] string unit Either "seconds" or "samples" indicating the type to report. Lua return parameter: number Duration of the source or -1 on error.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getDuration

Definition at line 958 of file nlua_audio.c.

◆ audioL_getPitch()

int audioL_getPitch ( lua_State * L)
static

Gets the pitch of a source.

Lua function parameter: Audio source Source to get pitch of. Lua return parameter: number Pitch of the source.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getPitch

Definition at line 1263 of file nlua_audio.c.

◆ audioL_getPosition()

int audioL_getPosition ( lua_State * L)
static

Gets the position of a source.

Lua function parameter: Audio source Source to get position of. Lua return parameter: number X position. Lua return parameter: number Y position. Lua return parameter: number Z position.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getPosition

Definition at line 1123 of file nlua_audio.c.

◆ audioL_getRolloff()

int audioL_getRolloff ( lua_State * L)
static

Gets the rolloff factor.

Lua return parameter: number Rolloff factor or 0. if sound is disabled.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getRolloff

Definition at line 1396 of file nlua_audio.c.

◆ audioL_getVelocity()

int audioL_getVelocity ( lua_State * L)
static

Gets the velocity of a source.

Lua function parameter: Audio source Source to get velocity of. Lua return parameter: number X velocity. Lua return parameter: number Y velocity. Lua return parameter: number Z velocity.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getVelocity

Definition at line 1181 of file nlua_audio.c.

◆ audioL_getVolume()

int audioL_getVolume ( lua_State * L)
static

Gets the volume of a source.

Lua function parameter:[opt] Audio source Source to get volume of. Lua return parameter: number Volume the source is set to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getVolume

Definition at line 1054 of file nlua_audio.c.

◆ audioL_isBool()

int audioL_isBool ( lua_State * L,
ALenum param )
static

Checks to see a boolean property of a source.

Definition at line 235 of file nlua_audio.c.

◆ audioL_isLooping()

int audioL_isLooping ( lua_State * L)
static

Gets the looping state of a source.

Lua function parameter: Audio source Source to get looping state of. Lua return parameter: boolean Whether or not the source is looping.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: isLooping

Definition at line 1231 of file nlua_audio.c.

◆ audioL_isPaused()

int audioL_isPaused ( lua_State * L)
static

Checks to see if a source is paused.

Lua function parameter: Audio source Source to check to see if is paused. Lua return parameter: boolean Whether or not the source is paused.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: isPaused

Definition at line 737 of file nlua_audio.c.

◆ audioL_isState()

int audioL_isState ( lua_State * L,
ALenum state )
static

Checks to see the state of the source.

Definition at line 252 of file nlua_audio.c.

◆ audioL_isStopped()

int audioL_isStopped ( lua_State * L)
static

Checks to see if a source is stopped.

Lua function parameter: Audio source Source to check to see if is stopped. Lua return parameter: boolean Whether or not the source is stopped.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: isStopped

Definition at line 801 of file nlua_audio.c.

◆ audioL_new()

int audioL_new ( lua_State * L)
static

Creates a new audio source.

Lua function parameter: string|File data Data to load the audio from. Lua function parameter:[opt="static"] string Either "static" to load the entire source at the start, or "stream" to load it in real time. Lua return parameter: Audio New audio corresponding to the data.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 485 of file nlua_audio.c.

◆ audioL_pause()

int audioL_pause ( lua_State * L)
static

Pauses a source.

Lua function parameter: Audio source Source to pause. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: pause

Definition at line 718 of file nlua_audio.c.

◆ audioL_play()

int audioL_play ( lua_State * L)
static

Plays a source.

Lua function parameter: Audio source Source to play. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: play

Definition at line 680 of file nlua_audio.c.

◆ audioL_rewind()

int audioL_rewind ( lua_State * L)
static

Rewinds a source.

Lua function parameter: Audio source Source to rewind.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: rewind

Definition at line 812 of file nlua_audio.c.

◆ audioL_seek()

int audioL_seek ( lua_State * L)
static

Seeks a source.

Lua function parameter: Audio source Source to seek. Lua function parameter: number offset Offset to seek to. Lua function parameter:[opt="seconds"] string unit Either "seconds" or "samples" indicating the type to seek to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: seek

Definition at line 845 of file nlua_audio.c.

◆ audioL_setAttenuationDistances()

int audioL_setAttenuationDistances ( lua_State * L)
static

Sets the attenuation distances for the audio source.

Lua function parameter: number ref Reference distance. Lua function parameter: number max Maximum distance.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setAttenuationDistances

Definition at line 1329 of file nlua_audio.c.

◆ audioL_setEffect()

int audioL_setEffect ( lua_State * L)
static

Sets effect stuff, behaves different if the first parameter is a source or not.

Lua usage parameter: audio.setEffect( "reverb", { type="reverb" } ) Lua usage parameter: source:setEffect( "reverb" )

Lua function parameter: string name Name of the effect. Lua function parameter: table|boolean params Parameter table of the effect if not applied to the source, or whether or not to enable it on the source otherwise. Lua return parameter: boolean true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setEffect

Definition at line 1681 of file nlua_audio.c.

◆ audioL_setEffectGlobal()

int audioL_setEffectGlobal ( lua_State * L)
static

Definition at line 1436 of file nlua_audio.c.

◆ audioL_setGlobaDopplerFactor()

int audioL_setGlobaDopplerFactor ( lua_State * L)
static

Sets the doppler effect factor.

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

Lua function parameter: number factor Factor to set doppler effect to. Must be positive.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setGlobalDopplerFactor

Definition at line 1793 of file nlua_audio.c.

◆ audioL_setGlobalAirAbsorption()

int audioL_setGlobalAirAbsorption ( lua_State * L)
static

Allows setting the speed of sound and air absorption.

Lua function parameter:[opt=3443] number speed Air speed. Lua function parameter:[opt=-1] number absorption Air absorptuion for all sources. Has to be a value between 0 and 10. If negative, value is ignored.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setGlobalAirAbsorption

Definition at line 1767 of file nlua_audio.c.

◆ audioL_setGlobalEffect()

int audioL_setGlobalEffect ( lua_State * L)
static

Sets a global effect. Will overwrite whatever was set. Does not affect sources created in Lua.

Lua function parameter:[opt] string name Name of the effect to set or nil to disable.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setGlobalEffect

Definition at line 1724 of file nlua_audio.c.

◆ audioL_setLooping()

int audioL_setLooping ( lua_State * L)
static

Sets a source to be looping or not.

Lua function parameter: Audio source Source to set looping state of. Lua function parameter: boolean enable Whether or not the source should be set to looping.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setLooping

Definition at line 1211 of file nlua_audio.c.

◆ audioL_setPitch()

int audioL_setPitch ( lua_State * L)
static

Sets the pitch of a source.

Lua function parameter: Audio source Source to set pitch of. Lua function parameter: number pitch Pitch to set the source to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setPitch

Definition at line 1243 of file nlua_audio.c.

◆ audioL_setPosition()

int audioL_setPosition ( lua_State * L)
static

Sets the position of a source.

Lua function parameter: Audio source Source to set position of. Lua function parameter: number x X position. Lua function parameter: number y Y position. Lua function parameter: number z Z position.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setPosition

Definition at line 1096 of file nlua_audio.c.

◆ audioL_setRelative()

int audioL_setRelative ( lua_State * L)
static

Sets whether a source is relative or not.

Lua function parameter: boolean relative Whether or not to make the source relative or not.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setRelative

Definition at line 1074 of file nlua_audio.c.

◆ audioL_setRolloff()

int audioL_setRolloff ( lua_State * L)
static

Sets the rollof factor.

Lua function parameter: number rolloff New rolloff factor.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setRolloff

Definition at line 1377 of file nlua_audio.c.

◆ audioL_setVelocity()

int audioL_setVelocity ( lua_State * L)
static

Sets the velocity of a source.

Lua function parameter: Audio source Source to set velocity of. Lua function parameter: number x X velocity. Lua function parameter: number y Y velocity. Lua function parameter: number z Z velocity.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setVelocity

Definition at line 1154 of file nlua_audio.c.

◆ audioL_setVolume()

int audioL_setVolume ( lua_State * L)
static

Sets the volume of a source.

Lua function parameter: Audio source Source to set volume of. Lua function parameter: number vol Volume to set the source to with 0.0 being silent and 1.0 being full volume. Lua function parameter: boolean ignorevol Don't modify volume based on master.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setVolume

Definition at line 1026 of file nlua_audio.c.

◆ audioL_soundPlay()

int audioL_soundPlay ( lua_State * L)
static

Plays a sound.

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

Lua usage parameter: audio.soundPlay( "hail" ) – Plays the hail sound Lua usage parameter: audio.soundPlay( "hail", pos ) – Plays the hail sound at position pos Lua usage parameter: audio.soundPlay( "hail", pos, vel ) – Plays the hail sound at position pos with velocity vel

Lua function parameter: string s Name of the sound to play Lua function parameter:[opt] Vec2 pos Position of the source Lua function parameter:[opt] Vec2 vel Velocity of the source

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: soundPlay

Definition at line 1292 of file nlua_audio.c.

◆ audioL_stop()

int audioL_stop ( lua_State * L)
static

Stops a source.

Lua function parameter: Audio source Source to stop.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: stop

Definition at line 748 of file nlua_audio.c.

◆ audioL_tell()

int audioL_tell ( lua_State * L)
static

Gets the position of a source.

Lua function parameter: Audio source Source to get position of. Lua function parameter:[opt="seconds"] string unit Either "seconds" or "samples" indicating the type to report. Lua return parameter: number Offset of the source or -1 on error.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: tell

Definition at line 899 of file nlua_audio.c.

◆ audioL_tostring()

int audioL_tostring ( lua_State * L)
static

Lua bindings to interact with audio.

Lua module: audio

Gets a string representation of an audio file.

Lua function parameter: Audio audio Audio to get string representation of. Lua return parameter: string String representation of the audio.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __tostring

Definition at line 404 of file nlua_audio.c.

◆ efx_setbool()

void efx_setbool ( lua_State * L,
int pos,
ALuint effect,
const char * name,
ALuint param )
static

Definition at line 1428 of file nlua_audio.c.

◆ efx_setint()

void efx_setint ( lua_State * L,
int pos,
ALuint effect,
const char * name,
ALuint param )
static

Definition at line 1420 of file nlua_audio.c.

◆ efx_setnum()

void efx_setnum ( lua_State * L,
int pos,
ALuint effect,
const char * name,
ALuint param )
static

Definition at line 1412 of file nlua_audio.c.

◆ lua_isaudio()

int lua_isaudio ( lua_State * L,
int ind )

Checks to see if ind is a audio.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a audio.

Definition at line 325 of file nlua_audio.c.

◆ lua_pushaudio()

LuaAudio_t * lua_pushaudio ( lua_State * L,
LuaAudio_t audio )

Pushes a audio on the stack.

Parameters
LLua state to push audio into.
audioAudio to push.
Returns
Newly pushed audio.

Definition at line 310 of file nlua_audio.c.

◆ lua_toaudio()

LuaAudio_t * lua_toaudio ( lua_State * L,
int ind )

Gets audio at index.

Parameters
LLua state to get audio from.
indIndex position to find the audio.
Returns
Audio found at the index in the state.

Definition at line 285 of file nlua_audio.c.

◆ luaL_checkaudio()

LuaAudio_t * luaL_checkaudio ( lua_State * L,
int ind )

Gets audio at index or raises error if there is no audio at index.

Parameters
LLua state to get audio from.
indIndex position to find audio.
Returns
Audio found at the index in the state.

Definition at line 296 of file nlua_audio.c.

◆ nlua_loadAudio()

int nlua_loadAudio ( nlua_env env)

Loads the audio library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 272 of file nlua_audio.c.

◆ stream_loadBuffer()

int stream_loadBuffer ( LuaAudio_t * la,
ALuint buffer )
static

Loads a buffer.

Assumes that soundLock() is set.

Definition at line 174 of file nlua_audio.c.

◆ stream_thread()

int stream_thread ( void * la_data)
static

Definition at line 122 of file nlua_audio.c.

Variable Documentation

◆ audioL_methods

const luaL_Reg audioL_methods[]
static

AudioLua methods.

Definition at line 84 of file nlua_audio.c.

◆ lua_efx

LuaAudioEfx_t* lua_efx = NULL
static

List of effects handled by Lua. These are persistent throughout game runtime.

Definition at line 41 of file nlua_audio.c.