11#include "physfsrwops.h"
16#include "nlua_audio.h"
19#include "AL/efx-presets.h"
33#define RG_PREAMP_DB 0.0
38typedef struct LuaAudioEfx_s {
49static int stream_thread(
void *la_data );
51static void rg_filter(
float **pcm,
long channels,
long samples,
void *filter_param );
127static int stream_thread(
void *la_data )
140 SDL_CondBroadcast( la->
cond );
141 alSourceStop( la->
source );
146 alGetSourcei( la->
source, AL_BUFFERS_PROCESSED, &alstate );
150 alSourceUnqueueBuffers( la->
source, 1, &removed );
152 if ((la->
active < 0) || (ret < 0)) {
157 SDL_CondBroadcast( la->
cond );
158 alSourceStop( la->
source );
183 char buf[ 32 * 1024 ];
188 while (size <
sizeof(buf)) {
191 SDL_mutexP( la->
lock );
192 result = ov_read_filter(
196 (SDL_BYTEORDER == SDL_BIG_ENDIAN),
202 SDL_mutexV( la->
lock );
213 else if (result == OV_HOLE) {
214 WARN(_(
"OGG: Vorbis hole detected in music!"));
218 else if (result == OV_EBADLINK) {
219 WARN(_(
"OGG: Invalid stream section or corrupt link in music!"));
228 alBufferData( buffer, la->
format, buf, size, la->
info->rate );
242static void rg_filter(
float **pcm,
long channels,
long samples,
void *filter_param )
246 float max_scale = param->rg_max_scale;
249 if (scale_factor > max_scale) {
250 for (
int i=0; i < channels; i++)
251 for (
int j=0; j < samples; j++) {
252 float cur_sample = pcm[i][j] * scale_factor;
258 if (cur_sample < -0.5)
259 cur_sample = tanh((cur_sample + 0.5) / (1-0.5)) * (1-0.5) - 0.5;
260 else if (cur_sample > 0.5)
261 cur_sample = tanh((cur_sample - 0.5) / (1-0.5)) * (1-0.5) + 0.5;
262 pcm[i][j] = cur_sample;
265 else if (scale_factor > 0.0)
266 for (
int i=0; i < channels; i++)
267 for (
int j=0; j < samples; j++)
268 pcm[i][j] *= scale_factor;
280 alGetSourcei( la->
source, param, &b );
284 lua_pushboolean(L,b);
297 alGetSourcei( la->
source, AL_SOURCE_STATE, &s );
301 lua_pushboolean(L, s==state );
339 luaL_typerror(L, ind, AUDIO_METATABLE);
353 luaL_getmetatable(L, AUDIO_METATABLE);
354 lua_setmetatable(L, -2);
368 if (lua_getmetatable(L,ind)==0)
370 lua_getfield(L, LUA_REGISTRYINDEX, AUDIO_METATABLE);
373 if (lua_rawequal(L, -1, -2))
388 case LUA_AUDIO_STATIC:
390 if (alIsSource( la->
source )==AL_TRUE)
391 alDeleteSources( 1, &la->
source );
393 if (la->
buf != NULL) {
404 case LUA_AUDIO_STREAM:
406 if (la->
th != NULL) {
408 if (SDL_CondWaitTimeout( la->
cond,
sound_lock, 3000 ) == SDL_MUTEX_TIMEDOUT)
410 WARN(_(
"Timed out while waiting for audio thread of '%s' to finish!"), la->name);
412 WARN(_(
"Timed out while waiting for audio thread to finish!"));
415 if (alIsSource( la->
source )==AL_TRUE)
416 alDeleteSources( 1, &la->
source );
419 if (la->
cond != NULL)
420 SDL_DestroyCond( la->
cond );
421 if (la->
lock != NULL)
422 SDL_DestroyMutex( la->
lock );
465 lua_pushboolean( L, (memcmp( a1, a2,
sizeof(
LuaAudio_t) )==0) );
475 alGenSources( 1, source );
476 if (alIsSource( *source)==AL_TRUE)
482 case AL_OUT_OF_MEMORY:
485 lua_gc( naevL, LUA_GCCOLLECT, 0 );
488 alGenSources( 1, source );
494 al_checkHandleError( err, __func__, __LINE__ );
519 if (lua_isstring(L,1))
520 name = lua_tostring(L,1);
526 NLUA_INVALID_PARAMETER(L);
529 if (lua_isnoneornil(L,2)) {
533 const char *type = luaL_optstring(L,2,
"static");
534 if (strcmp(type,
"static")==0)
536 else if (strcmp(type,
"stream")==0)
539 NLUA_INVALID_PARAMETER(L);
548 rw = PHYSFSRWOPS_openRead( name );
550 NLUA_ERROR(L,
"Unable to open '%s'", name );
552 la.name = strdup( name );
560 la.
type = LUA_AUDIO_STATIC;
573 ALfloat track_gain_db, track_peak;
576 la.
type = LUA_AUDIO_STREAM;
580 NLUA_ERROR(L,_(
"Audio '%s' does not appear to be a Vorbis bitstream."), name );
585 vc = ov_comment( &la.
stream, -1 );
588 if ((tag = vorbis_comment_query(vc,
"replaygain_track_gain", 0)))
589 track_gain_db = atof(tag);
590 if ((tag = vorbis_comment_query(vc,
"replaygain_track_peak", 0)))
591 track_peak = atof(tag);
596 if (la.
info->channels == 1)
597 la.
format = AL_FORMAT_MONO16;
599 la.
format = AL_FORMAT_STEREO16;
602 la.
lock = SDL_CreateMutex();
603 la.
cond = SDL_CreateCond();
611 alSourcef( la.
source, AL_GAIN, master );
620 alSourcei( la.
source, AL_SOURCE_RELATIVE, AL_TRUE );
621 alSource3f( la.
source, AL_POSITION, 0., 0., 0. );
642 switch (source->type) {
643 case LUA_AUDIO_STATIC:
645 la->
buf = source->buf;
652 case LUA_AUDIO_STREAM:
653 WARN(_(
"Unimplemented"));
659 la->
type = source->type;
665 alSourcef( la->
source, AL_GAIN, master );
668 alSourcei( la->
source, AL_SOURCE_RELATIVE, AL_TRUE );
669 alSource3f( la->
source, AL_POSITION, 0., 0., 0. );
686 audio_clone( &la, source );
705 if ((la->
type == LUA_AUDIO_STREAM) && (la->
th == NULL)) {
709 alGetSourcei( la->
source, AL_BUFFERS_QUEUED, &alstate );
710 while (alstate < 2) {
716 alGetSourcei( la->
source, AL_BUFFERS_QUEUED, &alstate );
719 la->
th = SDL_CreateThread( stream_thread,
"stream_thread", la );
723 alSourcePlay( la->
source );
727 lua_pushboolean(L,1);
744 alSourcePause( la->
source );
780 case LUA_AUDIO_STATIC:
781 alSourceStop( la->
source );
784 case LUA_AUDIO_STREAM:
786 if (la->
th != NULL) {
788 if (SDL_CondWaitTimeout( la->
cond,
sound_lock, 3000 ) == SDL_MUTEX_TIMEDOUT)
790 WARN(_(
"Timed out while waiting for audio thread of '%s' to finish!"), la->name);
792 WARN(_(
"Timed out while waiting for audio thread to finish!"));
798 alSourceStop( la->
source );
801 alGetSourcei( la->
source, AL_BUFFERS_PROCESSED, &alstate );
802 alSourceUnqueueBuffers( la->
source, alstate, removed );
805 SDL_mutexP( la->
lock );
806 ov_pcm_seek( &la->
stream, 0 );
807 SDL_mutexV( la->
lock );
840 case LUA_AUDIO_STATIC:
842 alSourceRewind( la->
source );
846 case LUA_AUDIO_STREAM:
847 SDL_mutexP( la->
lock );
848 ov_raw_seek( &la->
stream, 0 );
849 SDL_mutexV( la->
lock );
868 double offset = luaL_checknumber(L,2);
869 const char *unit = luaL_optstring(L,3,
"seconds");
872 if (strcmp(unit,
"samples")==0)
874 else if (strcmp(unit,
"seconds")!=0)
875 NLUA_ERROR(L, _(
"Unknown seek source '%s'! Should be either 'seconds' or 'samples'!"), unit );
881 case LUA_AUDIO_STATIC:
884 alSourcef( la->
source, AL_SEC_OFFSET, offset );
886 alSourcef( la->
source, AL_SAMPLE_OFFSET, offset );
891 case LUA_AUDIO_STREAM:
892 SDL_mutexP( la->
lock );
894 ov_time_seek( &la->
stream, offset );
896 ov_pcm_seek( &la->
stream, offset );
897 SDL_mutexV( la->
lock );
918 const char *unit = luaL_optstring(L,2,
"seconds");
923 if (strcmp(unit,
"samples")==0)
925 else if (strcmp(unit,
"seconds")!=0)
926 NLUA_ERROR(L, _(
"Unknown seek source '%s'! Should be either 'seconds' or 'samples'!"), unit );
929 lua_pushnumber(L, -1.);
934 case LUA_AUDIO_STATIC:
937 alGetSourcef( la->
source, AL_SEC_OFFSET, &aloffset );
939 alGetSourcef( la->
source, AL_SAMPLE_OFFSET, &aloffset );
945 case LUA_AUDIO_STREAM:
946 SDL_mutexP( la->
lock );
948 offset = ov_time_tell( &la->
stream );
950 offset = ov_pcm_tell( &la->
stream );
951 SDL_mutexV( la->
lock );
958 lua_pushnumber(L, offset);
973 const char *unit = luaL_optstring(L,2,
"seconds");
974 float duration = -1.;
976 ALint bytes, channels, bits, samples;
979 if (strcmp(unit,
"samples")==0)
981 else if (strcmp(unit,
"seconds")!=0)
982 NLUA_ERROR(L, _(
"Unknown duration source '%s'! Should be either 'seconds' or 'samples'!"), unit );
985 lua_pushnumber(L, -1.);
990 case LUA_AUDIO_STATIC:
993 alGetBufferi( buffer, AL_SIZE, &bytes );
994 alGetBufferi( buffer, AL_CHANNELS, &channels );
995 alGetBufferi( buffer, AL_BITS, &bits );
997 samples = bytes * 8 / (channels * bits);
1001 alGetBufferi( buffer, AL_FREQUENCY, &freq );
1002 duration = (float) samples / (
float) freq;
1010 case LUA_AUDIO_STREAM:
1011 SDL_mutexP( la->
lock );
1013 duration = ov_time_total( &la->
stream, -1 );
1015 duration = ov_pcm_total( &la->
stream, -1 );
1016 SDL_mutexV( la->
lock );
1019 case LUA_AUDIO_NULL:
1023 lua_pushnumber(L, duration);
1038 double volume =
CLAMP( 0.0, 1.0, luaL_checknumber(L,2) );
1039 int ignorevol = lua_toboolean(L,3);
1045 alSourcef( la->
source, AL_GAIN, volume );
1048 alSourcef( la->
source, AL_GAIN, master * volume );
1068 else if (lua_gettop(L) > 0)
1072 lua_pushnumber(L, volume);
1089 alSourcei( la->
source, AL_SOURCE_RELATIVE, lua_toboolean(L,2) );
1111 pos[0] = luaL_optnumber(L,2,0.);
1112 pos[1] = luaL_optnumber(L,3,0.);
1113 pos[2] = luaL_optnumber(L,4,0.);
1116 alSourcefv( la->
source, AL_POSITION, pos );
1136 lua_pushnumber(L,0.);
1137 lua_pushnumber(L,0.);
1138 lua_pushnumber(L,0.);
1143 alGetSource3f( la->
source, AL_POSITION, &pos[0], &pos[1], &pos[2] );
1147 lua_pushnumber(L,pos[0]);
1148 lua_pushnumber(L,pos[1]);
1149 lua_pushnumber(L,pos[2]);
1169 vel[0] = luaL_optnumber(L,2,0.);
1170 vel[1] = luaL_optnumber(L,3,0.);
1171 vel[2] = luaL_optnumber(L,4,0.);
1174 alSourcefv( la->
source, AL_VELOCITY, vel );
1194 lua_pushnumber(L,0.);
1195 lua_pushnumber(L,0.);
1196 lua_pushnumber(L,0.);
1201 alGetSource3f( la->
source, AL_VELOCITY, &vel[0], &vel[1], &vel[2] );
1205 lua_pushnumber(L,vel[0]);
1206 lua_pushnumber(L,vel[1]);
1207 lua_pushnumber(L,vel[2]);
1221 int b = lua_toboolean(L,2);
1225 alSourcei( la->
source, AL_LOOPING, b );
1253 double pitch = luaL_checknumber(L,2);
1257 alSourcef( la->
source, AL_PITCH, pitch );
1276 alGetSourcef( la->
source, AL_PITCH, &p );
1280 lua_pushnumber(L,p);
1301 vec2 *pos, *vel, vel0;
1308 name = luaL_checkstring(L,1);
1309 if (lua_gettop(L) > 1) {
1312 if (lua_gettop(L) > 2) {
1339 double ref = luaL_checknumber(L,2);
1340 double max = luaL_checknumber(L,3);
1344 alSourcef( la->
source, AL_REFERENCE_DISTANCE, ref );
1345 alSourcef( la->
source, AL_MAX_DISTANCE, max );
1363 lua_pushnumber(L,0.);
1364 lua_pushnumber(L,0.);
1368 alGetSourcef( la->
source, AL_REFERENCE_DISTANCE, &ref );
1369 alGetSourcef( la->
source, AL_MAX_DISTANCE, &max );
1372 lua_pushnumber( L, ref );
1373 lua_pushnumber( L, max );
1386 double rolloff = luaL_checknumber(L,2);
1390 alSourcef( la->
source, AL_ROLLOFF_FACTOR, rolloff );
1407 lua_pushnumber(L,0.);
1411 alGetSourcef( la->
source, AL_ROLLOFF_FACTOR, &rolloff);
1414 lua_pushnumber( L, rolloff );
1418static void efx_setnum( lua_State *L,
int pos, ALuint effect,
const char *name, ALuint param ) {
1419 lua_getfield(L,pos,name);
1420 if (!lua_isnil(L,-1))
1421 nalEffectf( effect, param, luaL_checknumber(L,-1) );
1424static void efx_setint( lua_State *L,
int pos, ALuint effect,
const char *name, ALuint param ) {
1425 lua_getfield(L,pos,name);
1426 if (!lua_isnil(L,-1))
1427 nalEffecti( effect, param, luaL_checkinteger(L,-1) );
1430static void efx_setbool( lua_State *L,
int pos, ALuint effect,
const char *name, ALuint param ) {
1431 lua_getfield(L,pos,name);
1432 if (!lua_isnil(L,-1))
1433 nalEffecti( effect, param, lua_toboolean(L,-1) ? AL_TRUE : AL_FALSE );
1436static int audioL_setEffectGlobal( lua_State *L )
1438 const char *name = luaL_checkstring(L,1);
1439 ALuint effect, slot;
1446 lua_getfield(L,p,
"type");
1447 type = luaL_checkstring(L,-1);
1451 lua_getfield(L,p,
"volume");
1452 if (lua_isnil(L,-1))
1455 volume = luaL_checknumber(L,-1);
1465 if (strcmp(name,
lua_efx[i].name)==0) {
1472 nalGenEffects(1, &effect);
1473 nalGenAuxiliaryEffectSlots( 1, &slot );
1474 lae->
name = strdup( name );
1484 if (strcmp(type,
"reverb")==0) {
1485 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);
1487 efx_setnum( L, p, effect,
"density", AL_REVERB_DENSITY );
1488 efx_setnum( L, p, effect,
"diffusion", AL_REVERB_DIFFUSION );
1489 efx_setnum( L, p, effect,
"gain", AL_REVERB_GAIN );
1490 efx_setnum( L, p, effect,
"highgain", AL_REVERB_GAINHF );
1491 efx_setnum( L, p, effect,
"decaytime", AL_REVERB_DECAY_TIME );
1492 efx_setnum( L, p, effect,
"decayhighratio", AL_REVERB_DECAY_HFRATIO );
1493 efx_setnum( L, p, effect,
"earlygain", AL_REVERB_REFLECTIONS_GAIN );
1494 efx_setnum( L, p, effect,
"earlydelay", AL_REVERB_REFLECTIONS_DELAY );
1495 efx_setnum( L, p, effect,
"lategain", AL_REVERB_LATE_REVERB_GAIN );
1496 efx_setnum( L, p, effect,
"latedelay", AL_REVERB_LATE_REVERB_DELAY );
1497 efx_setnum( L, p, effect,
"roomrolloff", AL_REVERB_ROOM_ROLLOFF_FACTOR );
1498 efx_setnum( L, p, effect,
"airabsorption", AL_REVERB_AIR_ABSORPTION_GAINHF );
1499 efx_setbool( L, p, effect,
"highlimit", AL_REVERB_DECAY_HFLIMIT );
1501 else if (strcmp(type,
"distortion")==0) {
1502 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_DISTORTION);
1504 efx_setnum( L, p, effect,
"gain", AL_DISTORTION_GAIN );
1505 efx_setnum( L, p, effect,
"edge", AL_DISTORTION_EDGE );
1506 efx_setnum( L, p, effect,
"lowcut", AL_DISTORTION_LOWPASS_CUTOFF );
1507 efx_setnum( L, p, effect,
"center", AL_DISTORTION_EQCENTER );
1508 efx_setnum( L, p, effect,
"bandwidth", AL_DISTORTION_EQBANDWIDTH );
1510 else if (strcmp(type,
"chorus")==0) {
1511 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_CHORUS);
1513 efx_setint( L, p, effect,
"waveform", AL_CHORUS_WAVEFORM );
1514 efx_setint( L, p, effect,
"phase", AL_CHORUS_PHASE );
1515 efx_setnum( L, p, effect,
"rate", AL_CHORUS_RATE );
1516 efx_setnum( L, p, effect,
"depth", AL_CHORUS_DEPTH );
1517 efx_setnum( L, p, effect,
"feedback", AL_CHORUS_FEEDBACK );
1518 efx_setnum( L, p, effect,
"delay", AL_CHORUS_DELAY );
1520 else if (strcmp(type,
"compressor")==0) {
1521 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_COMPRESSOR);
1523 efx_setbool( L, p, effect,
"enable", AL_COMPRESSOR_ONOFF );
1525 else if (strcmp(type,
"echo")==0) {
1526 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_ECHO);
1528 efx_setnum( L, p, effect,
"delay", AL_ECHO_DELAY );
1529 efx_setnum( L, p, effect,
"tapdelay", AL_ECHO_LRDELAY );
1530 efx_setnum( L, p, effect,
"damping", AL_ECHO_DAMPING );
1531 efx_setnum( L, p, effect,
"feedback", AL_ECHO_FEEDBACK );
1532 efx_setnum( L, p, effect,
"spread", AL_ECHO_SPREAD );
1534 else if (strcmp(type,
"ringmodulator")==0) {
1535 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_RING_MODULATOR);
1537 efx_setnum( L, p, effect,
"frequency", AL_RING_MODULATOR_FREQUENCY );
1538 efx_setnum( L, p, effect,
"highcut", AL_RING_MODULATOR_HIGHPASS_CUTOFF );
1539 efx_setint( L, p, effect,
"waveform", AL_RING_MODULATOR_WAVEFORM );
1541 else if (strcmp(type,
"equalizer")==0) {
1542 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_EQUALIZER);
1544 efx_setnum( L, p, effect,
"lowgain", AL_EQUALIZER_LOW_GAIN );
1545 efx_setnum( L, p, effect,
"lowcut", AL_EQUALIZER_LOW_CUTOFF );
1546 efx_setnum( L, p, effect,
"lowmidgain", AL_EQUALIZER_MID1_GAIN );
1547 efx_setnum( L, p, effect,
"lowmidfrequency", AL_EQUALIZER_MID1_CENTER );
1548 efx_setnum( L, p, effect,
"lowmidbandwidth", AL_EQUALIZER_MID1_WIDTH );
1549 efx_setnum( L, p, effect,
"highmidgain", AL_EQUALIZER_MID2_GAIN );
1550 efx_setnum( L, p, effect,
"highmidfrequency", AL_EQUALIZER_MID2_CENTER );
1551 efx_setnum( L, p, effect,
"highmidbandwidth", AL_EQUALIZER_MID2_WIDTH );
1552 efx_setnum( L, p, effect,
"highgain", AL_EQUALIZER_HIGH_GAIN );
1553 efx_setnum( L, p, effect,
"highcut", AL_EQUALIZER_HIGH_CUTOFF );
1555 else if (strcmp(type,
"pitchshifter")==0) {
1556 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_PITCH_SHIFTER);
1558 efx_setint( L, p, effect,
"tunecoarse", AL_PITCH_SHIFTER_COARSE_TUNE );
1559 efx_setint( L, p, effect,
"tunefine'", AL_PITCH_SHIFTER_FINE_TUNE );
1561 else if (strcmp(type,
"vocalmorpher")==0) {
1562 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_VOCAL_MORPHER);
1564 efx_setint( L, p, effect,
"phonemea", AL_VOCAL_MORPHER_PHONEMEA );
1565 efx_setint( L, p, effect,
"phonemeb", AL_VOCAL_MORPHER_PHONEMEB );
1566 efx_setint( L, p, effect,
"tunecoarsea", AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING );
1567 efx_setint( L, p, effect,
"tunecoarseb", AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING );
1568 efx_setint( L, p, effect,
"waveform", AL_VOCAL_MORPHER_WAVEFORM );
1569 efx_setnum( L, p, effect,
"rate", AL_VOCAL_MORPHER_RATE );
1571 else if (strcmp(type,
"flanger")==0) {
1572 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_FLANGER);
1574 efx_setint( L, p, effect,
"waveform", AL_FLANGER_WAVEFORM );
1575 efx_setnum( L, p, effect,
"phase", AL_FLANGER_PHASE );
1576 efx_setnum( L, p, effect,
"rate", AL_FLANGER_RATE );
1577 efx_setnum( L, p, effect,
"depth", AL_FLANGER_DEPTH );
1578 efx_setnum( L, p, effect,
"feedback", AL_FLANGER_FEEDBACK );
1579 efx_setnum( L, p, effect,
"delay", AL_FLANGER_DELAY );
1581 else if (strcmp(type,
"frequencyshifter")==0) {
1582 nalEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_FREQUENCY_SHIFTER);
1584 efx_setnum( L, p, effect,
"frequency", AL_FREQUENCY_SHIFTER_FREQUENCY );
1585 efx_setint( L, p, effect,
"leftdirection", AL_FREQUENCY_SHIFTER_LEFT_DIRECTION );
1586 efx_setint( L, p, effect,
"rightdirection", AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION );
1590 NLUA_ERROR(L, _(
"Usupported audio effect type '%s'!"), type);
1594 nalAuxiliaryEffectSlotf( slot, AL_EFFECTSLOT_GAIN, volume );
1595 nalAuxiliaryEffectSloti( slot, AL_EFFECTSLOT_EFFECT, effect );
1603static LuaAudioEfx_t *audio_getEffectByName(
const char *name )
1606 if (strcmp(name,
lua_efx[i].name)==0)
1608 WARN(_(
"Unknown audio effect '%s'!"), name);
1626 lua_pushboolean(L,1);
1632 return audioL_setEffectGlobal(L);
1635 const char *name = luaL_checkstring(L,2);
1636 int enable = (lua_isnoneornil(L,3)) ? 1 : lua_toboolean(L,3);
1646 alSource3i( la->
source, AL_AUXILIARY_SEND_FILTER, lae->
slot, 0, AL_FILTER_NULL );
1649 alSource3i( la->
source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL );
1654 lua_pushboolean(L,1);
1667 const char *name = luaL_optstring(L,1,NULL);
1685 lae = audio_getEffectByName( name );
1706 double speed = luaL_optnumber( L, 1, 3433. );
1707 double absorption = luaL_optnumber( L, 2, -1. );
1713 alSpeedOfSound( speed );
1714 if (absorption > 0.)
1715 sound_setAbsorption( absorption );
1735 alDopplerFactor( luaL_checknumber(L,1) );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Header file with generic functions and naev-specifics.
static int audioL_soundPlay(lua_State *L)
Plays a sound.
static int audioL_clone(lua_State *L)
Clones an existing audio source.
static int audioL_setGlobaDopplerFactor(lua_State *L)
Sets the doppler effect factor.
static int audioL_setRelative(lua_State *L)
Sets whether a source is relative or not.
static const luaL_Reg audioL_methods[]
static int audioL_pause(lua_State *L)
Pauses a source.
static int audioL_setEffect(lua_State *L)
Sets effect stuff, behaves different if the first parameter is a source or not.
static int audio_genSource(ALuint *source)
Tries to generate a single openal source, running GC if necessary.
static int audioL_setGlobalAirAbsorption(lua_State *L)
Allows setting the speed of sound and air absorption.
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_isLooping(lua_State *L)
Gets the looping state of a source.
LuaAudio_t * lua_toaudio(lua_State *L, int ind)
Gets audio at index.
static int audioL_seek(lua_State *L)
Seeks a source.
LuaAudio_t * lua_pushaudio(lua_State *L, LuaAudio_t audio)
Pushes a audio on the stack.
static int audioL_getVelocity(lua_State *L)
Gets the velocity of a source.
static int audioL_setVolume(lua_State *L)
Sets the volume of a source.
static int audioL_getRolloff(lua_State *L)
Gets the rolloff factor.
static int audioL_rewind(lua_State *L)
Rewinds a source.
static int audioL_play(lua_State *L)
Plays a source.
static int audioL_setRolloff(lua_State *L)
Sets the rollof factor.
static int audioL_setLooping(lua_State *L)
Sets a source to be looping or not.
static int audioL_setPosition(lua_State *L)
Sets the position of a source.
static int audioL_isState(lua_State *L, ALenum state)
Checks to see the state of the source.
static int stream_loadBuffer(LuaAudio_t *la, ALuint buffer)
Loads a buffer.
int lua_isaudio(lua_State *L, int ind)
Checks to see if ind is a audio.
static int audioL_getDuration(lua_State *L)
Gets the length of a source.
static LuaAudioEfx_t * lua_efx
List of effects handled by Lua. These are persistent throughout game runtime.
static int audioL_isPaused(lua_State *L)
Checks to see if a source is paused.
#define RG_PREAMP_DB
Default pre-amp in dB.
LuaAudio_t * luaL_checkaudio(lua_State *L, int ind)
Gets audio at index or raises error if there is no audio at index.
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 audioL_getAttenuationDistances(lua_State *L)
Gets the attenuation distances for the audio source. Set to 0. if audio is disabled.
static int audioL_tell(lua_State *L)
Gets the position of a source.
static int audioL_setPitch(lua_State *L)
Sets the pitch of a source.
static int audioL_getVolume(lua_State *L)
Gets the volume of a source.
static int audioL_new(lua_State *L)
Creates a new audio source.
static int audioL_getPosition(lua_State *L)
Gets the position of a source.
static int audioL_isStopped(lua_State *L)
Checks to see if a source is stopped.
static int audioL_getPitch(lua_State *L)
Gets the pitch of a source.
static int audioL_gc(lua_State *L)
Lua bindings to interact with audio.
static int audioL_setAttenuationDistances(lua_State *L)
Sets the attenuation distances for the audio source.
static int audioL_setVelocity(lua_State *L)
Sets the velocity of a source.
int nlua_loadAudio(nlua_env env)
Loads the audio library.
static int audioL_stop(lua_State *L)
Stops a source.
static int audioL_isBool(lua_State *L, ALenum param)
Checks to see a boolean property of a source.
static int audioL_eq(lua_State *L)
Compares two audios to see if they are the same.
LuaFile_t * lua_tofile(lua_State *L, int ind)
Lua bindings to interact with files.
int lua_isfile(lua_State *L, int ind)
Checks to see if ind is a file.
vec2 * luaL_checkvector(lua_State *L, int ind)
Gets vector at index making sure type is valid.
double sound_getVolumeLog(void)
Gets the current sound volume (logarithmic).
int sound_al_buffer(ALuint *buf, SDL_RWops *rw, const char *name)
Loads the sound.
double sound_getVolume(void)
Gets the current sound volume (linear).
int sound_playPos(int sound, double px, double py, double vx, double vy)
Plays a sound based on position.
int sound_get(const char *name)
Gets the buffer to sound of name.
ALuint sound_efx_directSlot
ov_callbacks sound_al_ovcall
int sound_play(int sound)
Plays the sound in the first available channel.
Handles the OpenAL effects that have been set up Lua side.