Add ability to set global note frequency scale

This commit is contained in:
Agent X 2024-02-21 20:46:27 -05:00
parent 18a3b333e8
commit de9c3c35b2
9 changed files with 103 additions and 1 deletions

View File

@ -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

View File

@ -7599,6 +7599,24 @@
<br />
## [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:](#)
<br />
## [smlua_audio_utils_replace_sequence](#smlua_audio_utils_replace_sequence)
### Lua Example
@ -7640,6 +7658,26 @@
<br />
## [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:](#)
<br />
---
# functions from smlua_collision_utils.h

View File

@ -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)
<br />

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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 //
//////////

View File

@ -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 //

View File

@ -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;