naev 0.11.5
nlua_audio.c File Reference

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

#include "nlua_audio.h"
#include "AL/efx.h"
#include "AL/efx-presets.h"
#include "conf.h"
#include "array.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "nlua_file.h"
#include "nstring.h"
#include "sound.h"
#include "nopenal.h"

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

Macros

#define RG_PREAMP_DB   0.0
 Default pre-amp in dB.
 

Functions

static int stream_thread (void *la_data)
 
static int stream_loadBuffer (LuaAudio_t *la, ALuint buffer)
 Loads a buffer.
 
static void rg_filter (float **pcm, long channels, long samples, void *filter_param)
 This is the filter function for the decoded Ogg Vorbis stream.
 
static int audio_genSource (ALuint *source)
 Tries to generate a single openal source, running GC if necessary.
 
static int audioL_gc (lua_State *L)
 Lua bindings to interact with 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.

Macro Definition Documentation

◆ RG_PREAMP_DB

#define RG_PREAMP_DB   0.0

Default pre-amp in dB.

Definition at line 33 of file nlua_audio.c.

Function Documentation

◆ audio_cleanup()

void audio_cleanup ( LuaAudio_t * la)

Definition at line 380 of file nlua_audio.c.

◆ audio_clone()

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

Definition at line 637 of file nlua_audio.c.

◆ audio_genSource()

static int audio_genSource ( ALuint * source)
static

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

Definition at line 472 of file nlua_audio.c.

◆ audio_getEffectByName()

static LuaAudioEfx_t * audio_getEffectByName ( const char * name)
static

Definition at line 1613 of file nlua_audio.c.

◆ audioL_clone()

static 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 693 of file nlua_audio.c.

◆ audioL_eq()

static 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 460 of file nlua_audio.c.

◆ audioL_gc()

static int audioL_gc ( lua_State * L)
static

Lua bindings to interact with audio.

Lua module: audio

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 445 of file nlua_audio.c.

◆ audioL_getAttenuationDistances()

static 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 1368 of file nlua_audio.c.

◆ audioL_getDuration()

static 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 980 of file nlua_audio.c.

◆ audioL_getPitch()

static 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 1280 of file nlua_audio.c.

◆ audioL_getPosition()

static 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 1141 of file nlua_audio.c.

◆ audioL_getRolloff()

static 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 1412 of file nlua_audio.c.

◆ audioL_getVelocity()

static 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 1199 of file nlua_audio.c.

◆ audioL_getVolume()

static 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 1073 of file nlua_audio.c.

◆ audioL_isBool()

static int audioL_isBool ( lua_State * L,
ALenum param )
static

Checks to see a boolean property of a source.

Definition at line 274 of file nlua_audio.c.

◆ audioL_isLooping()

static 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 1248 of file nlua_audio.c.

◆ audioL_isPaused()

static 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 767 of file nlua_audio.c.

◆ audioL_isState()

static int audioL_isState ( lua_State * L,
ALenum state )
static

Checks to see the state of the source.

Definition at line 291 of file nlua_audio.c.

◆ audioL_isStopped()

static 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 832 of file nlua_audio.c.

◆ audioL_new()

static 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 511 of file nlua_audio.c.

◆ audioL_pause()

static 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 748 of file nlua_audio.c.

◆ audioL_play()

static 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 709 of file nlua_audio.c.

◆ audioL_rewind()

static 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 843 of file nlua_audio.c.

◆ audioL_seek()

static 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 875 of file nlua_audio.c.

◆ audioL_setAttenuationDistances()

static 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 1346 of file nlua_audio.c.

◆ audioL_setEffect()

static 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 1633 of file nlua_audio.c.

◆ audioL_setEffectGlobal()

static int audioL_setEffectGlobal ( lua_State * L)
static

Definition at line 1446 of file nlua_audio.c.

◆ audioL_setGlobaDopplerFactor()

static 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 1739 of file nlua_audio.c.

◆ audioL_setGlobalAirAbsorption()

static 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 1714 of file nlua_audio.c.

◆ audioL_setGlobalEffect()

static 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 1674 of file nlua_audio.c.

◆ audioL_setLooping()

static 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 1228 of file nlua_audio.c.

◆ audioL_setPitch()

static 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 1260 of file nlua_audio.c.

◆ audioL_setPosition()

static 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 1114 of file nlua_audio.c.

◆ audioL_setRelative()

static 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 1092 of file nlua_audio.c.

◆ audioL_setRolloff()

static 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 1393 of file nlua_audio.c.

◆ audioL_setVelocity()

static 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 1172 of file nlua_audio.c.

◆ audioL_setVolume()

static 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 1045 of file nlua_audio.c.

◆ audioL_soundPlay()

static 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 1308 of file nlua_audio.c.

◆ audioL_stop()

static 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 778 of file nlua_audio.c.

◆ audioL_tell()

static 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 925 of file nlua_audio.c.

◆ efx_setbool()

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

Definition at line 1440 of file nlua_audio.c.

◆ efx_setint()

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

Definition at line 1434 of file nlua_audio.c.

◆ efx_setnum()

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

Definition at line 1428 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 364 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 349 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 324 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 335 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 311 of file nlua_audio.c.

◆ rg_filter()

static void rg_filter ( float ** pcm,
long channels,
long samples,
void * filter_param )
static

This is the filter function for the decoded Ogg Vorbis stream.

base on: vgfilter.c (c) 2007,2008 William Poetra Yoga Hadisoeseno based on: vgplay.c 1.0 (c) 2003 John Morton

Definition at line 242 of file nlua_audio.c.

◆ stream_loadBuffer()

static int stream_loadBuffer ( LuaAudio_t * la,
ALuint buffer )
static

Loads a buffer.

Assumes that soundLock() is set.

Definition at line 179 of file nlua_audio.c.

◆ stream_thread()

static int stream_thread ( void * la_data)
static

Definition at line 127 of file nlua_audio.c.

Variable Documentation

◆ audioL_methods

const luaL_Reg audioL_methods[]
static

AudioLua methods.

Definition at line 89 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 47 of file nlua_audio.c.