From 0c231db9e7b6012cc3ab947ac12e18aa4f057d7b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 13 Feb 2018 23:13:15 +0200 Subject: [PATCH] This is probably not correct (and makes no sense from an hardware design perspective), but this correctly emulates my analog test cases and fixes the pops introduced by the last commit. --- Core/apu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Core/apu.c b/Core/apu.c index 29b8dba..ade49b3 100755 --- a/Core/apu.c +++ b/Core/apu.c @@ -24,13 +24,13 @@ static void refresh_channel(GB_gameboy_t *gb, unsigned index, unsigned cycles_of static void update_sample(GB_gameboy_t *gb, unsigned index, uint8_t value, unsigned cycles_offset) { gb->apu.samples[index] = value; - if (gb->apu_output.sample_rate) { + if (gb->apu.is_active[index] && gb->apu_output.sample_rate) { unsigned left_volume = 0; - if (gb->apu.is_active[index] && (gb->io_registers[GB_IO_NR51] & (1 << index))) { + if (gb->io_registers[GB_IO_NR51] & (1 << index)) { left_volume = (gb->io_registers[GB_IO_NR50] & 7) + 1; } unsigned right_volume = 0; - if (gb->apu.is_active[index] && (gb->io_registers[GB_IO_NR51] & (0x10 << index))) { + if (gb->io_registers[GB_IO_NR51] & (0x10 << index)) { right_volume = ((gb->io_registers[GB_IO_NR50] >> 4) & 7) + 1; } GB_sample_t output = {(0xf - value) * left_volume, (0xf - value) * right_volume}; @@ -90,6 +90,10 @@ static void render(GB_gameboy_t *gb) right_volume += ((gb->io_registers[GB_IO_NR50] >> 4) & 7) * CH_STEP * 0xF; } } + else { + left_volume += gb->apu_output.current_sample[i].left * CH_STEP; + right_volume += gb->apu_output.current_sample[i].right * CH_STEP; + } mask >>= 1; } gb->apu_output.highpass_diff = (GB_double_sample_t)