GB Audio: Fix some channel 4 timing edge cases

This commit is contained in:
Vicki Pfau 2021-03-15 20:45:21 -07:00
parent 47728c7a8d
commit 3ca82b64af
2 changed files with 8 additions and 4 deletions

View File

@ -29,6 +29,7 @@ Emulation fixes:
- GB: Downgrade DMG-only ROMs from CGB mode even without boot ROM - 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: Fix marking BIOS as unmapped when skipping BIOS (fixes mgba.io/i/2061)
- GB Audio: Fix serializing sweep time - 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 MBC1 mode changing behavior
- GB MBC: Fix some MBC3 bit masking - GB MBC: Fix some MBC3 bit masking
- GB Video: Fix state after skipping BIOS (fixes mgba.io/i/1715 and mgba.io/i/1716) - GB Video: Fix state after skipping BIOS (fixes mgba.io/i/1715 and mgba.io/i/1716)

View File

@ -390,6 +390,7 @@ void GBAudioWriteNR44(struct GBAudio* audio, uint8_t value) {
} }
} }
if (audio->playingCh4 && audio->ch4.envelope.dead != 2) { if (audio->playingCh4 && audio->ch4.envelope.dead != 2) {
audio->ch4.lastEvent = mTimingCurrentTime(audio->timing);
mTimingDeschedule(audio->timing, &audio->ch4Event); mTimingDeschedule(audio->timing, &audio->ch4Event);
mTimingSchedule(audio->timing, &audio->ch4Event, 0); mTimingSchedule(audio->timing, &audio->ch4Event, 0);
} }
@ -581,14 +582,16 @@ void GBAudioUpdateFrame(struct GBAudio* audio, struct mTiming* timing) {
if (audio->playingCh4 && !audio->ch4.envelope.dead) { if (audio->playingCh4 && !audio->ch4.envelope.dead) {
--audio->ch4.envelope.nextStep; --audio->ch4.envelope.nextStep;
if (audio->ch4.envelope.nextStep == 0) { if (audio->ch4.envelope.nextStep == 0) {
int8_t sample = audio->ch4.sample > 0; int8_t sample = audio->ch4.sample;
audio->ch4.samples -= audio->ch4.sample;
_updateEnvelope(&audio->ch4.envelope); _updateEnvelope(&audio->ch4.envelope);
if (audio->ch4.envelope.dead == 2) { if (audio->ch4.envelope.dead == 2) {
mTimingDeschedule(timing, &audio->ch4Event); mTimingDeschedule(timing, &audio->ch4Event);
} }
audio->ch4.sample = sample * audio->ch4.envelope.currentVolume; audio->ch4.sample = (sample > 0) * audio->ch4.envelope.currentVolume;
audio->ch4.samples += audio->ch4.sample; if (audio->ch4.nSamples) {
audio->ch4.samples -= sample;
audio->ch4.samples += audio->ch4.sample;
}
} }
} }
break; break;