From 37e895352f12af9b80cf7e2acd475bd8ac16c01d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 20 Sep 2016 19:58:30 +0300 Subject: [PATCH] Volumes no longer doubles --- Core/apu.c | 12 ++++++------ Core/apu.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Core/apu.c b/Core/apu.c index c1d62d3..9bedc5e 100755 --- a/Core/apu.c +++ b/Core/apu.c @@ -177,8 +177,8 @@ void GB_apu_get_samples_and_update_pcm_regs(GB_gameboy_t *gb, GB_sample_t *sampl gb->io_registers[GB_IO_PCM_34] |= (((int)sample) * 0xF / MAX_CH_AMP) << 4; } - samples->left *= gb->apu.left_volume; - samples->right *= gb->apu.right_volume; + samples->left = (int) samples->left * gb->apu.left_volume / 7; + samples->right = (int) samples->right * gb->apu.right_volume / 7; } void GB_apu_run(GB_gameboy_t *gb) @@ -232,8 +232,8 @@ void GB_apu_init(GB_gameboy_t *gb) memset(&gb->apu, 0, sizeof(gb->apu)); gb->apu.wave_channels[0].duty = gb->apu.wave_channels[1].duty = 4; gb->apu.lfsr = 0x7FFF; - gb->apu.left_volume = 1.0; - gb->apu.right_volume = 1.0; + gb->apu.left_volume = 7; + gb->apu.right_volume = 7; for (int i = 0; i < 4; i++) { gb->apu.wave_channels[i].left_on = gb->apu.wave_channels[i].right_on = 1; } @@ -410,8 +410,8 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) break; case GB_IO_NR50: - gb->apu.left_volume = (value & 7) / 7.0; - gb->apu.right_volume = ((value >> 4) & 7) / 7.0; + gb->apu.left_volume = (value & 7); + gb->apu.right_volume = ((value >> 4) & 7); break; case GB_IO_NR51: diff --git a/Core/apu.h b/Core/apu.h index c02e191..ffd10e9 100644 --- a/Core/apu.h +++ b/Core/apu.h @@ -53,8 +53,8 @@ typedef struct bool wave_enable; uint16_t lfsr; bool lfsr_7_bit; - double left_volume; - double right_volume; + uint8_t left_volume; + uint8_t right_volume; GB_apu_channel_t wave_channels[4]; } GB_apu_t;