diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index ac879cbf..7be35db2 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -8275,6 +8275,11 @@ function audio_stream_stop(audio) -- ... end +--- @return number +function smlua_audio_utils_get_note_freq_scale() + -- ... +end + --- @param sequenceId integer --- @param bankId integer --- @param defaultVolume integer @@ -8289,6 +8294,12 @@ function smlua_audio_utils_reset_all() -- ... end +--- @param freq number +--- @return nil +function smlua_audio_utils_set_note_freq_scale(freq) + -- ... +end + --- @param x number --- @param y number --- @param z number diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index a00739a8..4ac3b843 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -7599,6 +7599,24 @@
+## [smlua_audio_utils_get_note_freq_scale](#smlua_audio_utils_get_note_freq_scale) + +### Lua Example +`local numberValue = smlua_audio_utils_get_note_freq_scale()` + +### Parameters +- None + +### Returns +- `number` + +### C Prototype +`f32 smlua_audio_utils_get_note_freq_scale(void);` + +[:arrow_up_small:](#) + +
+ ## [smlua_audio_utils_replace_sequence](#smlua_audio_utils_replace_sequence) ### Lua Example @@ -7640,6 +7658,26 @@
+## [smlua_audio_utils_set_note_freq_scale](#smlua_audio_utils_set_note_freq_scale) + +### Lua Example +`smlua_audio_utils_set_note_freq_scale(freq)` + +### Parameters +| Field | Type | +| ----- | ---- | +| freq | `number` | + +### Returns +- None + +### C Prototype +`void smlua_audio_utils_set_note_freq_scale(f32 freq);` + +[:arrow_up_small:](#) + +
+ --- # functions from smlua_collision_utils.h diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 5bd5b39e..cc29ef67 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1547,8 +1547,10 @@ - [audio_stream_set_tempo](functions-4.md#audio_stream_set_tempo) - [audio_stream_set_volume](functions-4.md#audio_stream_set_volume) - [audio_stream_stop](functions-4.md#audio_stream_stop) + - [smlua_audio_utils_get_note_freq_scale](functions-4.md#smlua_audio_utils_get_note_freq_scale) - [smlua_audio_utils_replace_sequence](functions-4.md#smlua_audio_utils_replace_sequence) - [smlua_audio_utils_reset_all](functions-4.md#smlua_audio_utils_reset_all) + - [smlua_audio_utils_set_note_freq_scale](functions-4.md#smlua_audio_utils_set_note_freq_scale)
diff --git a/src/audio/playback.c b/src/audio/playback.c index a20e39b2..93c85803 100644 --- a/src/audio/playback.c +++ b/src/audio/playback.c @@ -9,6 +9,8 @@ #include "effects.h" #include "external.h" +f32 gNoteFreqScale = 1.0f; + void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput); #if defined(VERSION_EU) || defined(VERSION_SH) @@ -598,7 +600,7 @@ void process_notes(void) { frequency = (frequency < cap ? frequency : cap); scale *= 4.3498e-5f; // ~1 / 23000 velocity = velocity * scale * scale; - note_set_frequency(note, frequency); + note_set_frequency(note, frequency * gNoteFreqScale); note_set_vel_pan_reverb(note, velocity, pan, reverb); continue; } diff --git a/src/audio/playback.h b/src/audio/playback.h index d0eaf2ba..6ee8d323 100644 --- a/src/audio/playback.h +++ b/src/audio/playback.h @@ -16,6 +16,8 @@ #define NOTE_ALLOC_SEQ 4 #define NOTE_ALLOC_GLOBAL_FREELIST 8 +extern f32 gNoteFreqScale; + void process_notes(void); void seq_channel_layer_note_decay(struct SequenceChannelLayer *seqLayer); void seq_channel_layer_note_release(struct SequenceChannelLayer *seqLayer); diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 193baee4..e57b32d8 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -27547,6 +27547,21 @@ int smlua_func_audio_stream_stop(lua_State* L) { return 1; } +int smlua_func_smlua_audio_utils_get_note_freq_scale(UNUSED lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 0) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "smlua_audio_utils_get_note_freq_scale", 0, top); + return 0; + } + + + lua_pushnumber(L, smlua_audio_utils_get_note_freq_scale()); + + return 1; +} + int smlua_func_smlua_audio_utils_replace_sequence(lua_State* L) { if (L == NULL) { return 0; } @@ -27585,6 +27600,23 @@ int smlua_func_smlua_audio_utils_reset_all(UNUSED lua_State* L) { return 1; } +int smlua_func_smlua_audio_utils_set_note_freq_scale(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", "smlua_audio_utils_set_note_freq_scale", 1, top); + return 0; + } + + f32 freq = smlua_to_number(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "smlua_audio_utils_set_note_freq_scale"); return 0; } + + smlua_audio_utils_set_note_freq_scale(freq); + + return 1; +} + ///////////////////////////// // smlua_collision_utils.h // ///////////////////////////// @@ -32824,8 +32856,10 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "audio_stream_set_tempo", smlua_func_audio_stream_set_tempo); smlua_bind_function(L, "audio_stream_set_volume", smlua_func_audio_stream_set_volume); smlua_bind_function(L, "audio_stream_stop", smlua_func_audio_stream_stop); + smlua_bind_function(L, "smlua_audio_utils_get_note_freq_scale", smlua_func_smlua_audio_utils_get_note_freq_scale); smlua_bind_function(L, "smlua_audio_utils_replace_sequence", smlua_func_smlua_audio_utils_replace_sequence); smlua_bind_function(L, "smlua_audio_utils_reset_all", smlua_func_smlua_audio_utils_reset_all); + smlua_bind_function(L, "smlua_audio_utils_set_note_freq_scale", smlua_func_smlua_audio_utils_set_note_freq_scale); // smlua_collision_utils.h smlua_bind_function(L, "collision_find_ceil", smlua_func_collision_find_ceil); diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c index 990e61ce..5ed64aab 100644 --- a/src/pc/lua/utils/smlua_audio_utils.c +++ b/src/pc/lua/utils/smlua_audio_utils.c @@ -1,6 +1,7 @@ #include "types.h" #include "seq_ids.h" #include "audio/external.h" +#include "audio/playback.h" #include "game/camera.h" #include "engine/math_util.h" #include "pc/mods/mods.h" @@ -144,6 +145,14 @@ void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolu LOG_LUA_LINE("Could not find m64 at path: %s", m64path); } +f32 smlua_audio_utils_get_note_freq_scale(void) { + return gNoteFreqScale; +} + +void smlua_audio_utils_set_note_freq_scale(f32 freq) { + gNoteFreqScale = freq; +} + ////////// // bass // ////////// diff --git a/src/pc/lua/utils/smlua_audio_utils.h b/src/pc/lua/utils/smlua_audio_utils.h index 07f16be6..26d39753 100644 --- a/src/pc/lua/utils/smlua_audio_utils.h +++ b/src/pc/lua/utils/smlua_audio_utils.h @@ -6,6 +6,8 @@ void smlua_audio_utils_reset_all(void); bool smlua_audio_utils_override(u8 sequenceId, s32* bankId, void** seqData); void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolume, const char* m64Name); +f32 smlua_audio_utils_get_note_freq_scale(void); +void smlua_audio_utils_set_note_freq_scale(f32 freq); ////////// // bass // diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 20cc5647..0bc061d5 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -29,6 +29,7 @@ #include "menu/intro_geo.h" #include "game/ingame_menu.h" #include "game/first_person_cam.h" +#include "audio/playback.h" #ifdef DISCORD_SDK #include "pc/discord/discord.h" @@ -696,6 +697,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gOverrideDialogColor = 0; gDialogMinWidth = 0; gOverrideAllowToxicGasCamera = FALSE; + gNoteFreqScale = 1.0f; struct Controller* cnt = gMarioStates[0].controller; cnt->rawStickX = 0;