From 2e989e48310ef31665168e46f29ae14f147ac153 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 15 Jun 2020 00:20:23 +0300 Subject: [PATCH] properly scale sound volumes instead of abusing fadeVolume --- src/audio/effects.c | 6 ++++-- src/audio/external.c | 4 ++-- src/audio/external.h | 2 +- src/audio/internal.h | 1 + src/audio/seqplayer.c | 4 ++++ src/pc/pc_main.c | 6 +++--- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/audio/effects.c b/src/audio/effects.c index 2218fba7..fd78f7af 100644 --- a/src/audio/effects.c +++ b/src/audio/effects.c @@ -18,7 +18,8 @@ static void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s s32 i; if (seqChannel->changes.as_bitfields.volume || recalculateVolume) { - channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->appliedFadeVolume; + channelVolume = seqChannel->volume * seqChannel->volumeScale * + seqChannel->seqPlayer->appliedFadeVolume * seqChannel->seqPlayer->volumeScale; if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) { channelVolume = seqChannel->seqPlayer->muteVolumeScale * channelVolume; } @@ -59,7 +60,8 @@ static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) { f32 panFromChannel; s32 i; - channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->fadeVolume; + channelVolume = seqChannel->volume * seqChannel->volumeScale * + seqChannel->seqPlayer->fadeVolume * seqChannel->seqPlayer->volumeScale; if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) { channelVolume *= seqChannel->seqPlayer->muteVolumeScale; } diff --git a/src/audio/external.c b/src/audio/external.c index b0ebbb99..ff8614e7 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -2062,8 +2062,8 @@ void play_dialog_sound(u8 dialogID) { #endif } -void setSequencePlayerVolume(s32 player, s32 volume){ - func_8031D838(player, 0, volume); +void set_sequence_player_volume(s32 player, f32 volume) { + gSequencePlayers[player].volumeScale = volume; } void play_music(u8 player, u16 seqArgs, u16 fadeTimer) { diff --git a/src/audio/external.h b/src/audio/external.h index 4d763f35..f2ab3ad0 100644 --- a/src/audio/external.h +++ b/src/audio/external.h @@ -37,7 +37,7 @@ void sound_banks_disable(u8 player, u16 bankMask); void sound_banks_enable(u8 player, u16 bankMask); void func_80320A4C(u8 bankIndex, u8 arg1); void play_dialog_sound(u8 dialogID); -void setSequencePlayerVolume(s32 player, s32 volume); +void set_sequence_player_volume(s32 player, f32 volume); void play_music(u8 player, u16 seqArgs, u16 fadeTimer); void stop_background_music(u16 seqId); void fadeout_background_music(u16 arg0, u16 fadeOut); diff --git a/src/audio/internal.h b/src/audio/internal.h index fa44c8be..bd9f1a2d 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -273,6 +273,7 @@ struct SequencePlayer #endif /*0x138, 0x140*/ uintptr_t bankDmaCurrDevAddr; /*0x13C, 0x144*/ ssize_t bankDmaRemaining; + /* ext */ f32 volumeScale; }; // size = 0x140, 0x148 on EU struct AdsrSettings diff --git a/src/audio/seqplayer.c b/src/audio/seqplayer.c index 7e66a220..810dc9ec 100644 --- a/src/audio/seqplayer.c +++ b/src/audio/seqplayer.c @@ -2227,6 +2227,10 @@ void init_sequence_players(void) { #endif gSequencePlayers[i].bankDmaInProgress = FALSE; gSequencePlayers[i].seqDmaInProgress = FALSE; + + // only set this once at the start so it doesn't spike later + gSequencePlayers[i].volumeScale = 1.0f; + init_note_lists(&gSequencePlayers[i].notePool); init_sequence_player(i); } diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 53dcc773..d84fc6f6 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -78,9 +78,9 @@ void produce_one_frame(void) { gfx_start_frame(); - setSequencePlayerVolume(SEQ_PLAYER_LEVEL, (s32)configMusicVolume); - setSequencePlayerVolume(SEQ_PLAYER_SFX, (s32)configSfxVolume); - setSequencePlayerVolume(SEQ_PLAYER_ENV, (s32)configEnvVolume); + set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f); + set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f); + set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f); game_loop_one_iteration(); thread6_rumble_loop(NULL);