diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py
index 9a9f7d53a..1c0e74807 100644
--- a/autogen/convert_functions.py
+++ b/autogen/convert_functions.py
@@ -130,7 +130,7 @@ override_disallowed_functions = {
"src/pc/lua/utils/smlua_obj_utils.h": [ "spawn_object_remember_field" ],
"src/game/camera.h": [ "geo_", "update_camera", "init_camera", "stub_camera", "^reset_camera", "move_point_along_spline", "romhack_camera_init_settings", "romhack_camera_reset_settings" ],
"src/game/behavior_actions.h": [ "bhv_dust_smoke_loop", "bhv_init_room", "geo_" ],
- "src/pc/lua/utils/smlua_audio_utils.h": [ "smlua_audio_utils_override", "audio_custom_shutdown", "smlua_audio_custom_deinit", "audio_sample_destroy_pending_copies", "audio_custom_update_volume" ],
+ "src/pc/lua/utils/smlua_audio_utils.h": [ "smlua_audio_utils_override", "audio_custom_shutdown", "smlua_audio_custom_deinit", "audio_sample_destroy_pending_copies", "audio_custom_update_volume", "audio_custom_update_mute" ],
"src/pc/lua/utils/smlua_level_utils.h": [ "smlua_level_util_reset" ],
"src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_init", "smlua_text_utils_shutdown", "smlua_text_utils_dialog_get_unmodified"],
"src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_reset", "smlua_anim_util_register_animation" ],
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 08b0b1587..d72bb35a4 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -10275,6 +10275,13 @@ function audio_stream_set_looping(audio, looping)
-- ...
end
+--- @param audio ModAudio
+--- @return table
+--- Gets an `audio` stream's loop points in samples
+function audio_stream_get_loop_points(audio)
+ -- ...
+end
+
--- @param audio ModAudio
--- @param loopStart integer
--- @param loopEnd integer
@@ -10701,6 +10708,7 @@ function smlua_collision_util_get_level_collision(level, area)
end
--- @param data Pointer_Collision
+--- @return table
--- Gets a table of the surface types from `data`
function smlua_collision_util_find_surface_types(data)
-- ...
@@ -11578,49 +11586,49 @@ function get_coopnet_id(localIndex)
-- ...
end
---- @return number
+--- @return integer
--- Gets the master volume level
function get_volume_master()
-- ...
end
---- @return number
+--- @return integer
--- Gets the volume level of music
function get_volume_level()
-- ...
end
---- @return number
+--- @return integer
--- Gets the volume level of sound effects
function get_volume_sfx()
-- ...
end
---- @return number
+--- @return integer
--- Gets the volume level of environment sounds effects
function get_volume_env()
-- ...
end
---- @param volume number
+--- @param volume integer
--- Sets the master volume level
function set_volume_master(volume)
-- ...
end
---- @param volume number
+--- @param volume integer
--- Sets the volume level of music
function set_volume_level(volume)
-- ...
end
---- @param volume number
+--- @param volume integer
--- Sets the volume level of sound effects
function set_volume_sfx(volume)
-- ...
end
---- @param volume number
+--- @param volume integer
--- Sets the volume level of environment sounds effects
function set_volume_env(volume)
-- ...
diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md
index a639b7db9..b0ecc707a 100644
--- a/docs/lua/functions-6.md
+++ b/docs/lua/functions-6.md
@@ -5848,6 +5848,29 @@ Sets if an `audio` stream is looping or not
+## [audio_stream_get_loop_points](#audio_stream_get_loop_points)
+
+### Description
+Gets an `audio` stream's loop points in samples
+
+### Lua Example
+`local tableValue = audio_stream_get_loop_points(audio)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| audio | [ModAudio](structs.md#ModAudio) |
+
+### Returns
+- `table`
+
+### C Prototype
+`LuaTable audio_stream_get_loop_points(struct ModAudio* audio);`
+
+[:arrow_up_small:](#)
+
+
+
## [audio_stream_set_loop_points](#audio_stream_set_loop_points)
### Description
@@ -7382,7 +7405,7 @@ Gets the `level` terrain collision from `area`
Gets a table of the surface types from `data`
### Lua Example
-`smlua_collision_util_find_surface_types(data)`
+`local tableValue = smlua_collision_util_find_surface_types(data)`
### Parameters
| Field | Type |
@@ -7390,10 +7413,10 @@ Gets a table of the surface types from `data`
| data | `Pointer` <`Collision`> |
### Returns
-- None
+- `table`
### C Prototype
-`void smlua_collision_util_find_surface_types(Collision* data);`
+`LuaTable smlua_collision_util_find_surface_types(Collision* data);`
[:arrow_up_small:](#)
diff --git a/docs/lua/functions-7.md b/docs/lua/functions-7.md
index 1dd27c2d7..f2c56c139 100644
--- a/docs/lua/functions-7.md
+++ b/docs/lua/functions-7.md
@@ -1846,16 +1846,16 @@ Gets the CoopNet ID of a player with `localIndex` if CoopNet is being used and t
Gets the master volume level
### Lua Example
-`local numberValue = get_volume_master()`
+`local integerValue = get_volume_master()`
### Parameters
- None
### Returns
-- `number`
+- `integer`
### C Prototype
-`f32 get_volume_master(void);`
+`u8 get_volume_master(void);`
[:arrow_up_small:](#)
@@ -1867,16 +1867,16 @@ Gets the master volume level
Gets the volume level of music
### Lua Example
-`local numberValue = get_volume_level()`
+`local integerValue = get_volume_level()`
### Parameters
- None
### Returns
-- `number`
+- `integer`
### C Prototype
-`f32 get_volume_level(void);`
+`u8 get_volume_level(void);`
[:arrow_up_small:](#)
@@ -1888,16 +1888,16 @@ Gets the volume level of music
Gets the volume level of sound effects
### Lua Example
-`local numberValue = get_volume_sfx()`
+`local integerValue = get_volume_sfx()`
### Parameters
- None
### Returns
-- `number`
+- `integer`
### C Prototype
-`f32 get_volume_sfx(void);`
+`u8 get_volume_sfx(void);`
[:arrow_up_small:](#)
@@ -1909,16 +1909,16 @@ Gets the volume level of sound effects
Gets the volume level of environment sounds effects
### Lua Example
-`local numberValue = get_volume_env()`
+`local integerValue = get_volume_env()`
### Parameters
- None
### Returns
-- `number`
+- `integer`
### C Prototype
-`f32 get_volume_env(void);`
+`u8 get_volume_env(void);`
[:arrow_up_small:](#)
@@ -1935,13 +1935,13 @@ Sets the master volume level
### Parameters
| Field | Type |
| ----- | ---- |
-| volume | `number` |
+| volume | `integer` |
### Returns
- None
### C Prototype
-`void set_volume_master(f32 volume);`
+`void set_volume_master(u8 volume);`
[:arrow_up_small:](#)
@@ -1958,13 +1958,13 @@ Sets the volume level of music
### Parameters
| Field | Type |
| ----- | ---- |
-| volume | `number` |
+| volume | `integer` |
### Returns
- None
### C Prototype
-`void set_volume_level(f32 volume);`
+`void set_volume_level(u8 volume);`
[:arrow_up_small:](#)
@@ -1981,13 +1981,13 @@ Sets the volume level of sound effects
### Parameters
| Field | Type |
| ----- | ---- |
-| volume | `number` |
+| volume | `integer` |
### Returns
- None
### C Prototype
-`void set_volume_sfx(f32 volume);`
+`void set_volume_sfx(u8 volume);`
[:arrow_up_small:](#)
@@ -2004,13 +2004,13 @@ Sets the volume level of environment sounds effects
### Parameters
| Field | Type |
| ----- | ---- |
-| volume | `number` |
+| volume | `integer` |
### Returns
- None
### C Prototype
-`void set_volume_env(f32 volume);`
+`void set_volume_env(u8 volume);`
[:arrow_up_small:](#)
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index b463ac63e..9e23bfdfe 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1838,6 +1838,7 @@
- [audio_stream_set_position](functions-6.md#audio_stream_set_position)
- [audio_stream_get_looping](functions-6.md#audio_stream_get_looping)
- [audio_stream_set_looping](functions-6.md#audio_stream_set_looping)
+ - [audio_stream_get_loop_points](functions-6.md#audio_stream_get_loop_points)
- [audio_stream_set_loop_points](functions-6.md#audio_stream_set_loop_points)
- [audio_stream_get_frequency](functions-6.md#audio_stream_get_frequency)
- [audio_stream_set_frequency](functions-6.md#audio_stream_set_frequency)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 54bb0672b..0dd08aec3 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -30600,6 +30600,23 @@ int smlua_func_audio_stream_set_looping(lua_State* L) {
return 1;
}
+int smlua_func_audio_stream_get_loop_points(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "audio_stream_get_loop_points", 1, top);
+ return 0;
+ }
+
+ struct ModAudio* audio = (struct ModAudio*)smlua_to_cobject(L, 1, LOT_MODAUDIO);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "audio_stream_get_loop_points"); return 0; }
+
+ smlua_push_lua_table(L, audio_stream_get_loop_points(audio));
+
+ return 1;
+}
+
int smlua_func_audio_stream_set_loop_points(lua_State* L) {
if (L == NULL) { return 0; }
@@ -31742,7 +31759,7 @@ int smlua_func_smlua_collision_util_find_surface_types(lua_State* L) {
Collision* data = (Collision*)smlua_to_cpointer(L, 1, LVT_COLLISION_P);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "smlua_collision_util_find_surface_types"); return 0; }
- smlua_collision_util_find_surface_types(data);
+ smlua_push_lua_table(L, smlua_collision_util_find_surface_types(data));
return 1;
}
@@ -34130,7 +34147,7 @@ int smlua_func_get_volume_master(UNUSED lua_State* L) {
}
- lua_pushnumber(L, get_volume_master());
+ lua_pushinteger(L, get_volume_master());
return 1;
}
@@ -34145,7 +34162,7 @@ int smlua_func_get_volume_level(UNUSED lua_State* L) {
}
- lua_pushnumber(L, get_volume_level());
+ lua_pushinteger(L, get_volume_level());
return 1;
}
@@ -34160,7 +34177,7 @@ int smlua_func_get_volume_sfx(UNUSED lua_State* L) {
}
- lua_pushnumber(L, get_volume_sfx());
+ lua_pushinteger(L, get_volume_sfx());
return 1;
}
@@ -34175,7 +34192,7 @@ int smlua_func_get_volume_env(UNUSED lua_State* L) {
}
- lua_pushnumber(L, get_volume_env());
+ lua_pushinteger(L, get_volume_env());
return 1;
}
@@ -34189,7 +34206,7 @@ int smlua_func_set_volume_master(lua_State* L) {
return 0;
}
- f32 volume = smlua_to_number(L, 1);
+ u8 volume = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_master"); return 0; }
set_volume_master(volume);
@@ -34206,7 +34223,7 @@ int smlua_func_set_volume_level(lua_State* L) {
return 0;
}
- f32 volume = smlua_to_number(L, 1);
+ u8 volume = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_level"); return 0; }
set_volume_level(volume);
@@ -34223,7 +34240,7 @@ int smlua_func_set_volume_sfx(lua_State* L) {
return 0;
}
- f32 volume = smlua_to_number(L, 1);
+ u8 volume = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_sfx"); return 0; }
set_volume_sfx(volume);
@@ -34240,7 +34257,7 @@ int smlua_func_set_volume_env(lua_State* L) {
return 0;
}
- f32 volume = smlua_to_number(L, 1);
+ u8 volume = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_env"); return 0; }
set_volume_env(volume);
@@ -38495,6 +38512,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "audio_stream_set_position", smlua_func_audio_stream_set_position);
smlua_bind_function(L, "audio_stream_get_looping", smlua_func_audio_stream_get_looping);
smlua_bind_function(L, "audio_stream_set_looping", smlua_func_audio_stream_set_looping);
+ smlua_bind_function(L, "audio_stream_get_loop_points", smlua_func_audio_stream_get_loop_points);
smlua_bind_function(L, "audio_stream_set_loop_points", smlua_func_audio_stream_set_loop_points);
smlua_bind_function(L, "audio_stream_get_frequency", smlua_func_audio_stream_get_frequency);
smlua_bind_function(L, "audio_stream_set_frequency", smlua_func_audio_stream_set_frequency);
diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c
index 9b02de52e..65c6adc74 100644
--- a/src/pc/lua/utils/smlua_audio_utils.c
+++ b/src/pc/lua/utils/smlua_audio_utils.c
@@ -20,6 +20,7 @@
#include "pc/fs/fmem.h"
#include "audio/load.h"
+#pragma region m64
struct AudioOverride {
bool enabled;
bool loaded;
@@ -172,6 +173,7 @@ void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolu
LOG_LUA_LINE("Could not find m64 at path: %s", m64path);
}
+#pragma endregion
u8 smlua_audio_utils_allocate_sequence(void) {
for (u8 seqId = SEQ_COUNT + 1; seqId < MAX_AUDIO_OVERRIDE; seqId++) {
@@ -192,6 +194,8 @@ u8 smlua_audio_utils_allocate_sequence(void) {
#define MA_SOUND_SAMPLE_FLAGS (MA_SOUND_FLAG_NO_SPATIALIZATION | MA_SOUND_FLAG_NO_PITCH | MA_SOUND_FLAG_DECODE) // No pitch, pre-decode audio samples
static ma_engine sModAudioEngine;
+static ma_sound_group sModAudioStreamGroup;
+static ma_sound_group sModAudioSampleGroup;
static struct DynamicPool *sModAudioPool;
static void smlua_audio_custom_init(void) {
@@ -201,6 +205,13 @@ static void smlua_audio_custom_init(void) {
if (result != MA_SUCCESS) {
LOG_ERROR("failed to init Miniaudio: %d", result);
}
+
+ ma_sound_group_init(&sModAudioEngine, 0, NULL, &sModAudioStreamGroup);
+ ma_sound_group_init(&sModAudioEngine, 0, NULL, &sModAudioSampleGroup);
+ f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
+ f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
+ ma_sound_group_set_volume(&sModAudioStreamGroup, musicVolume);
+ ma_sound_group_set_volume(&sModAudioSampleGroup, sfxVolume);
}
static struct ModAudio* find_mod_audio(const char *filepath) {
@@ -263,7 +274,7 @@ struct ModAudio* audio_load_internal(const char* filename, bool isStream) {
u16 fileCount = gLuaActiveMod->fileCount;
for (u16 i = 0; i < fileCount; i++) {
struct ModFile* file = &gLuaActiveMod->files[i];
- if(path_ends_with(file->relativePath, normPath)) {
+ if (path_ends_with(file->relativePath, normPath)) {
foundModFile = true;
modFile = file;
break;
@@ -358,7 +369,7 @@ struct ModAudio* audio_load_internal(const char* filename, bool isStream) {
result = ma_sound_init_from_data_source(
&sModAudioEngine, &audio->decoder,
isStream ? MA_SOUND_STREAM_FLAGS : MA_SOUND_SAMPLE_FLAGS,
- NULL, &audio->sound
+ isStream ? &sModAudioStreamGroup : &sModAudioSampleGroup, &audio->sound
);
if (result != MA_SUCCESS) {
free(buffer);
@@ -387,12 +398,7 @@ void audio_stream_destroy(struct ModAudio* audio) {
void audio_stream_play(struct ModAudio* audio, bool restart, f32 volume) {
if (!audio_sanity_check(audio, true, "play")) { return; }
- if (configMuteFocusLoss && !WAPI.has_focus()) {
- ma_sound_set_volume(&audio->sound, 0);
- } else {
- f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
- ma_sound_set_volume(&audio->sound, gMasterVolume * musicVolume * volume);
- }
+ ma_sound_set_volume(&audio->sound, volume);
audio->baseVolume = volume;
if (restart || !ma_sound_is_playing(&audio->sound)) { ma_sound_seek_to_pcm_frame(&audio->sound, 0); }
ma_sound_start(&audio->sound);
@@ -436,13 +442,30 @@ void audio_stream_set_looping(struct ModAudio* audio, bool looping) {
ma_sound_set_looping(&audio->sound, looping);
}
-void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, s64 loopEnd) {
+LuaTable audio_stream_get_loop_points(struct ModAudio* audio) {
+ struct lua_State *L = gLuaState;
+ if (!L || !audio_sanity_check(audio, true, "get stream loop points for")) { return 0; }
+
+ u64 loopStart, loopEnd;
+ ma_data_source_get_loop_point_in_pcm_frames(&audio->decoder, &loopStart, &loopEnd);
+
+ lua_newtable(L);
+ lua_pushinteger(L, loopStart);
+ lua_rawseti(L, -2, 1);
+ lua_pushinteger(L, loopEnd);
+ lua_rawseti(L, -2, 2);
+
+ return smlua_to_lua_table(L, -1);
+}
+
+void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, OPTIONAL s64 loopEnd) {
if (!audio_sanity_check(audio, true, "set stream loop points for")) { return; }
u64 length; ma_data_source_get_length_in_pcm_frames(&audio->decoder, &length);
if (loopStart < 0) loopStart += length;
if (loopEnd <= 0) loopEnd += length;
+ ma_sound_set_looping(&audio->sound, true);
ma_data_source_set_loop_point_in_pcm_frames(&audio->decoder, loopStart, loopEnd);
}
@@ -480,12 +503,7 @@ f32 audio_stream_get_volume(struct ModAudio* audio) {
void audio_stream_set_volume(struct ModAudio* audio, f32 volume) {
if (!audio_sanity_check(audio, true, "set stream volume for")) { return; }
- if (configMuteFocusLoss && !WAPI.has_focus()) {
- ma_sound_set_volume(&audio->sound, 0);
- } else {
- f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
- ma_sound_set_volume(&audio->sound, gMasterVolume * musicVolume * volume);
- }
+ ma_sound_set_volume(&audio->sound, volume);
audio->baseVolume = volume;
}
@@ -588,7 +606,7 @@ void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume) {
struct ModAudioSampleCopies* copy = calloc(1, sizeof(struct ModAudioSampleCopies));
ma_result result = ma_decoder_init_memory(audio->buffer, audio->bufferSize, NULL, ©->decoder);
if (result != MA_SUCCESS) { return; }
- result = ma_sound_init_from_data_source(&sModAudioEngine, ©->decoder, MA_SOUND_SAMPLE_FLAGS, NULL, ©->sound);
+ result = ma_sound_init_from_data_source(&sModAudioEngine, ©->decoder, MA_SOUND_SAMPLE_FLAGS, &sModAudioSampleGroup, ©->sound);
if (result != MA_SUCCESS) { return; }
ma_sound_set_end_callback(©->sound, audio_sample_copy_end_callback, copy);
copy->parent = audio;
@@ -618,33 +636,32 @@ void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume) {
pan = (get_sound_pan(mtx[3][0] * factor, mtx[3][2] * factor) - 0.5f) * 2.0f;
}
- if (configMuteFocusLoss && !WAPI.has_focus()) {
- ma_sound_set_volume(sound, 0);
- } else {
- f32 intensity = sound_get_level_intensity(dist);
- f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
- ma_sound_set_volume(sound, gMasterVolume * sfxVolume * volume * intensity);
- }
+ f32 intensity = sound_get_level_intensity(dist);
+ ma_sound_set_volume(sound, volume * intensity);
ma_sound_set_pan(sound, pan);
audio->baseVolume = volume;
ma_sound_start(sound);
}
+static bool sModAudioMute = false;
void audio_custom_update_volume(void) {
gMasterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
if (!sModAudioPool) { return; }
+ ma_engine_set_volume(&sModAudioEngine, sModAudioMute ? 0 : gMasterVolume);
+
f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
- struct DynamicPoolNode* node = sModAudioPool->tail;
- while (node) {
- struct DynamicPoolNode* prev = node->prev;
- struct ModAudio* audio = node->ptr;
- if (configMuteFocusLoss && !WAPI.has_focus()) {
- ma_sound_set_volume(&audio->sound, 0);
- } else if (audio->isStream) {
- ma_sound_set_volume(&audio->sound, gMasterVolume * musicVolume * audio->baseVolume);
- }
- node = prev;
+ f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
+ ma_sound_group_set_volume(&sModAudioStreamGroup, musicVolume);
+ ma_sound_group_set_volume(&sModAudioSampleGroup, sfxVolume);
+}
+
+void audio_custom_update_mute(bool mute) {
+ if (!sModAudioPool) { return; }
+
+ if (sModAudioMute != mute) {
+ sModAudioMute = mute;
+ ma_engine_set_volume(&sModAudioEngine, mute ? 0 : gMasterVolume);
}
}
@@ -671,6 +688,8 @@ void smlua_audio_custom_deinit(void) {
if (sModAudioPool) {
audio_custom_shutdown();
free(sModAudioPool);
+ ma_sound_group_uninit(&sModAudioStreamGroup);
+ ma_sound_group_uninit(&sModAudioSampleGroup);
ma_engine_uninit(&sModAudioEngine);
sModAudioPool = NULL;
}
diff --git a/src/pc/lua/utils/smlua_audio_utils.h b/src/pc/lua/utils/smlua_audio_utils.h
index 93696c80d..c6075fcb0 100644
--- a/src/pc/lua/utils/smlua_audio_utils.h
+++ b/src/pc/lua/utils/smlua_audio_utils.h
@@ -1,6 +1,11 @@
#ifndef SMLUA_AUDIO_UTILS_H
#define SMLUA_AUDIO_UTILS_H
+#include "pc/lua/smlua_utils.h"
+
+#define MA_NO_RESOURCE_MANAGER
+#define MA_NO_GENERATION
+#define MA_NO_ENCODING
#include "pc/utils/miniaudio.h"
/* |description|Resets all custom sequences back to vanilla|descriptionEnd| */
@@ -53,6 +58,8 @@ void audio_stream_set_position(struct ModAudio* audio, f32 pos);
bool audio_stream_get_looping(struct ModAudio* audio);
/* |description|Sets if an `audio` stream is looping or not|descriptionEnd| */
void audio_stream_set_looping(struct ModAudio* audio, bool looping);
+/* |description|Gets an `audio` stream's loop points in samples|descriptionEnd| */
+LuaTable audio_stream_get_loop_points(struct ModAudio* audio);
/* |description|Sets an `audio` stream's loop points in samples|descriptionEnd| */
void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, s64 loopEnd);
/* |description|Gets the frequency of an `audio` stream|descriptionEnd| */
@@ -75,6 +82,7 @@ void audio_sample_stop(struct ModAudio* audio);
void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume);
void audio_custom_update_volume(void);
+void audio_custom_update_mute(bool mute);
void audio_custom_shutdown(void);
void smlua_audio_custom_deinit(void);
diff --git a/src/pc/lua/utils/smlua_collision_utils.c b/src/pc/lua/utils/smlua_collision_utils.c
index 0a83bc172..2888ee45f 100644
--- a/src/pc/lua/utils/smlua_collision_utils.c
+++ b/src/pc/lua/utils/smlua_collision_utils.c
@@ -209,7 +209,7 @@ Collision *smlua_collision_util_get_level_collision(u32 level, u16 area) {
return dynos_level_get_collision(level, area);
}
-void smlua_collision_util_find_surface_types(Collision* data) {
+LuaTable smlua_collision_util_find_surface_types(Collision* data) {
lua_State* L = gLuaState;
if (data && *data++ == COL_INIT()) {
@@ -231,11 +231,12 @@ void smlua_collision_util_find_surface_types(Collision* data) {
lua_pushinteger(L, surfaceType);
lua_settable(L, t);
}
- return;
+ return smlua_to_lua_table(L, -1);
}
// Couldn't find anything
lua_pushnil(L);
+ return 0;
}
bool surface_is_quicksand(struct Surface* surf) {
diff --git a/src/pc/lua/utils/smlua_collision_utils.h b/src/pc/lua/utils/smlua_collision_utils.h
index 8836a7162..0c4bb1652 100644
--- a/src/pc/lua/utils/smlua_collision_utils.h
+++ b/src/pc/lua/utils/smlua_collision_utils.h
@@ -1,6 +1,7 @@
#ifndef SMLUA_COLLISION_UTILS_H
#define SMLUA_COLLISION_UTILS_H
+#include "pc/lua/smlua_utils.h"
#include "engine/surface_collision.h"
struct RayIntersectionInfo {
@@ -140,7 +141,7 @@ Collision* smlua_collision_util_get_current_terrain_collision(void);
Collision *smlua_collision_util_get_level_collision(u32 level, u16 area);
/* |description|Gets a table of the surface types from `data`|descriptionEnd| */
-void smlua_collision_util_find_surface_types(Collision* data);
+LuaTable smlua_collision_util_find_surface_types(Collision* data);
/* |description|Checks if the surface is quicksand|descriptionEnd| */
bool surface_is_quicksand(struct Surface* surf);
diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c
index 9e90a45fb..08a9c8c5e 100644
--- a/src/pc/lua/utils/smlua_misc_utils.c
+++ b/src/pc/lua/utils/smlua_misc_utils.c
@@ -524,38 +524,38 @@ const char* get_coopnet_id(UNUSED s8 localIndex) {
///
-f32 get_volume_master(void) {
+u8 get_volume_master(void) {
return gLuaVolumeMaster;
}
-f32 get_volume_level(void) {
+u8 get_volume_level(void) {
return gLuaVolumeLevel;
}
-f32 get_volume_sfx(void) {
+u8 get_volume_sfx(void) {
return gLuaVolumeSfx;
}
-f32 get_volume_env(void) {
+u8 get_volume_env(void) {
return gLuaVolumeEnv;
}
-void set_volume_master(f32 volume) {
+void set_volume_master(u8 volume) {
gLuaVolumeMaster = MIN(volume, 127);
audio_custom_update_volume();
}
-void set_volume_level(f32 volume) {
+void set_volume_level(u8 volume) {
gLuaVolumeLevel = MIN(volume, 127);
audio_custom_update_volume();
}
-void set_volume_sfx(f32 volume) {
+void set_volume_sfx(u8 volume) {
gLuaVolumeSfx = MIN(volume, 127);
audio_custom_update_volume();
}
-void set_volume_env(f32 volume) {
+void set_volume_env(u8 volume) {
gLuaVolumeEnv = MIN(volume, 127);
audio_custom_update_volume();
}
diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h
index 1b7d929cb..1106a4425 100644
--- a/src/pc/lua/utils/smlua_misc_utils.h
+++ b/src/pc/lua/utils/smlua_misc_utils.h
@@ -221,21 +221,21 @@ const char* get_local_discord_id(void);
const char* get_coopnet_id(s8 localIndex);
/* |description|Gets the master volume level|descriptionEnd| */
-f32 get_volume_master(void);
+u8 get_volume_master(void);
/* |description|Gets the volume level of music|descriptionEnd| */
-f32 get_volume_level(void);
+u8 get_volume_level(void);
/* |description|Gets the volume level of sound effects|descriptionEnd| */
-f32 get_volume_sfx(void);
+u8 get_volume_sfx(void);
/* |description|Gets the volume level of environment sounds effects|descriptionEnd| */
-f32 get_volume_env(void);
+u8 get_volume_env(void);
/* |description|Sets the master volume level|descriptionEnd| */
-void set_volume_master(f32 volume);
+void set_volume_master(u8 volume);
/* |description|Sets the volume level of music|descriptionEnd| */
-void set_volume_level(f32 volume);
+void set_volume_level(u8 volume);
/* |description|Sets the volume level of sound effects|descriptionEnd| */
-void set_volume_sfx(f32 volume);
+void set_volume_sfx(u8 volume);
/* |description|Sets the volume level of environment sounds effects|descriptionEnd| */
-void set_volume_env(f32 volume);
+void set_volume_env(u8 volume);
/* |description|Gets an environment region (gas/water boxes) height value|descriptionEnd| */
s16 get_environment_region(u8 index);
diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c
index 91f689b6d..389fe4128 100644
--- a/src/pc/pc_main.c
+++ b/src/pc/pc_main.c
@@ -301,6 +301,8 @@ static s16 sAudioBuffer[SAMPLES_HIGH * 2 * 2] = { 0 };
inline static void buffer_audio(void) {
bool shouldMute = (configMuteFocusLoss && !WAPI.has_focus()) || (gMasterVolume == 0);
+ audio_custom_update_mute(shouldMute);
+
if (!shouldMute) {
set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f);
set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f);