From ca9448cd353ca12264bfa1dcfddc6fe470f7d77a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 22 Sep 2018 15:34:18 -0700 Subject: [PATCH] GB Audio: Fix channel 1, 2 and 4 reset timing --- CHANGES | 1 + src/gb/audio.c | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index b521da8f0..032f4e537 100644 --- a/CHANGES +++ b/CHANGES @@ -61,6 +61,7 @@ Bugfixes: - GB Audio: Fix channel 3 reset value - GB Audio: Fix channel 4 initial LFSR - GB, GBA Video: Don't call finishFrame twice in thread proxy + - GB Audio: Fix channel 1, 2 and 4 reset timing Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722) diff --git a/src/gb/audio.c b/src/gb/audio.c index f1489c9bb..6c8b7bfe1 100644 --- a/src/gb/audio.c +++ b/src/gb/audio.c @@ -206,11 +206,6 @@ void GBAudioWriteNR14(struct GBAudio* audio, uint8_t value) { } if (GBAudioRegisterControlIsRestart(value << 8)) { audio->playingCh1 = _resetEnvelope(&audio->ch1.envelope); - - if (audio->playingCh1) { - _updateSquareSample(&audio->ch1); - } - audio->ch1.sweep.realFrequency = audio->ch1.control.frequency; _resetSweep(&audio->ch1.sweep); if (audio->playingCh1 && audio->ch1.sweep.shift) { @@ -222,7 +217,8 @@ void GBAudioWriteNR14(struct GBAudio* audio, uint8_t value) { --audio->ch1.control.length; } } - if (audio->playingCh1 && audio->ch1.envelope.dead != 2 && !mTimingIsScheduled(audio->timing, &audio->ch1Event)) { + if (audio->playingCh1 && audio->ch1.envelope.dead != 2) { + mTimingDeschedule(audio->timing, &audio->ch1Event); mTimingSchedule(audio->timing, &audio->ch1Event, 0); } } @@ -263,17 +259,14 @@ void GBAudioWriteNR24(struct GBAudio* audio, uint8_t value) { if (GBAudioRegisterControlIsRestart(value << 8)) { audio->playingCh2 = _resetEnvelope(&audio->ch2.envelope); - if (audio->playingCh2) { - _updateSquareSample(&audio->ch2); - } - if (!audio->ch2.control.length) { audio->ch2.control.length = 64; if (audio->ch2.control.stop && !(audio->frame & 1)) { --audio->ch2.control.length; } } - if (audio->playingCh2 && audio->ch2.envelope.dead != 2 && !mTimingIsScheduled(audio->timing, &audio->ch2Event)) { + if (audio->playingCh2 && audio->ch2.envelope.dead != 2) { + mTimingDeschedule(audio->timing, &audio->ch2Event); mTimingSchedule(audio->timing, &audio->ch2Event, 0); } } @@ -390,7 +383,8 @@ void GBAudioWriteNR44(struct GBAudio* audio, uint8_t value) { --audio->ch4.length; } } - if (audio->playingCh4 && audio->ch4.envelope.dead != 2 && !mTimingIsScheduled(audio->timing, &audio->ch4Event)) { + if (audio->playingCh4 && audio->ch4.envelope.dead != 2) { + mTimingDeschedule(audio->timing, &audio->ch4Event); mTimingSchedule(audio->timing, &audio->ch4Event, 0); } }