premultiply volume scales by master volume

instead of scaling the output
This commit is contained in:
fgsfds 2020-06-18 02:20:32 +03:00
parent 94db04aaf0
commit 34af21bad4
2 changed files with 7 additions and 13 deletions

View file

@ -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;

View file

@ -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();
}