Skip to content

Commit

Permalink
Fix an audio bug when the frequency of SOUND1CNT_X is overwritten w…
Browse files Browse the repository at this point in the history
…hen a sound is playing.
  • Loading branch information
Arignir committed Feb 12, 2024
1 parent ff7d66f commit 371c5db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion source/gba/apu/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ apu_modules_sweep_step(
new_frequency = sweep->shadow_frequency + (sweep->shadow_frequency >> sweep->shifts);
}

/* Overflow check */
if (new_frequency >= 2048) {
return (false);
} else if (sweep->shifts > 0) {
}

if (sweep->shifts > 0) {
sweep->frequency = new_frequency;
sweep->shadow_frequency = new_frequency;
}
Expand Down
4 changes: 4 additions & 0 deletions source/gba/memory/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ mem_io_write8(
case IO_REG_SOUND1CNT_X: io->sound1cnt_x.bytes[0] = val; break;
case IO_REG_SOUND1CNT_X + 1: {
io->sound1cnt_x.bytes[1] = val;

gba->apu.tone_and_sweep.sweep.frequency = io->sound1cnt_x.sample_rate;
gba->apu.tone_and_sweep.sweep.shadow_frequency = io->sound1cnt_x.sample_rate;

if (io->sound1cnt_x.reset) {
apu_tone_and_sweep_reset(gba);
}
Expand Down

0 comments on commit 371c5db

Please sign in to comment.