From 34af21bad4630fa71a7dc5e80a5d8d3b264b78f4 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Thu, 18 Jun 2020 02:20:32 +0300 Subject: [PATCH] premultiply volume scales by master volume instead of scaling the output --- src/pc/configfile.h | 5 ++--- src/pc/pc_main.c | 15 +++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 45025141..18e4b919 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -5,9 +5,8 @@ #define CONFIGFILE_DEFAULT "sm64config.txt" -#define MAX_BINDS 3 -#define MAX_VOLUME 127 -#define VOLUME_SHIFT 7 +#define MAX_BINDS 3 +#define MAX_VOLUME 127 typedef struct { unsigned int x, y, w, h; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index d84fc6f6..af07b57a 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -75,12 +75,12 @@ void send_display_list(struct SPTask *spTask) { #define printf void produce_one_frame(void) { - gfx_start_frame(); - 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); + const f32 master_mod = (f32)configMasterVolume / 127.0f; + set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * master_mod); + set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * master_mod); + set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * master_mod); game_loop_one_iteration(); thread6_rumble_loop(NULL); @@ -98,13 +98,8 @@ void produce_one_frame(void) { } //printf("Audio samples before submitting: %d\n", audio_api->buffered()); - // scale by master volume (0-127) - const s32 mod = (s32)configMasterVolume; - for (u32 i = 0; i < num_audio_samples * 4; ++i) - audio_buffer[i] = ((s32)audio_buffer[i] * mod) >> VOLUME_SHIFT; - audio_api->play((u8*)audio_buffer, 2 * num_audio_samples * 4); - + gfx_end_frame(); }