From 56b14c67aafa2bedf86f99d10edda037c415dca0 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 22 Jan 2022 01:11:23 +0200 Subject: [PATCH] Fixed AGB audio regression --- Cocoa/Document.m | 3 +-- Core/apu.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 92b348d..80da097 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -1128,9 +1128,8 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) [self.consoleWindow orderFront:nil]; } pending_console_output = nil; -} + } [console_output_lock unlock]; - } - (void) log: (const char *) string withAttributes: (GB_log_attributes) attributes diff --git a/Core/apu.c b/Core/apu.c index 2708113..572969a 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -72,9 +72,7 @@ static void update_sample(GB_gameboy_t *gb, unsigned index, int8_t value, unsign /* For some reason, channel 3 is inverted on the AGB */ value ^= 0xF; } - - if (value == 0 && gb->apu.samples[index] == 0) return; - + if (gb->model >= GB_MODEL_AGB) { /* On the AGB, because no analog mixing is done, the behavior of NR51 is a bit different. A channel that is not connected to a terminal is idenitcal to a connected channel @@ -111,6 +109,8 @@ static void update_sample(GB_gameboy_t *gb, unsigned index, int8_t value, unsign return; } + if (value == 0 && gb->apu.samples[index] == 0) return; + if (!GB_apu_is_DAC_enabled(gb, index)) { value = gb->apu.samples[index]; } @@ -283,7 +283,12 @@ static void render(GB_gameboy_t *gb) static void update_square_sample(GB_gameboy_t *gb, unsigned index) { - if (gb->apu.square_channels[index].sample_surpressed) return; + if (gb->apu.square_channels[index].sample_surpressed) { + if (gb->model >= GB_MODEL_AGB) { + update_sample(gb, index, gb->apu.samples[index], 0); + } + return; + } uint8_t duty = gb->io_registers[index == GB_SQUARE_1? GB_IO_NR11 :GB_IO_NR21] >> 6; update_sample(gb, index,