10#include "physfsrwops.h"
16#include "nlua_audio.h"
31typedef struct LuaAudioEfx_s {
43static int stream_thread(
void *la_data );
122static int stream_thread(
void *la_data )
135 SDL_CondBroadcast( la->
cond );
136 alSourceStop( la->
source );
141 alGetSourcei( la->
source, AL_BUFFERS_PROCESSED, &alstate );
145 alSourceUnqueueBuffers( la->
source, 1, &removed );
147 if ( ( la->
active < 0 ) || ( ret < 0 ) ) {
152 SDL_CondBroadcast( la->
cond );
153 alSourceStop( la->
source );
157 alSourceQueueBuffers( la->
source, 1,
183 while ( size <
sizeof( buf ) ) {
190 SDL_mutexP( la->
lock );
192 ov_read_filter( &la->
stream,
194 sizeof( buf ) - size,
195 ( SDL_BYTEORDER == SDL_BIG_ENDIAN ), 2,
200 SDL_mutexV( la->
lock );
211 else if ( result == OV_HOLE ) {
212 WARN( _(
"OGG: Vorbis hole detected in music!" ) );
216 else if ( result == OV_EBADLINK ) {
217 WARN( _(
"OGG: Invalid stream section or corrupt link in music!" ) );
226 alBufferData( buffer, la->
format, buf, size, la->
info->rate );
241 alGetSourcei( la->
source, param, &b );
245 lua_pushboolean( L, b );
258 alGetSourcei( la->
source, AL_SOURCE_STATE, &s );
262 lua_pushboolean( L, s == state );
287 return (
LuaAudio_t *)lua_touserdata( L, ind );
300 luaL_typerror( L, ind, AUDIO_METATABLE );
314 luaL_getmetatable( L, AUDIO_METATABLE );
315 lua_setmetatable( L, -2 );
329 if ( lua_getmetatable( L, ind ) == 0 )
331 lua_getfield( L, LUA_REGISTRYINDEX, AUDIO_METATABLE );
334 if ( lua_rawequal( L, -1, -2 ) )
343 if ( ( la == NULL ) || ( la->
nocleanup ) )
346 switch ( la->
type ) {
349 case LUA_AUDIO_STATIC:
351 if ( alIsSource( la->
source ) == AL_TRUE )
352 alDeleteSources( 1, &la->
source );
354 if ( la->
buf != NULL ) {
365 case LUA_AUDIO_STREAM:
367 if ( la->
th != NULL ) {
371 WARN( _(
"Timed out while waiting for audio thread of '%s' to "
375 if ( alIsSource( la->
source ) == AL_TRUE )
376 alDeleteSources( 1, &la->
source );
379 if ( la->
cond != NULL )
380 SDL_DestroyCond( la->
cond );
381 if ( la->
lock != NULL )
382 SDL_DestroyMutex( la->
lock );
406 char buf[STRMAX_SHORT];
408 snprintf( buf,
sizeof( buf ),
"Audio( %s )", la->
name );
409 lua_pushstring( L, buf );
438 lua_pushboolean( L, ( memcmp( a1, a2,
sizeof(
LuaAudio_t ) ) == 0 ) );
448 alGenSources( 1, source );
449 if ( alIsSource( *source ) == AL_TRUE )
455 case AL_OUT_OF_MEMORY:
458 lua_gc(
naevL, LUA_GCCOLLECT, 0 );
461 alGenSources( 1, source );
462 if ( alIsSource( *source ) == AL_TRUE )
469 al_checkHandleError( err, __func__, __LINE__ );
495 if ( lua_isstring( L, 1 ) )
496 name = lua_tostring( L, 1 );
501 NLUA_INVALID_PARAMETER( L, 1 );
504 if ( lua_isnoneornil( L, 2 ) ) {
507 const char *type = luaL_optstring( L, 2,
"static" );
508 if ( strcmp( type,
"static" ) == 0 )
510 else if ( strcmp( type,
"stream" ) == 0 )
513 NLUA_INVALID_PARAMETER( L, 2 );
522 rw = PHYSFSRWOPS_openRead( name );
524 return NLUA_ERROR( L,
"Unable to open '%s'", name );
525 la.
name = strdup( name );
538 la.
type = LUA_AUDIO_STATIC;
550 ALfloat track_gain_db, track_peak;
553 la.
type = LUA_AUDIO_STREAM;
558 L, _(
"Audio '%s' does not appear to be a Vorbis bitstream." ),
564 vc = ov_comment( &la.
stream, -1 );
567 if ( ( tag = vorbis_comment_query( vc,
"replaygain_track_gain", 0 ) ) )
568 track_gain_db = atof( tag );
569 if ( ( tag = vorbis_comment_query( vc,
"replaygain_track_peak", 0 ) ) )
570 track_peak = atof( tag );
571 la.
rg_scale_factor = pow( 10.0, ( track_gain_db + RG_PREAMP_DB ) / 20.0 );
575 if ( la.
info->channels == 1 )
576 la.
format = AL_FORMAT_MONO16;
578 la.
format = AL_FORMAT_STEREO16;
581 la.
lock = SDL_CreateMutex();
582 la.
cond = SDL_CreateCond();
590 alSourcef( la.
source, AL_GAIN, master );
599 alSourcei( la.
source, AL_SOURCE_RELATIVE, AL_TRUE );
600 alSource3f( la.
source, AL_POSITION, 0., 0., 0. );
625 switch ( source->type ) {
626 case LUA_AUDIO_STATIC:
628 la->
buf = source->buf;
635 case LUA_AUDIO_STREAM:
636 WARN( _(
"Unimplemented" ) );
642 la->
type = source->type;
648 alSourcef( la->
source, AL_GAIN, master * source->volume );
649 la->
volume = source->volume;
651 alSourcei( la->
source, AL_SOURCE_RELATIVE, AL_TRUE );
652 alSource3f( la->
source, AL_POSITION, 0., 0., 0. );
668 audio_clone( &la, source );
686 if ( ( la->
type == LUA_AUDIO_STREAM ) && ( la->
th == NULL ) ) {
690 alGetSourcei( la->
source, AL_BUFFERS_QUEUED, &alstate );
691 while ( alstate < 2 ) {
697 alGetSourcei( la->
source, AL_BUFFERS_QUEUED, &alstate );
700 la->
th = SDL_CreateThread( stream_thread,
"stream_thread", la );
703 alSourcePlay( la->
source );
707 lua_pushboolean( L, 1 );
724 alSourcePause( la->
source );
757 switch ( la->
type ) {
760 case LUA_AUDIO_STATIC:
761 alSourceStop( la->
source );
764 case LUA_AUDIO_STREAM:
766 if ( la->
th != NULL ) {
770 WARN( _(
"Timed out while waiting for audio thread of '%s' to "
777 alSourceStop( la->
source );
780 alGetSourcei( la->
source, AL_BUFFERS_PROCESSED, &alstate );
781 alSourceUnqueueBuffers( la->
source, alstate, removed );
784 SDL_mutexP( la->
lock );
785 ov_pcm_seek( &la->
stream, 0 );
786 SDL_mutexV( la->
lock );
819 case LUA_AUDIO_STATIC:
821 alSourceRewind( la->
source );
825 case LUA_AUDIO_STREAM:
826 SDL_mutexP( la->
lock );
827 ov_raw_seek( &la->
stream, 0 );
828 SDL_mutexV( la->
lock );
848 double offset = luaL_checknumber( L, 2 );
849 const char *unit = luaL_optstring( L, 3,
"seconds" );
852 if ( strcmp( unit,
"samples" ) == 0 )
854 else if ( strcmp( unit,
"seconds" ) != 0 )
855 return NLUA_ERROR( L,
856 _(
"Unknown seek source '%s'! Should be either "
857 "'seconds' or 'samples'!" ),
863 switch ( la->
type ) {
864 case LUA_AUDIO_STATIC:
867 alSourcef( la->
source, AL_SEC_OFFSET, offset );
869 alSourcef( la->
source, AL_SAMPLE_OFFSET, offset );
874 case LUA_AUDIO_STREAM:
875 SDL_mutexP( la->
lock );
877 ov_time_seek( &la->
stream, offset );
879 ov_pcm_seek( &la->
stream, offset );
880 SDL_mutexV( la->
lock );
902 const char *unit = luaL_optstring( L, 2,
"seconds" );
907 if ( strcmp( unit,
"samples" ) == 0 )
909 else if ( strcmp( unit,
"seconds" ) != 0 )
910 return NLUA_ERROR( L,
911 _(
"Unknown seek source '%s'! Should be either "
912 "'seconds' or 'samples'!" ),
916 lua_pushnumber( L, -1. );
920 switch ( la->
type ) {
921 case LUA_AUDIO_STATIC:
924 alGetSourcef( la->
source, AL_SEC_OFFSET, &aloffset );
926 alGetSourcef( la->
source, AL_SAMPLE_OFFSET, &aloffset );
932 case LUA_AUDIO_STREAM:
933 SDL_mutexP( la->
lock );
935 offset = ov_time_tell( &la->
stream );
937 offset = ov_pcm_tell( &la->
stream );
938 SDL_mutexV( la->
lock );
945 lua_pushnumber( L, offset );
961 const char *unit = luaL_optstring( L, 2,
"seconds" );
962 float duration = -1.;
964 ALint bytes, channels, bits, samples;
967 if ( strcmp( unit,
"samples" ) == 0 )
969 else if ( strcmp( unit,
"seconds" ) != 0 )
970 return NLUA_ERROR( L,
971 _(
"Unknown duration source '%s'! Should be either "
972 "'seconds' or 'samples'!" ),
976 lua_pushnumber( L, -1. );
980 switch ( la->
type ) {
981 case LUA_AUDIO_STATIC:
984 alGetBufferi( buffer, AL_SIZE, &bytes );
985 alGetBufferi( buffer, AL_CHANNELS, &channels );
986 alGetBufferi( buffer, AL_BITS, &bits );
988 samples = bytes * 8 / ( channels * bits );
992 alGetBufferi( buffer, AL_FREQUENCY, &freq );
993 duration = (float)samples / (
float)freq;
1000 case LUA_AUDIO_STREAM:
1001 SDL_mutexP( la->
lock );
1003 duration = ov_time_total( &la->
stream, -1 );
1005 duration = ov_pcm_total( &la->
stream, -1 );
1006 SDL_mutexV( la->
lock );
1009 case LUA_AUDIO_NULL:
1013 lua_pushnumber( L, duration );
1029 double volume =
CLAMP( 0.0, 1.0, luaL_checknumber( L, 2 ) );
1030 int ignorevol = lua_toboolean( L, 3 );
1036 alSourcef( la->
source, AL_GAIN, volume );
1039 alSourcef( la->
source, AL_GAIN, master * volume );
1059 else if ( lua_gettop( L ) > 0 )
1063 lua_pushnumber( L, volume );
1081 alSourcei( la->
source, AL_SOURCE_RELATIVE, lua_toboolean( L, 2 ) );
1103 pos[0] = luaL_optnumber( L, 2, 0. );
1104 pos[1] = luaL_optnumber( L, 3, 0. );
1105 pos[2] = luaL_optnumber( L, 4, 0. );
1108 alSourcefv( la->
source, AL_POSITION, pos );
1128 lua_pushnumber( L, 0. );
1129 lua_pushnumber( L, 0. );
1130 lua_pushnumber( L, 0. );
1135 alGetSource3f( la->
source, AL_POSITION, &pos[0], &pos[1], &pos[2] );
1139 lua_pushnumber( L, pos[0] );
1140 lua_pushnumber( L, pos[1] );
1141 lua_pushnumber( L, pos[2] );
1161 vel[0] = luaL_optnumber( L, 2, 0. );
1162 vel[1] = luaL_optnumber( L, 3, 0. );
1163 vel[2] = luaL_optnumber( L, 4, 0. );
1166 alSourcefv( la->
source, AL_VELOCITY, vel );
1186 lua_pushnumber( L, 0. );
1187 lua_pushnumber( L, 0. );
1188 lua_pushnumber( L, 0. );
1193 alGetSource3f( la->
source, AL_VELOCITY, &vel[0], &vel[1], &vel[2] );
1197 lua_pushnumber( L, vel[0] );
1198 lua_pushnumber( L, vel[1] );
1199 lua_pushnumber( L, vel[2] );
1214 int b = lua_toboolean( L, 2 );
1218 alSourcei( la->
source, AL_LOOPING, b );
1246 double pitch = luaL_checknumber( L, 2 );
1250 alSourcef( la->
source, AL_PITCH, pitch );
1269 alGetSourcef( la->
source, AL_PITCH, &p );
1273 lua_pushnumber( L, p );
1295 vec2 *pos, *vel, vel0;
1302 name = luaL_checkstring( L, 1 );
1303 if ( lua_gettop( L ) > 1 ) {
1306 if ( lua_gettop( L ) > 2 ) {
1332 double ref = luaL_checknumber( L, 2 );
1333 double max = luaL_checknumber( L, 3 );
1337 alSourcef( la->
source, AL_REFERENCE_DISTANCE, ref );
1338 alSourcef( la->
source, AL_MAX_DISTANCE, max );
1357 lua_pushnumber( L, 0. );
1358 lua_pushnumber( L, 0. );
1362 alGetSourcef( la->
source, AL_REFERENCE_DISTANCE, &ref );
1363 alGetSourcef( la->
source, AL_MAX_DISTANCE, &max );
1366 lua_pushnumber( L, ref );
1367 lua_pushnumber( L, max );
1380 double rolloff = luaL_checknumber( L, 2 );
1384 alSourcef( la->
source, AL_ROLLOFF_FACTOR, rolloff );
1401 lua_pushnumber( L, 0. );
1405 alGetSourcef( la->
source, AL_ROLLOFF_FACTOR, &rolloff );
1408 lua_pushnumber( L, rolloff );
1412static void efx_setnum( lua_State *L,
int pos, ALuint effect,
const char *name,
1415 lua_getfield( L, pos, name );
1416 if ( !lua_isnil( L, -1 ) )
1417 nalEffectf( effect, param, luaL_checknumber( L, -1 ) );
1420static void efx_setint( lua_State *L,
int pos, ALuint effect,
const char *name,
1423 lua_getfield( L, pos, name );
1424 if ( !lua_isnil( L, -1 ) )
1425 nalEffecti( effect, param, luaL_checkinteger( L, -1 ) );
1428static void efx_setbool( lua_State *L,
int pos, ALuint effect,
const char *name,
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 ) {
1470 if ( lae == NULL ) {
1472 nalGenEffects( 1, &effect );
1473 nalGenAuxiliaryEffectSlots( 1, &slot );
1474 lae->
name = strdup( name );
1483 if ( strcmp( type,
"reverb" ) == 0 ) {
1484 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB );
1486 efx_setnum( L, p, effect,
"density",
1487 AL_REVERB_DENSITY );
1488 efx_setnum( L, p, effect,
"diffusion",
1489 AL_REVERB_DIFFUSION );
1490 efx_setnum( L, p, effect,
"gain",
1492 efx_setnum( L, p, effect,
"highgain",
1494 efx_setnum( L, p, effect,
"decaytime",
1495 AL_REVERB_DECAY_TIME );
1496 efx_setnum( L, p, effect,
"decayhighratio",
1497 AL_REVERB_DECAY_HFRATIO );
1498 efx_setnum( L, p, effect,
"earlygain",
1499 AL_REVERB_REFLECTIONS_GAIN );
1500 efx_setnum( L, p, effect,
"earlydelay",
1501 AL_REVERB_REFLECTIONS_DELAY );
1502 efx_setnum( L, p, effect,
"lategain",
1503 AL_REVERB_LATE_REVERB_GAIN );
1504 efx_setnum( L, p, effect,
"latedelay",
1505 AL_REVERB_LATE_REVERB_DELAY );
1506 efx_setnum( L, p, effect,
"roomrolloff",
1507 AL_REVERB_ROOM_ROLLOFF_FACTOR );
1508 efx_setnum( L, p, effect,
"airabsorption",
1509 AL_REVERB_AIR_ABSORPTION_GAINHF );
1511 L, p, effect,
"highlimit",
1512 AL_REVERB_DECAY_HFLIMIT );
1513 }
else if ( strcmp( type,
"distortion" ) == 0 ) {
1514 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_DISTORTION );
1516 efx_setnum( L, p, effect,
"gain",
1517 AL_DISTORTION_GAIN );
1518 efx_setnum( L, p, effect,
"edge",
1519 AL_DISTORTION_EDGE );
1520 efx_setnum( L, p, effect,
"lowcut",
1521 AL_DISTORTION_LOWPASS_CUTOFF );
1522 efx_setnum( L, p, effect,
"center",
1523 AL_DISTORTION_EQCENTER );
1524 efx_setnum( L, p, effect,
"bandwidth",
1525 AL_DISTORTION_EQBANDWIDTH );
1526 }
else if ( strcmp( type,
"chorus" ) == 0 ) {
1527 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_CHORUS );
1529 efx_setint( L, p, effect,
"waveform",
1530 AL_CHORUS_WAVEFORM );
1531 efx_setint( L, p, effect,
"phase",
1533 efx_setnum( L, p, effect,
"rate",
1535 efx_setnum( L, p, effect,
"depth",
1537 efx_setnum( L, p, effect,
"feedback",
1538 AL_CHORUS_FEEDBACK );
1539 efx_setnum( L, p, effect,
"delay",
1541 }
else if ( strcmp( type,
"compressor" ) == 0 ) {
1542 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_COMPRESSOR );
1544 efx_setbool( L, p, effect,
"enable",
1545 AL_COMPRESSOR_ONOFF );
1546 }
else if ( strcmp( type,
"echo" ) == 0 ) {
1547 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_ECHO );
1549 efx_setnum( L, p, effect,
"delay",
1551 efx_setnum( L, p, effect,
"tapdelay",
1553 efx_setnum( L, p, effect,
"damping",
1555 efx_setnum( L, p, effect,
"feedback",
1557 efx_setnum( L, p, effect,
"spread",
1559 }
else if ( strcmp( type,
"ringmodulator" ) == 0 ) {
1560 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_RING_MODULATOR );
1562 efx_setnum( L, p, effect,
"frequency",
1563 AL_RING_MODULATOR_FREQUENCY );
1565 L, p, effect,
"highcut",
1566 AL_RING_MODULATOR_HIGHPASS_CUTOFF );
1567 efx_setint( L, p, effect,
"waveform",
1568 AL_RING_MODULATOR_WAVEFORM );
1570 }
else if ( strcmp( type,
"equalizer" ) == 0 ) {
1571 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_EQUALIZER );
1573 efx_setnum( L, p, effect,
"lowgain",
1574 AL_EQUALIZER_LOW_GAIN );
1575 efx_setnum( L, p, effect,
"lowcut",
1576 AL_EQUALIZER_LOW_CUTOFF );
1577 efx_setnum( L, p, effect,
"lowmidgain",
1578 AL_EQUALIZER_MID1_GAIN );
1579 efx_setnum( L, p, effect,
"lowmidfrequency",
1580 AL_EQUALIZER_MID1_CENTER );
1581 efx_setnum( L, p, effect,
"lowmidbandwidth",
1582 AL_EQUALIZER_MID1_WIDTH );
1583 efx_setnum( L, p, effect,
"highmidgain",
1584 AL_EQUALIZER_MID2_GAIN );
1585 efx_setnum( L, p, effect,
"highmidfrequency",
1586 AL_EQUALIZER_MID2_CENTER );
1587 efx_setnum( L, p, effect,
"highmidbandwidth",
1588 AL_EQUALIZER_MID2_WIDTH );
1589 efx_setnum( L, p, effect,
"highgain",
1590 AL_EQUALIZER_HIGH_GAIN );
1591 efx_setnum( L, p, effect,
"highcut",
1592 AL_EQUALIZER_HIGH_CUTOFF );
1593 }
else if ( strcmp( type,
"pitchshifter" ) == 0 ) {
1594 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_PITCH_SHIFTER );
1596 efx_setint( L, p, effect,
"tunecoarse",
1597 AL_PITCH_SHIFTER_COARSE_TUNE );
1598 efx_setint( L, p, effect,
"tunefine'",
1599 AL_PITCH_SHIFTER_FINE_TUNE );
1600 }
else if ( strcmp( type,
"vocalmorpher" ) == 0 ) {
1601 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_VOCAL_MORPHER );
1603 efx_setint( L, p, effect,
"phonemea",
1604 AL_VOCAL_MORPHER_PHONEMEA );
1605 efx_setint( L, p, effect,
"phonemeb",
1606 AL_VOCAL_MORPHER_PHONEMEB );
1607 efx_setint( L, p, effect,
"tunecoarsea",
1608 AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING );
1609 efx_setint( L, p, effect,
"tunecoarseb",
1610 AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING );
1611 efx_setint( L, p, effect,
"waveform",
1612 AL_VOCAL_MORPHER_WAVEFORM );
1614 efx_setnum( L, p, effect,
"rate",
1615 AL_VOCAL_MORPHER_RATE );
1616 }
else if ( strcmp( type,
"flanger" ) == 0 ) {
1617 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_FLANGER );
1620 L, p, effect,
"waveform",
1621 AL_FLANGER_WAVEFORM );
1622 efx_setnum( L, p, effect,
"phase",
1624 efx_setnum( L, p, effect,
"rate",
1626 efx_setnum( L, p, effect,
"depth",
1628 efx_setnum( L, p, effect,
"feedback",
1629 AL_FLANGER_FEEDBACK );
1630 efx_setnum( L, p, effect,
"delay",
1632 }
else if ( strcmp( type,
"frequencyshifter" ) == 0 ) {
1633 nalEffecti( effect, AL_EFFECT_TYPE, AL_EFFECT_FREQUENCY_SHIFTER );
1635 efx_setnum( L, p, effect,
"frequency",
1636 AL_FREQUENCY_SHIFTER_FREQUENCY );
1637 efx_setint( L, p, effect,
"leftdirection",
1638 AL_FREQUENCY_SHIFTER_LEFT_DIRECTION );
1640 efx_setint( L, p, effect,
"rightdirection",
1641 AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION );
1645 return NLUA_ERROR( L, _(
"Unsupported audio effect type '%s'!" ), type );
1649 nalAuxiliaryEffectSlotf( slot, AL_EFFECTSLOT_GAIN, volume );
1650 nalAuxiliaryEffectSloti( slot, AL_EFFECTSLOT_EFFECT, effect );
1658static LuaAudioEfx_t *audio_getEffectByName(
const char *name )
1661 if ( strcmp( name,
lua_efx[i].name ) == 0 )
1663 WARN( _(
"Unknown audio effect '%s'!" ), name );
1683 if (
al_info.efx == AL_FALSE ) {
1684 lua_pushboolean( L, 1 );
1690 return audioL_setEffectGlobal( L );
1693 const char *name = luaL_checkstring( L, 2 );
1694 int enable = ( lua_isnoneornil( L, 3 ) ) ? 1 : lua_toboolean( L, 3 );
1699 if ( lae == NULL ) {
1704 alSource3i( la->
source, AL_AUXILIARY_SEND_FILTER, lae->
slot, 0,
1707 alSource3i( la->
source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0,
1713 lua_pushboolean( L, 1 );
1727 const char *name = luaL_optstring( L, 1, NULL );
1732 if (
al_info.efx == AL_FALSE )
1736 if ( name == NULL ) {
1746 lae = audio_getEffectByName( name );
1769 double speed = luaL_optnumber( L, 1, 3433. );
1770 double absorption = luaL_optnumber( L, 2, -1. );
1776 alSpeedOfSound( speed );
1777 if ( absorption > 0. )
1778 sound_setAbsorption( absorption );
1799 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_tostring(lua_State *L)
Lua bindings to interact with audio.
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.
LuaAudio_t * luaL_checkaudio(lua_State *L, int ind)
Gets audio at index or raises error if there is no audio at index.
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)
Frees a 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.
void rg_filter(float **pcm, long channels, long samples, void *filter_param)
This is the filter function for the decoded Ogg Vorbis stream.
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.