diff options
Diffstat (limited to 'src/audio')
-rw-r--r-- | src/audio/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/audio/audio.c | 67 | ||||
-rw-r--r-- | src/audio/audio.h | 112 | ||||
-rw-r--r-- | src/audio/bind | 68 | ||||
-rw-r--r-- | src/audio/bind.bind | 655 | ||||
-rw-r--r-- | src/audio/engine.c | 310 | ||||
-rw-r--r-- | src/audio/impl.c | 8 | ||||
-rw-r--r-- | src/audio/setup.c | 31 | ||||
-rw-r--r-- | src/audio/sound.c | 640 |
9 files changed, 1824 insertions, 72 deletions
diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index 41644fb..8d38f01 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -1,5 +1,8 @@ project(honey_engine) target_sources(honey PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/audio.c + ${CMAKE_CURRENT_LIST_DIR}/impl.c + ${CMAKE_CURRENT_LIST_DIR}/setup.c + ${CMAKE_CURRENT_LIST_DIR}/engine.c + ${CMAKE_CURRENT_LIST_DIR}/sound.c ) diff --git a/src/audio/audio.c b/src/audio/audio.c deleted file mode 100644 index 412a434..0000000 --- a/src/audio/audio.c +++ /dev/null @@ -1,67 +0,0 @@ -#include <lua.h> -#include <lauxlib.h> - -#define STB_VORBIS_HEADER_ONLY -#include <stb_vorbis.c> -#define MINIAUDIO_IMPLEMENTATION -#include <miniaudio.h> -#undef STB_VORBIS_HEADER_ONLY -#include <stb_vorbis.c> - -/* stb_vorbis defines this for some reason? */ -#undef L - -#include "util/util.h" -#include "audio.h" - - -const char *audio_engine_tname = "audio.Engine"; - - -void setup_audio(lua_State *L, int honey_tbl) -{ - luaL_newmetatable(L, audio_engine_tname); lua_pop(L, 1); - - struct honey_tbl_t audio[] = { - #define X(name, func) H_FUNC(name, func), - AUDIO_FUNCTIONS - #undef X - - /* ma_result values */ - H_ENUM(MA_SUCCESS), - - H_END, - }; - create_table(L, audio); - lua_setfield(L, honey_tbl, "audio"); -} - - -int audio_engine_init(lua_State *L) -{ - ma_engine *engine = lua_newuserdata(L, sizeof(ma_engine)); - ma_result result = ma_engine_init(NULL, engine); - if (result != MA_SUCCESS) - luaL_error(L, "failed to initialize audio engine: %d", result); - - luaL_getmetatable(L, audio_engine_tname); - lua_setmetatable(L, -2); - return 1; -} - - -int audio_engine_uninit(lua_State *L) -{ - ma_engine *engine = luaL_checkudata(L, 1, audio_engine_tname); - ma_engine_uninit(engine); - return 0; -} - - -int audio_engine_play_sound(lua_State *L) -{ - ma_engine *engine = luaL_checkudata(L, 1, audio_engine_tname); - char *filename = luaL_checkstring(L, 2); - ma_engine_play_sound(engine, filename, NULL); - return 0; -} diff --git a/src/audio/audio.h b/src/audio/audio.h index 319a86c..984e1ea 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -2,13 +2,117 @@ #define HONEY_AUDIO_H #include <lua.h> +#include <miniaudio.h> + + +ma_sound_group * to_sound_group(lua_State *L, int index); +void ma_push_node(lua_State *L, ma_node *n); + +#define AUDIO_METATABLES \ + X("ma.engine", ma_engine_tname) \ + X("ma.node", ma_node_tname) \ + X("ma.sound", ma_sound_tname) \ + +#define X(name, mt) extern const char *mt; +AUDIO_METATABLES +#undef X -extern const char *audio_engine_tname; #define AUDIO_FUNCTIONS \ - X("engine_init", audio_engine_init) \ - X("engine_uninit", audio_engine_uninit) \ - X("engine_play_sound", audio_engine_play_sound) \ + /* engine */ \ + X("ma_engine_init", ma_engine_init_bind) \ + X("ma_engine_uninit", ma_engine_uninit_bind) \ + X("ma_engine_get_endpoint", ma_engine_get_endpoint_bind) \ + X("ma_engine_get_time", ma_engine_get_time_bind) \ + X("ma_engine_set_time", ma_engine_set_time_bind) \ + X("ma_engine_get_channels", ma_engine_get_channels_bind) \ + X("ma_engine_get_sample_rate", ma_engine_get_sample_rate_bind) \ + X("ma_engine_start", ma_engine_start_bind) \ + X("ma_engine_stop", ma_engine_stop_bind) \ + X("ma_engine_set_volume", ma_engine_set_volume_bind) \ + X("ma_engine_set_gain_db", ma_engine_set_gain_db_bind) \ + X("ma_engine_get_listener_count", ma_engine_get_listener_count_bind) \ + X("ma_engine_find_closest_listener", ma_engine_find_closest_listener_bind) \ + X("ma_engine_listener_set_position", ma_engine_listener_set_position_bind) \ + X("ma_engine_listener_get_position", ma_engine_listener_get_position_bind) \ + X("ma_engine_listener_set_direction", ma_engine_listener_set_direction_bind) \ + X("ma_engine_listener_get_direction", ma_engine_listener_get_direction_bind) \ + X("ma_engine_listener_set_velocity", ma_engine_listener_set_velocity_bind) \ + X("ma_engine_listener_get_velocity", ma_engine_listener_get_velocity_bind) \ + X("ma_engine_listener_set_cone", ma_engine_listener_set_cone_bind) \ + X("ma_engine_listener_get_cone", ma_engine_listener_get_cone_bind) \ + X("ma_engine_listener_set_world_up", ma_engine_listener_set_world_up_bind) \ + X("ma_engine_listener_get_world_up", ma_engine_listener_get_world_up_bind) \ + X("ma_engine_listener_set_enabled", ma_engine_listener_set_enabled_bind) \ + X("ma_engine_listener_is_enabled", ma_engine_listener_is_enabled_bind) \ + X("ma_engine_play_sound_ex", ma_engine_play_sound_ex_bind) \ + X("ma_engine_play_sound", ma_engine_play_sound_bind) \ +\ + /* sound */ \ + X("ma_sound_init_from_file", ma_sound_init_from_file_bind) \ + X("ma_sound_init_copy", ma_sound_init_copy_bind) \ + X("ma_sound_uninit", ma_sound_uninit_bind) \ + X("ma_sound_start", ma_sound_start_bind) \ + X("ma_sound_stop", ma_sound_stop_bind) \ + X("ma_sound_set_volume", ma_sound_set_volume_bind) \ + X("ma_sound_get_volume", ma_sound_get_volume_bind) \ + X("ma_sound_set_pan", ma_sound_set_pan_bind) \ + X("ma_sound_get_pan", ma_sound_get_pan_bind) \ + X("ma_sound_set_pan_mode", ma_sound_set_pan_mode_bind) \ + X("ma_sound_get_pan_mode", ma_sound_get_pan_mode_bind) \ + X("ma_sound_set_pitch", ma_sound_set_pitch_bind) \ + X("ma_sound_get_pitch", ma_sound_get_pitch_bind) \ + X("ma_sound_set_spatialization_enabled", ma_sound_set_spatialization_enabled_bind) \ + X("ma_sound_is_spatialization_enabled", ma_sound_is_spatialization_enabled_bind) \ + X("ma_sound_set_pinned_listener_index", ma_sound_set_pinned_listener_index_bind) \ + X("ma_sound_get_pinned_listener_index", ma_sound_get_pinned_listener_index_bind) \ + X("ma_sound_get_listener_index", ma_sound_get_listener_index_bind) \ + X("ma_sound_get_direction_to_listener", ma_sound_get_direction_to_listener_bind) \ + X("ma_sound_set_position", ma_sound_set_position_bind) \ + X("ma_sound_get_position", ma_sound_get_position_bind) \ + X("ma_sound_set_direction", ma_sound_set_direction_bind) \ + X("ma_sound_get_direction", ma_sound_get_direction_bind) \ + X("ma_sound_set_velocity", ma_sound_set_velocity_bind) \ + X("ma_sound_get_velocity", ma_sound_get_velocity_bind) \ + X("ma_sound_set_attenuation_model", ma_sound_set_attenuation_model_bind) \ + X("ma_sound_get_attenuation_model", ma_sound_get_attenuation_model_bind) \ + X("ma_sound_set_positioning", ma_sound_set_positioning_bind) \ + X("ma_sound_get_positioning", ma_sound_get_positioning_bind) \ + X("ma_sound_set_rolloff", ma_sound_set_rolloff_bind) \ + X("ma_sound_get_rolloff", ma_sound_get_rolloff_bind) \ + X("ma_sound_set_min_gain", ma_sound_set_min_gain_bind) \ + X("ma_sound_get_min_gain", ma_sound_get_min_gain_bind) \ + X("ma_sound_set_max_gain", ma_sound_set_max_gain_bind) \ + X("ma_sound_get_max_gain", ma_sound_get_max_gain_bind) \ + X("ma_sound_set_min_distance", ma_sound_set_min_distance_bind) \ + X("ma_sound_get_min_distance", ma_sound_get_min_distance_bind) \ + X("ma_sound_set_max_distance", ma_sound_set_max_distance_bind) \ + X("ma_sound_get_max_distance", ma_sound_get_max_distance_bind) \ + X("ma_sound_set_cone", ma_sound_set_cone_bind) \ + X("ma_sound_get_cone", ma_sound_get_cone_bind) \ + X("ma_sound_set_doppler_factor", ma_sound_set_doppler_factor_bind) \ + X("ma_sound_get_doppler_factor", ma_sound_get_doppler_factor_bind) \ + X("ma_sound_set_directional_attenuation_factor", ma_sound_set_directional_attenuation_factor_bind) \ + X("ma_sound_get_directional_attenuation_factor", ma_sound_get_directional_attenuation_factor_bind) \ + X("ma_sound_set_fade_in_pcm_frames", ma_sound_set_fade_in_pcm_frames_bind) \ + X("ma_sound_set_fade_in_milliseconds", ma_sound_set_fade_in_milliseconds_bind) \ + X("ma_sound_get_current_fade_volume", ma_sound_get_current_fade_volume_bind) \ + X("ma_sound_set_start_time_in_pcm_frames", ma_sound_set_start_time_in_pcm_frames_bind) \ + X("ma_sound_set_start_time_in_milliseconds", ma_sound_set_start_time_in_milliseconds_bind) \ + X("ma_sound_set_stop_time_in_pcm_frames", ma_sound_set_stop_time_in_pcm_frames_bind) \ + X("ma_sound_set_stop_time_in_milliseconds", ma_sound_set_stop_time_in_milliseconds_bind) \ + X("ma_sound_is_playing", ma_sound_is_playing_bind) \ + X("ma_sound_get_time_in_pcm_frames", ma_sound_get_time_in_pcm_frames_bind) \ + X("ma_sound_set_looping", ma_sound_set_looping_bind) \ + X("ma_sound_is_looping", ma_sound_is_looping_bind) \ + X("ma_sound_at_end", ma_sound_at_end_bind) \ + X("ma_sound_seek_to_pcm_frame", ma_sound_seek_to_pcm_frame_bind) \ + X("ma_sound_get_data_format", ma_sound_get_data_format_bind) \ + X("ma_sound_get_cursor_in_pcm_frames", ma_sound_get_cursor_in_pcm_frames_bind) \ + X("ma_sound_get_length_in_pcm_frames", ma_sound_get_length_in_pcm_frames_bind) \ + X("ma_sound_get_cursor_in_seconds", ma_sound_get_cursor_in_seconds_bind) \ + X("ma_sound_get_length_in_seconds", ma_sound_get_length_in_seconds_bind) \ + #define X(name, func) int func(lua_State *L); AUDIO_FUNCTIONS diff --git a/src/audio/bind b/src/audio/bind new file mode 100644 index 0000000..6f7e41c --- /dev/null +++ b/src/audio/bind @@ -0,0 +1,68 @@ +ma_result ma_sound_init_from_file(ma_engine* pEngine, const char* pFilePath, ma_uint32 flags, ma_sound_group* pGroup, ma_fence* pDoneFence, ma_sound* pSound); +ma_result ma_sound_init_from_file_w(ma_engine* pEngine, const wchar_t* pFilePath, ma_uint32 flags, ma_sound_group* pGroup, ma_fence* pDoneFence, ma_sound* pSound); +ma_result ma_sound_init_copy(ma_engine* pEngine, const ma_sound* pExistingSound, ma_uint32 flags, ma_sound_group* pGroup, ma_sound* pSound); +ma_result ma_sound_init_from_data_source(ma_engine* pEngine, ma_data_source* pDataSource, ma_uint32 flags, ma_sound_group* pGroup, ma_sound* pSound); +ma_result ma_sound_init_ex(ma_engine* pEngine, const ma_sound_config* pConfig, ma_sound* pSound); +void ma_sound_uninit(ma_sound* pSound); +ma_engine* ma_sound_get_engine(const ma_sound* pSound); +ma_data_source* ma_sound_get_data_source(const ma_sound* pSound); +ma_result ma_sound_start(ma_sound* pSound); +ma_result ma_sound_stop(ma_sound* pSound); +void ma_sound_set_volume(ma_sound* pSound, float volume); +float ma_sound_get_volume(const ma_sound* pSound); +void ma_sound_set_pan(ma_sound* pSound, float pan); +float ma_sound_get_pan(const ma_sound* pSound); +void ma_sound_set_pan_mode(ma_sound* pSound, ma_pan_mode panMode); +ma_pan_mode ma_sound_get_pan_mode(const ma_sound* pSound); +void ma_sound_set_pitch(ma_sound* pSound, float pitch); +float ma_sound_get_pitch(const ma_sound* pSound); +void ma_sound_set_spatialization_enabled(ma_sound* pSound, ma_bool32 enabled); +ma_bool32 ma_sound_is_spatialization_enabled(const ma_sound* pSound); +void ma_sound_set_pinned_listener_index(ma_sound* pSound, ma_uint32 listenerIndex); +ma_uint32 ma_sound_get_pinned_listener_index(const ma_sound* pSound); +ma_uint32 ma_sound_get_listener_index(const ma_sound* pSound); +ma_vec3f ma_sound_get_direction_to_listener(const ma_sound* pSound); +void ma_sound_set_position(ma_sound* pSound, float x, float y, float z); +ma_vec3f ma_sound_get_position(const ma_sound* pSound); +void ma_sound_set_direction(ma_sound* pSound, float x, float y, float z); +ma_vec3f ma_sound_get_direction(const ma_sound* pSound); +void ma_sound_set_velocity(ma_sound* pSound, float x, float y, float z); +ma_vec3f ma_sound_get_velocity(const ma_sound* pSound); +void ma_sound_set_attenuation_model(ma_sound* pSound, ma_attenuation_model attenuationModel); +ma_attenuation_model ma_sound_get_attenuation_model(const ma_sound* pSound); +void ma_sound_set_positioning(ma_sound* pSound, ma_positioning positioning); +ma_positioning ma_sound_get_positioning(const ma_sound* pSound); +void ma_sound_set_rolloff(ma_sound* pSound, float rolloff); +float ma_sound_get_rolloff(const ma_sound* pSound); +void ma_sound_set_min_gain(ma_sound* pSound, float minGain); +float ma_sound_get_min_gain(const ma_sound* pSound); +void ma_sound_set_max_gain(ma_sound* pSound, float maxGain); +float ma_sound_get_max_gain(const ma_sound* pSound); +void ma_sound_set_min_distance(ma_sound* pSound, float minDistance); +float ma_sound_get_min_distance(const ma_sound* pSound); +void ma_sound_set_max_distance(ma_sound* pSound, float maxDistance); +float ma_sound_get_max_distance(const ma_sound* pSound); +void ma_sound_set_cone(ma_sound* pSound, float innerAngleInRadians, float outerAngleInRadians, float outerGain); +void ma_sound_get_cone(const ma_sound* pSound, float* pInnerAngleInRadians, float* pOuterAngleInRadians, float* pOuterGain); +void ma_sound_set_doppler_factor(ma_sound* pSound, float dopplerFactor); +float ma_sound_get_doppler_factor(const ma_sound* pSound); +void ma_sound_set_directional_attenuation_factor(ma_sound* pSound, float directionalAttenuationFactor); +float ma_sound_get_directional_attenuation_factor(const ma_sound* pSound); +void ma_sound_set_fade_in_pcm_frames(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInFrames); +void ma_sound_set_fade_in_milliseconds(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInMilliseconds); +float ma_sound_get_current_fade_volume(ma_sound* pSound); +void ma_sound_set_start_time_in_pcm_frames(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInFrames); +void ma_sound_set_start_time_in_milliseconds(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInMilliseconds); +void ma_sound_set_stop_time_in_pcm_frames(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInFrames); +void ma_sound_set_stop_time_in_milliseconds(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInMilliseconds); +ma_bool32 ma_sound_is_playing(const ma_sound* pSound); +ma_uint64 ma_sound_get_time_in_pcm_frames(const ma_sound* pSound); +void ma_sound_set_looping(ma_sound* pSound, ma_bool32 isLooping); +ma_bool32 ma_sound_is_looping(const ma_sound* pSound); +ma_bool32 ma_sound_at_end(const ma_sound* pSound); +ma_result ma_sound_seek_to_pcm_frame(ma_sound* pSound, ma_uint64 frameIndex); +ma_result ma_sound_get_data_format(ma_sound* pSound, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap); +ma_result ma_sound_get_cursor_in_pcm_frames(ma_sound* pSound, ma_uint64* pCursor); +ma_result ma_sound_get_length_in_pcm_frames(ma_sound* pSound, ma_uint64* pLength); +ma_result ma_sound_get_cursor_in_seconds(ma_sound* pSound, float* pCursor); +ma_result ma_sound_get_length_in_seconds(ma_sound* pSound, float* pLength); diff --git a/src/audio/bind.bind b/src/audio/bind.bind new file mode 100644 index 0000000..c09a1ca --- /dev/null +++ b/src/audio/bind.bind @@ -0,0 +1,655 @@ +int ma_sound_init_from_file_bind(lua_State *L) +{ + ma_engine * pEngine = get: ma_engine * + const char * pFilePath = luaL_checkstring(L, 2); + ma_uint32 flags = luaL_checkinteger(L, 3); + ma_sound_group * pGroup = get: ma_sound_group * + ma_fence * pDoneFence = get: ma_fence * + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_init_from_file(pEngine, pFilePath, flags, pGroup, pDoneFence, pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_init_from_file_w_bind(lua_State *L) +{ + ma_engine * pEngine = get: ma_engine * + const wchar_t * pFilePath = luaL_checkstring(L, 2); + ma_uint32 flags = luaL_checkinteger(L, 3); + ma_sound_group * pGroup = get: ma_sound_group * + ma_fence * pDoneFence = get: ma_fence * + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_init_from_file_w(pEngine, pFilePath, flags, pGroup, pDoneFence, pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_init_copy_bind(lua_State *L) +{ + ma_engine * pEngine = get: ma_engine * + const ma_sound * pExistingSound = get: const ma_sound * + ma_uint32 flags = luaL_checkinteger(L, 3); + ma_sound_group * pGroup = get: ma_sound_group * + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_init_copy(pEngine, pExistingSound, flags, pGroup, pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_init_from_data_source_bind(lua_State *L) +{ + ma_engine * pEngine = get: ma_engine * + ma_data_source * pDataSource = get: ma_data_source * + ma_uint32 flags = luaL_checkinteger(L, 3); + ma_sound_group * pGroup = get: ma_sound_group * + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_init_from_data_source(pEngine, pDataSource, flags, pGroup, pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_init_ex_bind(lua_State *L) +{ + ma_engine * pEngine = get: ma_engine * + const ma_sound_config * pConfig = get: const ma_sound_config * + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_init_ex(pEngine, pConfig, pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_uninit_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_sound_uninit(pSound); + return 0; +} + + +int ma_sound_get_engine_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_engine* bind_result = ma_sound_get_engine(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_get_data_source_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_data_source* bind_result = ma_sound_get_data_source(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_start_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_start(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_stop_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_result bind_result = ma_sound_stop(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_volume_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float volume = luaL_checknumber(L, 2); + ma_sound_set_volume(pSound, volume); + return 0; +} + + +int ma_sound_get_volume_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_volume(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_pan_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float pan = luaL_checknumber(L, 2); + ma_sound_set_pan(pSound, pan); + return 0; +} + + +int ma_sound_get_pan_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_pan(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_pan_mode_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_pan_mode panMode = get: ma_pan_mode + ma_sound_set_pan_mode(pSound, panMode); + return 0; +} + + +int ma_sound_get_pan_mode_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_pan_mode bind_result = ma_sound_get_pan_mode(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_pitch_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float pitch = luaL_checknumber(L, 2); + ma_sound_set_pitch(pSound, pitch); + return 0; +} + + +int ma_sound_get_pitch_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_pitch(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_spatialization_enabled_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_bool32 enabled = get: ma_bool32 + ma_sound_set_spatialization_enabled(pSound, enabled); + return 0; +} + + +int ma_sound_is_spatialization_enabled_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_bool32 bind_result = ma_sound_is_spatialization_enabled(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_pinned_listener_index_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_sound_set_pinned_listener_index(pSound, listenerIndex); + return 0; +} + + +int ma_sound_get_pinned_listener_index_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_uint32 bind_result = ma_sound_get_pinned_listener_index(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_listener_index_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_uint32 bind_result = ma_sound_get_listener_index(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_direction_to_listener_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_vec3f bind_result = ma_sound_get_direction_to_listener(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_position_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + ma_sound_set_position(pSound, x, y, z); + return 0; +} + + +int ma_sound_get_position_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_vec3f bind_result = ma_sound_get_position(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_direction_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + ma_sound_set_direction(pSound, x, y, z); + return 0; +} + + +int ma_sound_get_direction_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_vec3f bind_result = ma_sound_get_direction(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_velocity_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + ma_sound_set_velocity(pSound, x, y, z); + return 0; +} + + +int ma_sound_get_velocity_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_vec3f bind_result = ma_sound_get_velocity(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_attenuation_model_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_attenuation_model attenuationModel = get: ma_attenuation_model + ma_sound_set_attenuation_model(pSound, attenuationModel); + return 0; +} + + +int ma_sound_get_attenuation_model_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_attenuation_model bind_result = ma_sound_get_attenuation_model(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_positioning_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_positioning positioning = get: ma_positioning + ma_sound_set_positioning(pSound, positioning); + return 0; +} + + +int ma_sound_get_positioning_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_positioning bind_result = ma_sound_get_positioning(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_set_rolloff_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float rolloff = luaL_checknumber(L, 2); + ma_sound_set_rolloff(pSound, rolloff); + return 0; +} + + +int ma_sound_get_rolloff_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_rolloff(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_min_gain_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float minGain = luaL_checknumber(L, 2); + ma_sound_set_min_gain(pSound, minGain); + return 0; +} + + +int ma_sound_get_min_gain_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_min_gain(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_max_gain_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float maxGain = luaL_checknumber(L, 2); + ma_sound_set_max_gain(pSound, maxGain); + return 0; +} + + +int ma_sound_get_max_gain_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_max_gain(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_min_distance_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float minDistance = luaL_checknumber(L, 2); + ma_sound_set_min_distance(pSound, minDistance); + return 0; +} + + +int ma_sound_get_min_distance_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_min_distance(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_max_distance_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float maxDistance = luaL_checknumber(L, 2); + ma_sound_set_max_distance(pSound, maxDistance); + return 0; +} + + +int ma_sound_get_max_distance_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_max_distance(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_cone_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float innerAngleInRadians = luaL_checknumber(L, 2); + float outerAngleInRadians = luaL_checknumber(L, 3); + float outerGain = luaL_checknumber(L, 4); + ma_sound_set_cone(pSound, innerAngleInRadians, outerAngleInRadians, outerGain); + return 0; +} + + +int ma_sound_get_cone_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float * pInnerAngleInRadians = get: float * + float * pOuterAngleInRadians = get: float * + float * pOuterGain = get: float * + ma_sound_get_cone(pSound, pInnerAngleInRadians, pOuterAngleInRadians, pOuterGain); + return 0; +} + + +int ma_sound_set_doppler_factor_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float dopplerFactor = luaL_checknumber(L, 2); + ma_sound_set_doppler_factor(pSound, dopplerFactor); + return 0; +} + + +int ma_sound_get_doppler_factor_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_doppler_factor(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_directional_attenuation_factor_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float directionalAttenuationFactor = luaL_checknumber(L, 2); + ma_sound_set_directional_attenuation_factor(pSound, directionalAttenuationFactor); + return 0; +} + + +int ma_sound_get_directional_attenuation_factor_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + float bind_result = ma_sound_get_directional_attenuation_factor(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_fade_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float volumeBeg = luaL_checknumber(L, 2); + float volumeEnd = luaL_checknumber(L, 3); + ma_uint64 fadeLengthInFrames = luaL_checkinteger(L, 4); + ma_sound_set_fade_in_pcm_frames(pSound, volumeBeg, volumeEnd, fadeLengthInFrames); + return 0; +} + + +int ma_sound_set_fade_in_milliseconds_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float volumeBeg = luaL_checknumber(L, 2); + float volumeEnd = luaL_checknumber(L, 3); + ma_uint64 fadeLengthInMilliseconds = luaL_checkinteger(L, 4); + ma_sound_set_fade_in_milliseconds(pSound, volumeBeg, volumeEnd, fadeLengthInMilliseconds); + return 0; +} + + +int ma_sound_get_current_fade_volume_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float bind_result = ma_sound_get_current_fade_volume(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_start_time_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 absoluteGlobalTimeInFrames = luaL_checkinteger(L, 2); + ma_sound_set_start_time_in_pcm_frames(pSound, absoluteGlobalTimeInFrames); + return 0; +} + + +int ma_sound_set_start_time_in_milliseconds_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 absoluteGlobalTimeInMilliseconds = luaL_checkinteger(L, 2); + ma_sound_set_start_time_in_milliseconds(pSound, absoluteGlobalTimeInMilliseconds); + return 0; +} + + +int ma_sound_set_stop_time_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 absoluteGlobalTimeInFrames = luaL_checkinteger(L, 2); + ma_sound_set_stop_time_in_pcm_frames(pSound, absoluteGlobalTimeInFrames); + return 0; +} + + +int ma_sound_set_stop_time_in_milliseconds_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 absoluteGlobalTimeInMilliseconds = luaL_checkinteger(L, 2); + ma_sound_set_stop_time_in_milliseconds(pSound, absoluteGlobalTimeInMilliseconds); + return 0; +} + + +int ma_sound_is_playing_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_bool32 bind_result = ma_sound_is_playing(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_get_time_in_pcm_frames_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_uint64 bind_result = ma_sound_get_time_in_pcm_frames(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_looping_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_bool32 isLooping = get: ma_bool32 + ma_sound_set_looping(pSound, isLooping); + return 0; +} + + +int ma_sound_is_looping_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_bool32 bind_result = ma_sound_is_looping(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_at_end_bind(lua_State *L) +{ + const ma_sound * pSound = get: const ma_sound * + ma_bool32 bind_result = ma_sound_at_end(pSound); + /* push result */ + return /* count */; +} + + +int ma_sound_seek_to_pcm_frame_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 frameIndex = luaL_checkinteger(L, 2); + ma_result bind_result = ma_sound_seek_to_pcm_frame(pSound, frameIndex); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_data_format_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_format * pFormat = get: ma_format * + ma_uint32 * pChannels = get: ma_uint32 * + ma_uint32 * pSampleRate = get: ma_uint32 * + ma_channel * pChannelMap = get: ma_channel * + size_t channelMapCap = get: size_t + ma_result bind_result = ma_sound_get_data_format(pSound, pFormat, pChannels, pSampleRate, pChannelMap, channelMapCap); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_cursor_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 * pCursor = get: ma_uint64 * + ma_result bind_result = ma_sound_get_cursor_in_pcm_frames(pSound, pCursor); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_length_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + ma_uint64 * pLength = get: ma_uint64 * + ma_result bind_result = ma_sound_get_length_in_pcm_frames(pSound, pLength); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_cursor_in_seconds_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float * pCursor = get: float * + ma_result bind_result = ma_sound_get_cursor_in_seconds(pSound, pCursor); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_length_in_seconds_bind(lua_State *L) +{ + ma_sound * pSound = get: ma_sound * + float * pLength = get: float * + ma_result bind_result = ma_sound_get_length_in_seconds(pSound, pLength); + lua_pushinteger(L, bind_result); + return 1; +} + + diff --git a/src/audio/engine.c b/src/audio/engine.c new file mode 100644 index 0000000..4d2caba --- /dev/null +++ b/src/audio/engine.c @@ -0,0 +1,310 @@ +#include <lua.h> +#include <lauxlib.h> +#include <miniaudio.h> +#include "audio.h" + + +#define GET_PARAM(param) \ +do { \ + lua_getfield(L, conf_tbl, #param); \ + if (!lua_isnil(L, -1)) { \ + config.param = lua_tointeger(L, -1); \ + } \ + lua_pop(L, 1); \ +} while (0) + +int ma_engine_init_bind(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TTABLE); + const int conf_tbl = 1; + ma_engine_config config = ma_engine_config_init(); + GET_PARAM(listenerCount); + GET_PARAM(sampleRate); + GET_PARAM(gainSmoothTimeInFrames); + GET_PARAM(gainSmoothTimeInMilliseconds); + + ma_engine *engine = lua_newuserdata(L, sizeof(ma_engine)); + int engine_index = lua_gettop(L); + ma_result result = ma_engine_init(&config, engine); + lua_pushinteger(L, result); + lua_pushvalue(L, engine_index); + lua_remove(L, engine_index); + return 2; +} + + +int ma_engine_uninit_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_engine_uninit(pEngine); + return 0; +} + + +int ma_engine_get_endpoint_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_node* bind_result = ma_engine_get_endpoint(pEngine); + ma_push_node(L, bind_result); + return 1; +} + + +int ma_engine_get_time_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint64 bind_result = ma_engine_get_time(pEngine); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_set_time_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint64 globalTime = luaL_checkinteger(L, 2); + ma_result bind_result = ma_engine_set_time(pEngine, globalTime); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_get_channels_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 bind_result = ma_engine_get_channels(pEngine); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_get_sample_rate_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 bind_result = ma_engine_get_sample_rate(pEngine); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_start_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_result bind_result = ma_engine_start(pEngine); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_stop_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_result bind_result = ma_engine_stop(pEngine); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_set_volume_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + float volume = luaL_checknumber(L, 2); + ma_result bind_result = ma_engine_set_volume(pEngine, volume); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_set_gain_db_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + float gainDB = luaL_checknumber(L, 2); + ma_result bind_result = ma_engine_set_gain_db(pEngine, gainDB); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_get_listener_count_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 bind_result = ma_engine_get_listener_count(pEngine); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_find_closest_listener_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + float absolutePosX = luaL_checknumber(L, 2); + float absolutePosY = luaL_checknumber(L, 3); + float absolutePosZ = luaL_checknumber(L, 4); + ma_uint32 bind_result = ma_engine_find_closest_listener(pEngine, absolutePosX, absolutePosY, absolutePosZ); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_listener_set_position_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + float x = luaL_checknumber(L, 3); + float y = luaL_checknumber(L, 4); + float z = luaL_checknumber(L, 5); + ma_engine_listener_set_position(pEngine, listenerIndex, x, y, z); + return 0; +} + + +int ma_engine_listener_get_position_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_vec3f bind_result = ma_engine_listener_get_position(pEngine, listenerIndex); + lua_pushnumber(L, bind_result.x); + lua_pushnumber(L, bind_result.y); + lua_pushnumber(L, bind_result.z); + return 3; +} + + +int ma_engine_listener_set_direction_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + float x = luaL_checknumber(L, 3); + float y = luaL_checknumber(L, 4); + float z = luaL_checknumber(L, 5); + ma_engine_listener_set_direction(pEngine, listenerIndex, x, y, z); + return 0; +} + + +int ma_engine_listener_get_direction_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_vec3f bind_result = ma_engine_listener_get_direction(pEngine, listenerIndex); + lua_pushnumber(L, bind_result.x); + lua_pushnumber(L, bind_result.y); + lua_pushnumber(L, bind_result.z); + return 3; +} + + +int ma_engine_listener_set_velocity_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + float x = luaL_checknumber(L, 3); + float y = luaL_checknumber(L, 4); + float z = luaL_checknumber(L, 5); + ma_engine_listener_set_velocity(pEngine, listenerIndex, x, y, z); + return 0; +} + + +int ma_engine_listener_get_velocity_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_vec3f bind_result = ma_engine_listener_get_velocity(pEngine, listenerIndex); + lua_pushnumber(L, bind_result.x); + lua_pushnumber(L, bind_result.y); + lua_pushnumber(L, bind_result.z); + return 3; +} + + +int ma_engine_listener_set_cone_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + float innerAngleInRadians = luaL_checknumber(L, 3); + float outerAngleInRadians = luaL_checknumber(L, 4); + float outerGain = luaL_checknumber(L, 5); + ma_engine_listener_set_cone(pEngine, listenerIndex, innerAngleInRadians, outerAngleInRadians, outerGain); + return 0; +} + + +int ma_engine_listener_get_cone_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + float innerAngleInRadians, outerAngleInRadians, outerGain; + ma_engine_listener_get_cone(pEngine, listenerIndex, &innerAngleInRadians, &outerAngleInRadians, &outerGain); + lua_pushnumber(L, innerAngleInRadians); + lua_pushnumber(L, outerAngleInRadians); + lua_pushnumber(L, outerGain); + return 3; +} + + +int ma_engine_listener_set_world_up_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + float x = luaL_checknumber(L, 3); + float y = luaL_checknumber(L, 4); + float z = luaL_checknumber(L, 5); + ma_engine_listener_set_world_up(pEngine, listenerIndex, x, y, z); + return 0; +} + + +int ma_engine_listener_get_world_up_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_vec3f bind_result = ma_engine_listener_get_world_up(pEngine, listenerIndex); + lua_pushnumber(L, bind_result.x); + lua_pushnumber(L, bind_result.y); + lua_pushnumber(L, bind_result.z); + return 3; +} + + +int ma_engine_listener_set_enabled_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_bool32 isEnabled = luaL_checkinteger(L, 3); + ma_engine_listener_set_enabled(pEngine, listenerIndex, isEnabled); + return 0; +} + + +int ma_engine_listener_is_enabled_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_bool32 bind_result = ma_engine_listener_is_enabled(pEngine, listenerIndex); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_play_sound_ex_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + const char * pFilePath = luaL_checkstring(L, 2); + ma_node * pNode = luaL_checkudata(L, 3, ma_node_tname); + ma_uint32 nodeInputBusIndex = luaL_checkinteger(L, 4); + ma_result bind_result = ma_engine_play_sound_ex(pEngine, pFilePath, pNode, nodeInputBusIndex); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_engine_play_sound_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + const char * pFilePath = luaL_checkstring(L, 2); + ma_sound_group * pGroup = to_sound_group(L, 3); + ma_result bind_result = ma_engine_play_sound(pEngine, pFilePath, pGroup); + lua_pushinteger(L, bind_result); + return 1; +} diff --git a/src/audio/impl.c b/src/audio/impl.c new file mode 100644 index 0000000..5e8969a --- /dev/null +++ b/src/audio/impl.c @@ -0,0 +1,8 @@ +#define STB_VORBIS_HEADER_ONLY +#include <stb_vorbis.c> +#define MINIAUDIO_IMPLEMENTATION +#include <miniaudio.h> +#undef STB_VORBIS_HEADER_ONLY +#include <stb_vorbis.c> + + diff --git a/src/audio/setup.c b/src/audio/setup.c new file mode 100644 index 0000000..774bf39 --- /dev/null +++ b/src/audio/setup.c @@ -0,0 +1,31 @@ +#include <lua.h> +#include <lauxlib.h> +#include <miniaudio.h> +#include "util/util.h" +#include "audio.h" + + +#define X(name, mt) const char *mt = name; +AUDIO_METATABLES +#undef X + + +void setup_audio(lua_State *L, int honey_tbl) +{ + #define X(n, mt) luaL_newmetatable(L, mt); lua_pop(L, 1); + AUDIO_METATABLES + #undef X + + struct honey_tbl_t audio[] = { + #define X(name, func) H_FUNC(name, func), + AUDIO_FUNCTIONS + #undef X + + /* ma_result values */ + H_ENUM(MA_SUCCESS), + + H_END, + }; + create_table(L, audio); + lua_setfield(L, honey_tbl, "ma"); +} diff --git a/src/audio/sound.c b/src/audio/sound.c new file mode 100644 index 0000000..334a08a --- /dev/null +++ b/src/audio/sound.c @@ -0,0 +1,640 @@ +#include <lua.h> +#include <lauxlib.h> +#include <miniaudio.h> +#include "audio.h" + + +void push_sound(lua_State *L, ma_sound s) { + ma_sound *su = lua_newuserdata(L, sizeof(ma_sound)); + *su = s; + luaL_getmetatable(L, ma_sound_tname); + lua_setmetatable(L, -2); +} + + +int ma_sound_init_from_file_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + const char * pFilePath = luaL_checkstring(L, 2); + ma_uint32 flags = luaL_checkinteger(L, 3); + ma_sound_group * pGroup = to_sound_group(L, 4); + + ma_sound *sound = lua_newuserdata(L, sizeof(ma_sound)); + int sound_index = lua_gettop(L); + ma_result bind_result = ma_sound_init_from_file(pEngine, pFilePath, flags, pGroup, NULL, sound); + lua_pushinteger(L, bind_result); + lua_pushvalue(L, sound_index); + lua_remove(L, sound_index); + luaL_getmetatable(L, ma_sound_tname); + lua_setmetatable(L, -2); + return 2; +} + + +int ma_sound_init_copy_bind(lua_State *L) +{ + ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname); + ma_sound * pExistingSound = luaL_checkudata(L, 2, ma_sound_tname); + ma_uint32 flags = luaL_checkinteger(L, 3); + ma_sound_group * pGroup = to_sound_group(L, 4); + ma_sound *sound = lua_newuserdata(L, sizeof(ma_sound)); + int sound_index = lua_gettop(L); + ma_result bind_result = ma_sound_init_copy(pEngine, pExistingSound, flags, pGroup, sound); + lua_pushinteger(L, bind_result); + lua_pushvalue(L, sound_index); + lua_remove(L, sound_index); + luaL_getmetatable(L, ma_sound_tname); + lua_setmetatable(L, -2); + return 2; +} + + +int ma_sound_uninit_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_sound_uninit(pSound); + return 0; +} + + +int ma_sound_start_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_result bind_result = ma_sound_start(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_stop_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_result bind_result = ma_sound_stop(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_volume_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float volume = luaL_checknumber(L, 2); + ma_sound_set_volume(pSound, volume); + return 0; +} + + +int ma_sound_get_volume_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_volume(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_pan_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float pan = luaL_checknumber(L, 2); + ma_sound_set_pan(pSound, pan); + return 0; +} + + +int ma_sound_get_pan_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_pan(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_pan_mode_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_pan_mode panMode = luaL_checkinteger(L, 2); + ma_sound_set_pan_mode(pSound, panMode); + return 0; +} + + +int ma_sound_get_pan_mode_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_pan_mode bind_result = ma_sound_get_pan_mode(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_pitch_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float pitch = luaL_checknumber(L, 2); + ma_sound_set_pitch(pSound, pitch); + return 0; +} + + +int ma_sound_get_pitch_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_pitch(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_spatialization_enabled_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_bool32 enabled = lua_toboolean(L, 2); + ma_sound_set_spatialization_enabled(pSound, enabled); + return 0; +} + + +int ma_sound_is_spatialization_enabled_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_bool32 bind_result = ma_sound_is_spatialization_enabled(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_pinned_listener_index_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint32 listenerIndex = luaL_checkinteger(L, 2); + ma_sound_set_pinned_listener_index(pSound, listenerIndex); + return 0; +} + + +int ma_sound_get_pinned_listener_index_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint32 bind_result = ma_sound_get_pinned_listener_index(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_listener_index_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint32 bind_result = ma_sound_get_listener_index(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_direction_to_listener_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_vec3f bind_result = ma_sound_get_direction_to_listener(pSound); + lua_pushinteger(L, bind_result.x); + lua_pushinteger(L, bind_result.y); + lua_pushinteger(L, bind_result.z); + return 3; +} + + +int ma_sound_set_position_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + ma_sound_set_position(pSound, x, y, z); + return 0; +} + + +int ma_sound_get_position_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_vec3f bind_result = ma_sound_get_position(pSound); + lua_pushinteger(L, bind_result.x); + lua_pushinteger(L, bind_result.y); + lua_pushinteger(L, bind_result.z); + return 3; +} + + +int ma_sound_set_direction_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + ma_sound_set_direction(pSound, x, y, z); + return 0; +} + + +int ma_sound_get_direction_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_vec3f bind_result = ma_sound_get_direction(pSound); + lua_pushinteger(L, bind_result.x); + lua_pushinteger(L, bind_result.y); + lua_pushinteger(L, bind_result.z); + return 3; +} + + +int ma_sound_set_velocity_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + ma_sound_set_velocity(pSound, x, y, z); + return 0; +} + + +int ma_sound_get_velocity_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_vec3f bind_result = ma_sound_get_velocity(pSound); + lua_pushinteger(L, bind_result.x); + lua_pushinteger(L, bind_result.y); + lua_pushinteger(L, bind_result.z); + return 3; +} + + +int ma_sound_set_attenuation_model_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_attenuation_model attenuationModel = luaL_checkinteger(L, 2); + ma_sound_set_attenuation_model(pSound, attenuationModel); + return 0; +} + + +int ma_sound_get_attenuation_model_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_attenuation_model bind_result = ma_sound_get_attenuation_model(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_positioning_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_positioning positioning = luaL_checkinteger(L, 2); + ma_sound_set_positioning(pSound, positioning); + return 0; +} + + +int ma_sound_get_positioning_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_positioning bind_result = ma_sound_get_positioning(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_rolloff_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float rolloff = luaL_checknumber(L, 2); + ma_sound_set_rolloff(pSound, rolloff); + return 0; +} + + +int ma_sound_get_rolloff_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_rolloff(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_min_gain_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float minGain = luaL_checknumber(L, 2); + ma_sound_set_min_gain(pSound, minGain); + return 0; +} + + +int ma_sound_get_min_gain_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_min_gain(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_max_gain_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float maxGain = luaL_checknumber(L, 2); + ma_sound_set_max_gain(pSound, maxGain); + return 0; +} + + +int ma_sound_get_max_gain_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_max_gain(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_min_distance_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float minDistance = luaL_checknumber(L, 2); + ma_sound_set_min_distance(pSound, minDistance); + return 0; +} + + +int ma_sound_get_min_distance_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_min_distance(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_max_distance_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float maxDistance = luaL_checknumber(L, 2); + ma_sound_set_max_distance(pSound, maxDistance); + return 0; +} + + +int ma_sound_get_max_distance_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_max_distance(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_cone_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float innerAngleInRadians = luaL_checknumber(L, 2); + float outerAngleInRadians = luaL_checknumber(L, 3); + float outerGain = luaL_checknumber(L, 4); + ma_sound_set_cone(pSound, innerAngleInRadians, outerAngleInRadians, outerGain); + return 0; +} + + +int ma_sound_get_cone_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float innerAngleInRadians, outerAngleInRadians, outerGain; + ma_sound_get_cone(pSound, &innerAngleInRadians, &outerAngleInRadians, &outerGain); + lua_pushnumber(L, innerAngleInRadians); + lua_pushnumber(L, outerAngleInRadians); + lua_pushnumber(L, outerGain); + return 3; +} + + +int ma_sound_set_doppler_factor_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float dopplerFactor = luaL_checknumber(L, 2); + ma_sound_set_doppler_factor(pSound, dopplerFactor); + return 0; +} + + +int ma_sound_get_doppler_factor_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_doppler_factor(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_directional_attenuation_factor_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float directionalAttenuationFactor = luaL_checknumber(L, 2); + ma_sound_set_directional_attenuation_factor(pSound, directionalAttenuationFactor); + return 0; +} + + +int ma_sound_get_directional_attenuation_factor_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_directional_attenuation_factor(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_fade_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float volumeBeg = luaL_checknumber(L, 2); + float volumeEnd = luaL_checknumber(L, 3); + ma_uint64 fadeLengthInFrames = luaL_checkinteger(L, 4); + ma_sound_set_fade_in_pcm_frames(pSound, volumeBeg, volumeEnd, fadeLengthInFrames); + return 0; +} + + +int ma_sound_set_fade_in_milliseconds_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float volumeBeg = luaL_checknumber(L, 2); + float volumeEnd = luaL_checknumber(L, 3); + ma_uint64 fadeLengthInMilliseconds = luaL_checkinteger(L, 4); + ma_sound_set_fade_in_milliseconds(pSound, volumeBeg, volumeEnd, fadeLengthInMilliseconds); + return 0; +} + + +int ma_sound_get_current_fade_volume_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float bind_result = ma_sound_get_current_fade_volume(pSound); + lua_pushnumber(L, bind_result); + return 1; +} + + +int ma_sound_set_start_time_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 absoluteGlobalTimeInFrames = luaL_checkinteger(L, 2); + ma_sound_set_start_time_in_pcm_frames(pSound, absoluteGlobalTimeInFrames); + return 0; +} + + +int ma_sound_set_start_time_in_milliseconds_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 absoluteGlobalTimeInMilliseconds = luaL_checkinteger(L, 2); + ma_sound_set_start_time_in_milliseconds(pSound, absoluteGlobalTimeInMilliseconds); + return 0; +} + + +int ma_sound_set_stop_time_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 absoluteGlobalTimeInFrames = luaL_checkinteger(L, 2); + ma_sound_set_stop_time_in_pcm_frames(pSound, absoluteGlobalTimeInFrames); + return 0; +} + + +int ma_sound_set_stop_time_in_milliseconds_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 absoluteGlobalTimeInMilliseconds = luaL_checkinteger(L, 2); + ma_sound_set_stop_time_in_milliseconds(pSound, absoluteGlobalTimeInMilliseconds); + return 0; +} + + +int ma_sound_is_playing_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_bool32 bind_result = ma_sound_is_playing(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_time_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 bind_result = ma_sound_get_time_in_pcm_frames(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_set_looping_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_bool32 isLooping = luaL_checkinteger(L, 2); + ma_sound_set_looping(pSound, isLooping); + return 0; +} + + +int ma_sound_is_looping_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_bool32 bind_result = ma_sound_is_looping(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_at_end_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_bool32 bind_result = ma_sound_at_end(pSound); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_seek_to_pcm_frame_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 frameIndex = luaL_checkinteger(L, 2); + ma_result bind_result = ma_sound_seek_to_pcm_frame(pSound, frameIndex); + lua_pushinteger(L, bind_result); + return 1; +} + + +int ma_sound_get_data_format_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_format format; + ma_uint32 channels; + ma_uint32 sampleRate; + ma_channel channelMap; + size_t channelMapCap = 0; + ma_result bind_result = ma_sound_get_data_format(pSound, &format, &channels, &sampleRate, &channelMap, channelMapCap); + lua_pushinteger(L, bind_result); + lua_pushinteger(L, format); + lua_pushinteger(L, channels); + lua_pushinteger(L, sampleRate); + lua_pushinteger(L, channelMap); + return 5; +} + + +int ma_sound_get_cursor_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 cursor; + ma_result bind_result = ma_sound_get_cursor_in_pcm_frames(pSound, &cursor); + lua_pushinteger(L, bind_result); + lua_pushinteger(L, cursor); + return 2; +} + + +int ma_sound_get_length_in_pcm_frames_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + ma_uint64 length; + ma_result bind_result = ma_sound_get_length_in_pcm_frames(pSound, &length); + lua_pushinteger(L, bind_result); + lua_pushinteger(L, length); + return 2; +} + + +int ma_sound_get_cursor_in_seconds_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float cursor; + ma_result bind_result = ma_sound_get_cursor_in_seconds(pSound, &cursor); + lua_pushinteger(L, bind_result); + lua_pushnumber(L, cursor); + return 2; +} + + +int ma_sound_get_length_in_seconds_bind(lua_State *L) +{ + ma_sound * pSound = luaL_checkudata(L, 1, ma_sound_tname); + float length; + ma_result bind_result = ma_sound_get_length_in_seconds(pSound, &length); + lua_pushinteger(L, bind_result); + lua_pushnumber(L, length); + return 2; +} + + |