all repos — mgba @ 3ca82b64afa0ffd66fba1f0facb3b82176fa4381

mGBA Game Boy Advance Emulator

GB Audio: Fix some channel 4 timing edge cases
Vicki Pfau vi@endrift.com
Mon, 15 Mar 2021 20:45:21 -0700
commit

3ca82b64afa0ffd66fba1f0facb3b82176fa4381

parent

47728c7a8d7f349cae8a22022b803b36515cc23e

2 files changed, 8 insertions(+), 4 deletions(-)

jump to
M CHANGESCHANGES

@@ -29,6 +29,7 @@ - GB: Partially fix timing for skipped BIOS

- GB: Downgrade DMG-only ROMs from CGB mode even without boot ROM - GB: Fix marking BIOS as unmapped when skipping BIOS (fixes mgba.io/i/2061) - GB Audio: Fix serializing sweep time + - GB Audio: Fix some channel 4 timing edge cases - GB MBC: Fix MBC1 mode changing behavior - GB MBC: Fix some MBC3 bit masking - GB Video: Fix state after skipping BIOS (fixes mgba.io/i/1715 and mgba.io/i/1716)
M src/gb/audio.csrc/gb/audio.c

@@ -390,6 +390,7 @@ --audio->ch4.length;

} } if (audio->playingCh4 && audio->ch4.envelope.dead != 2) { + audio->ch4.lastEvent = mTimingCurrentTime(audio->timing); mTimingDeschedule(audio->timing, &audio->ch4Event); mTimingSchedule(audio->timing, &audio->ch4Event, 0); }

@@ -581,14 +582,16 @@

if (audio->playingCh4 && !audio->ch4.envelope.dead) { --audio->ch4.envelope.nextStep; if (audio->ch4.envelope.nextStep == 0) { - int8_t sample = audio->ch4.sample > 0; - audio->ch4.samples -= audio->ch4.sample; + int8_t sample = audio->ch4.sample; _updateEnvelope(&audio->ch4.envelope); if (audio->ch4.envelope.dead == 2) { mTimingDeschedule(timing, &audio->ch4Event); } - audio->ch4.sample = sample * audio->ch4.envelope.currentVolume; - audio->ch4.samples += audio->ch4.sample; + audio->ch4.sample = (sample > 0) * audio->ch4.envelope.currentVolume; + if (audio->ch4.nSamples) { + audio->ch4.samples -= sample; + audio->ch4.samples += audio->ch4.sample; + } } } break;