Fixed sound pops in Super Mario Land 2.

This commit is contained in:
Lior Halphon 2018-01-19 00:47:46 +02:00
parent 130c7c28c2
commit 37906bcd1f
1 changed files with 11 additions and 9 deletions

View File

@ -173,10 +173,12 @@ void GB_apu_div_event(GB_gameboy_t *gb)
gb->apu.square_channels[i].volume_countdown = nrx2 & 7;
if (gb->apu.is_active[i]) {
update_square_sample(gb, i);
}
}
}
}
uint8_t nr42 = gb->io_registers[GB_IO_NR42];
@ -192,6 +194,7 @@ void GB_apu_div_event(GB_gameboy_t *gb)
gb->apu.noise_channel.volume_countdown = nr42 & 7;
if (gb->apu.is_active[GB_NOISE]) {
update_sample(gb, GB_NOISE,
(gb->apu.noise_channel.lfsr & 1) ?
gb->apu.noise_channel.current_volume : 0,
@ -199,6 +202,7 @@ void GB_apu_div_event(GB_gameboy_t *gb)
}
}
}
}
if ((gb->apu.div_divider & 1) == 1) {
for (unsigned i = GB_SQUARE_2 + 1; i--;) {
@ -748,8 +752,6 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
case GB_IO_NR44: {
if (value & 0x80) {
gb->apu.noise_channel.lfsr = 0;
gb->apu.noise_channel.sample_countdown = (gb->apu.noise_channel.sample_length) * 2 + 6 - gb->apu.lf_div;
/* I'm COMPLETELY unsure about this logic, but it passes all relevant tests.
@ -777,7 +779,7 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
gb->apu.noise_channel.current_volume : 0,
0);
}
gb->apu.noise_channel.lfsr = 0;
gb->apu.noise_channel.volume_countdown = gb->io_registers[GB_IO_NR42] & 7;
if ((gb->io_registers[GB_IO_NR42] & 0xF8) != 0) {