properly scale sound volumes instead of abusing fadeVolume

This commit is contained in:
fgsfds 2020-06-15 00:20:23 +03:00
parent 91f50a4089
commit 2e989e4831
6 changed files with 15 additions and 8 deletions

View file

@ -18,7 +18,8 @@ static void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s
s32 i; s32 i;
if (seqChannel->changes.as_bitfields.volume || recalculateVolume) { 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) { if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) {
channelVolume = seqChannel->seqPlayer->muteVolumeScale * channelVolume; channelVolume = seqChannel->seqPlayer->muteVolumeScale * channelVolume;
} }
@ -59,7 +60,8 @@ static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) {
f32 panFromChannel; f32 panFromChannel;
s32 i; 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) { if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) {
channelVolume *= seqChannel->seqPlayer->muteVolumeScale; channelVolume *= seqChannel->seqPlayer->muteVolumeScale;
} }

View file

@ -2062,8 +2062,8 @@ void play_dialog_sound(u8 dialogID) {
#endif #endif
} }
void setSequencePlayerVolume(s32 player, s32 volume){ void set_sequence_player_volume(s32 player, f32 volume) {
func_8031D838(player, 0, volume); gSequencePlayers[player].volumeScale = volume;
} }
void play_music(u8 player, u16 seqArgs, u16 fadeTimer) { void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {

View file

@ -37,7 +37,7 @@ void sound_banks_disable(u8 player, u16 bankMask);
void sound_banks_enable(u8 player, u16 bankMask); void sound_banks_enable(u8 player, u16 bankMask);
void func_80320A4C(u8 bankIndex, u8 arg1); void func_80320A4C(u8 bankIndex, u8 arg1);
void play_dialog_sound(u8 dialogID); 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 play_music(u8 player, u16 seqArgs, u16 fadeTimer);
void stop_background_music(u16 seqId); void stop_background_music(u16 seqId);
void fadeout_background_music(u16 arg0, u16 fadeOut); void fadeout_background_music(u16 arg0, u16 fadeOut);

View file

@ -273,6 +273,7 @@ struct SequencePlayer
#endif #endif
/*0x138, 0x140*/ uintptr_t bankDmaCurrDevAddr; /*0x138, 0x140*/ uintptr_t bankDmaCurrDevAddr;
/*0x13C, 0x144*/ ssize_t bankDmaRemaining; /*0x13C, 0x144*/ ssize_t bankDmaRemaining;
/* ext */ f32 volumeScale;
}; // size = 0x140, 0x148 on EU }; // size = 0x140, 0x148 on EU
struct AdsrSettings struct AdsrSettings

View file

@ -2227,6 +2227,10 @@ void init_sequence_players(void) {
#endif #endif
gSequencePlayers[i].bankDmaInProgress = FALSE; gSequencePlayers[i].bankDmaInProgress = FALSE;
gSequencePlayers[i].seqDmaInProgress = 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_note_lists(&gSequencePlayers[i].notePool);
init_sequence_player(i); init_sequence_player(i);
} }

View file

@ -78,9 +78,9 @@ void produce_one_frame(void) {
gfx_start_frame(); gfx_start_frame();
setSequencePlayerVolume(SEQ_PLAYER_LEVEL, (s32)configMusicVolume); set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f);
setSequencePlayerVolume(SEQ_PLAYER_SFX, (s32)configSfxVolume); set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f);
setSequencePlayerVolume(SEQ_PLAYER_ENV, (s32)configEnvVolume); set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f);
game_loop_one_iteration(); game_loop_one_iteration();
thread6_rumble_loop(NULL); thread6_rumble_loop(NULL);