From 8bae9e2ec7c3964e358264ca56492baf025604f5 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Tue, 11 Jun 2024 19:10:40 -0400 Subject: [PATCH] Change Lua volume control to 0-127 instead of 0.0-1.0 --- src/pc/lua/utils/smlua_audio_utils.c | 12 ++++++------ src/pc/lua/utils/smlua_misc_utils.c | 8 ++++---- src/pc/network/network.c | 8 ++++---- src/pc/pc_main.c | 16 ++++++++-------- src/pc/pc_main.h | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c index d15e2e23..95d7ee1f 100644 --- a/src/pc/lua/utils/smlua_audio_utils.c +++ b/src/pc/lua/utils/smlua_audio_utils.c @@ -281,8 +281,8 @@ void audio_stream_play(struct ModAudio* audio, bool restart, f32 volume) { if (!audio_sanity_check(audio, true, "play")) { return; } - f32 masterVolume = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster; - f32 musicVolume = (f32)configMusicVolume / 127.0f * gLuaVolumeLevel; + f32 masterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f; + f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f; ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * volume); audio->baseVolume = volume; if (restart || !ma_sound_is_playing(&audio->sound)) { ma_sound_seek_to_pcm_frame(&audio->sound, 0); } @@ -511,8 +511,8 @@ void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume) { } f32 intensity = sound_get_level_intensity(dist); - f32 masterVolume = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster; - f32 sfxVolume = (f32)configSfxVolume / 127.0f * gLuaVolumeSfx; + f32 masterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f; + f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f; ma_sound_set_volume(sound, masterVolume * sfxVolume * volume * intensity); ma_sound_set_pan(sound, pan); audio->baseVolume = volume; @@ -525,8 +525,8 @@ void audio_custom_update_volume(void) { while (node) { struct DynamicPoolNode* prev = node->prev; struct ModAudio* audio = node->ptr; - f32 masterVolume = (f32)configMasterVolume / 127.0f; - f32 musicVolume = (f32)configMusicVolume / 127.0f; + f32 masterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f; + f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f; if (audio->isStream) { ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * audio->baseVolume); } diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index ebd295e0..fa5326b3 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -674,22 +674,22 @@ f32 get_volume_env(void) { } void set_volume_master(f32 volume) { - gLuaVolumeMaster = clampf(volume, 0.0f, 1.0f); + gLuaVolumeMaster = MIN(volume, 127); audio_custom_update_volume(); } void set_volume_level(f32 volume) { - gLuaVolumeLevel = clampf(volume, 0.0f, 1.0f); + gLuaVolumeLevel = MIN(volume, 127); audio_custom_update_volume(); } void set_volume_sfx(f32 volume) { - gLuaVolumeSfx = clampf(volume, 0.0f, 1.0f); + gLuaVolumeSfx = MIN(volume, 127); audio_custom_update_volume(); } void set_volume_env(f32 volume) { - gLuaVolumeEnv = clampf(volume, 0.0f, 1.0f); + gLuaVolumeEnv = MIN(volume, 127); audio_custom_update_volume(); } diff --git a/src/pc/network/network.c b/src/pc/network/network.c index bee2bc2e..89efddec 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -700,10 +700,10 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gOverrideDialogColor = 0; gDialogMinWidth = 0; gOverrideAllowToxicGasCamera = FALSE; - gLuaVolumeMaster = 1.0f; - gLuaVolumeLevel = 1.0f; - gLuaVolumeSfx = 1.0f; - gLuaVolumeEnv = 1.0f; + gLuaVolumeMaster = 127; + gLuaVolumeLevel = 127; + gLuaVolumeSfx = 127; + gLuaVolumeEnv = 127; struct Controller* cnt = gPlayer1Controller; cnt->rawStickX = 0; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 464066ad..3b62e04c 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -88,10 +88,10 @@ static f64 sFrameTimeStart; bool gGameInited = false; bool gGfxInited = false; -f32 gLuaVolumeMaster = 1.0f; -f32 gLuaVolumeLevel = 1.0f; -f32 gLuaVolumeSfx = 1.0f; -f32 gLuaVolumeEnv = 1.0f; +u8 gLuaVolumeMaster = 127; +u8 gLuaVolumeLevel = 127; +u8 gLuaVolumeSfx = 127; +u8 gLuaVolumeEnv = 127; static struct AudioAPI *audio_api; struct GfxWindowManagerAPI *wm_api = &WAPI; @@ -222,10 +222,10 @@ void produce_interpolation_frames_and_delay(void) { } inline static void buffer_audio(void) { - const f32 masterMod = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster; - set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * gLuaVolumeLevel * masterMod); - set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * gLuaVolumeSfx * masterMod); - set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * gLuaVolumeEnv * masterMod); + const f32 masterMod = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f; + set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f * masterMod); + set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f * masterMod); + set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * (f32)gLuaVolumeEnv / 127.0f * masterMod); int samplesLeft = audio_api->buffered(); u32 numAudioSamples = samplesLeft < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW; diff --git a/src/pc/pc_main.h b/src/pc/pc_main.h index d04a2515..24f8230c 100644 --- a/src/pc/pc_main.h +++ b/src/pc/pc_main.h @@ -64,10 +64,10 @@ extern "C" { extern bool gGameInited; extern bool gGfxInited; -extern f32 gLuaVolumeMaster; -extern f32 gLuaVolumeLevel; -extern f32 gLuaVolumeSfx; -extern f32 gLuaVolumeEnv; +extern u8 gLuaVolumeMaster; +extern u8 gLuaVolumeLevel; +extern u8 gLuaVolumeSfx; +extern u8 gLuaVolumeEnv; extern struct GfxWindowManagerAPI* wm_api; void produce_one_dummy_frame(void (*callback)());