Change Lua volume control to 0-127 instead of 0.0-1.0

This commit is contained in:
Agent X 2024-06-11 19:10:40 -04:00
parent a638c4725c
commit 8bae9e2ec7
5 changed files with 26 additions and 26 deletions

View File

@ -281,8 +281,8 @@ void audio_stream_play(struct ModAudio* audio, bool restart, f32 volume) {
if (!audio_sanity_check(audio, true, "play")) { if (!audio_sanity_check(audio, true, "play")) {
return; return;
} }
f32 masterVolume = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster; f32 masterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
f32 musicVolume = (f32)configMusicVolume / 127.0f * gLuaVolumeLevel; f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * volume); ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * volume);
audio->baseVolume = volume; audio->baseVolume = volume;
if (restart || !ma_sound_is_playing(&audio->sound)) { ma_sound_seek_to_pcm_frame(&audio->sound, 0); } 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 intensity = sound_get_level_intensity(dist);
f32 masterVolume = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster; f32 masterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
f32 sfxVolume = (f32)configSfxVolume / 127.0f * gLuaVolumeSfx; f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
ma_sound_set_volume(sound, masterVolume * sfxVolume * volume * intensity); ma_sound_set_volume(sound, masterVolume * sfxVolume * volume * intensity);
ma_sound_set_pan(sound, pan); ma_sound_set_pan(sound, pan);
audio->baseVolume = volume; audio->baseVolume = volume;
@ -525,8 +525,8 @@ void audio_custom_update_volume(void) {
while (node) { while (node) {
struct DynamicPoolNode* prev = node->prev; struct DynamicPoolNode* prev = node->prev;
struct ModAudio* audio = node->ptr; struct ModAudio* audio = node->ptr;
f32 masterVolume = (f32)configMasterVolume / 127.0f; f32 masterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
f32 musicVolume = (f32)configMusicVolume / 127.0f; f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
if (audio->isStream) { if (audio->isStream) {
ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * audio->baseVolume); ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * audio->baseVolume);
} }

View File

@ -674,22 +674,22 @@ f32 get_volume_env(void) {
} }
void set_volume_master(f32 volume) { void set_volume_master(f32 volume) {
gLuaVolumeMaster = clampf(volume, 0.0f, 1.0f); gLuaVolumeMaster = MIN(volume, 127);
audio_custom_update_volume(); audio_custom_update_volume();
} }
void set_volume_level(f32 volume) { void set_volume_level(f32 volume) {
gLuaVolumeLevel = clampf(volume, 0.0f, 1.0f); gLuaVolumeLevel = MIN(volume, 127);
audio_custom_update_volume(); audio_custom_update_volume();
} }
void set_volume_sfx(f32 volume) { void set_volume_sfx(f32 volume) {
gLuaVolumeSfx = clampf(volume, 0.0f, 1.0f); gLuaVolumeSfx = MIN(volume, 127);
audio_custom_update_volume(); audio_custom_update_volume();
} }
void set_volume_env(f32 volume) { void set_volume_env(f32 volume) {
gLuaVolumeEnv = clampf(volume, 0.0f, 1.0f); gLuaVolumeEnv = MIN(volume, 127);
audio_custom_update_volume(); audio_custom_update_volume();
} }

View File

@ -700,10 +700,10 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gOverrideDialogColor = 0; gOverrideDialogColor = 0;
gDialogMinWidth = 0; gDialogMinWidth = 0;
gOverrideAllowToxicGasCamera = FALSE; gOverrideAllowToxicGasCamera = FALSE;
gLuaVolumeMaster = 1.0f; gLuaVolumeMaster = 127;
gLuaVolumeLevel = 1.0f; gLuaVolumeLevel = 127;
gLuaVolumeSfx = 1.0f; gLuaVolumeSfx = 127;
gLuaVolumeEnv = 1.0f; gLuaVolumeEnv = 127;
struct Controller* cnt = gPlayer1Controller; struct Controller* cnt = gPlayer1Controller;
cnt->rawStickX = 0; cnt->rawStickX = 0;

View File

@ -88,10 +88,10 @@ static f64 sFrameTimeStart;
bool gGameInited = false; bool gGameInited = false;
bool gGfxInited = false; bool gGfxInited = false;
f32 gLuaVolumeMaster = 1.0f; u8 gLuaVolumeMaster = 127;
f32 gLuaVolumeLevel = 1.0f; u8 gLuaVolumeLevel = 127;
f32 gLuaVolumeSfx = 1.0f; u8 gLuaVolumeSfx = 127;
f32 gLuaVolumeEnv = 1.0f; u8 gLuaVolumeEnv = 127;
static struct AudioAPI *audio_api; static struct AudioAPI *audio_api;
struct GfxWindowManagerAPI *wm_api = &WAPI; struct GfxWindowManagerAPI *wm_api = &WAPI;
@ -222,10 +222,10 @@ void produce_interpolation_frames_and_delay(void) {
} }
inline static void buffer_audio(void) { inline static void buffer_audio(void) {
const f32 masterMod = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster; const f32 masterMod = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * gLuaVolumeLevel * masterMod); 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 * gLuaVolumeSfx * 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 * gLuaVolumeEnv * masterMod); set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * (f32)gLuaVolumeEnv / 127.0f * masterMod);
int samplesLeft = audio_api->buffered(); int samplesLeft = audio_api->buffered();
u32 numAudioSamples = samplesLeft < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW; u32 numAudioSamples = samplesLeft < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW;

View File

@ -64,10 +64,10 @@ extern "C" {
extern bool gGameInited; extern bool gGameInited;
extern bool gGfxInited; extern bool gGfxInited;
extern f32 gLuaVolumeMaster; extern u8 gLuaVolumeMaster;
extern f32 gLuaVolumeLevel; extern u8 gLuaVolumeLevel;
extern f32 gLuaVolumeSfx; extern u8 gLuaVolumeSfx;
extern f32 gLuaVolumeEnv; extern u8 gLuaVolumeEnv;
extern struct GfxWindowManagerAPI* wm_api; extern struct GfxWindowManagerAPI* wm_api;
void produce_one_dummy_frame(void (*callback)()); void produce_one_dummy_frame(void (*callback)());