From ad32c0f750e280945cf32305869d018b3e6cd89f Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 7 Aug 2022 15:29:10 -0700 Subject: [PATCH] GB Audio: Fix regressions --- include/mgba/internal/gb/serialize.h | 12 ++++++------ src/gb/audio.c | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/mgba/internal/gb/serialize.h b/include/mgba/internal/gb/serialize.h index c950af782..bffdb56f2 100644 --- a/include/mgba/internal/gb/serialize.h +++ b/include/mgba/internal/gb/serialize.h @@ -164,12 +164,12 @@ mLOG_DECLARE_CATEGORY(GB_STATE); * | 0x00197: Reserved (leave zero) * 0x00198 - 0x0019F: Global cycle counter * 0x001A0 - 0x001A1: Program counter for last cartridge read - * 0x001A2 - 0x00247: Reserved (leave zero) - * 0x00248 - 0x0025F: Additional audio state - * | 0x00248 - 0x0024B: Last sample timestamp - * | 0x0024C: Current audio sample index - * | 0x0024D - 0x0024F: Reserved (leave zero) - * | 0x00250 - 0x0025F: Audio rendered samples + * 0x001A2 - 0x001D7: Reserved (leave zero) + * 0x001D8 - 0x0025F: Additional audio state + * | 0x001D8 - 0x001DB: Last sample timestamp + * | 0x001DC: Current audio sample index + * | 0x001DD - 0x001DF: Reserved (leave zero) + * | 0x001E0 - 0x0025F: Audio rendered samples * 0x00260 - 0x002FF: OAM * 0x00300 - 0x0037F: I/O memory * 0x00380 - 0x003FE: HRAM diff --git a/src/gb/audio.c b/src/gb/audio.c index 793cceec8..8adc9335f 100644 --- a/src/gb/audio.c +++ b/src/gb/audio.c @@ -474,9 +474,8 @@ void GBAudioRun(struct GBAudio* audio, int32_t timestamp, int channels) { if (!audio->enable) { return; } - if (audio->p && channels != 0xF && timestamp - audio->lastSample > SAMPLE_INTERVAL) { + if (audio->p && channels != 0xF && timestamp - audio->lastSample > (int) (SAMPLE_INTERVAL * audio->timingFactor)) { GBAudioSample(audio, timestamp); - return; } if (audio->playingCh1 && (channels & 0x1)) { @@ -747,10 +746,9 @@ void GBAudioSamplePSG(struct GBAudio* audio, int16_t* left, int16_t* right) { } void GBAudioSample(struct GBAudio* audio, int32_t timestamp) { - timestamp -= audio->lastSample; - timestamp -= audio->sampleIndex * SAMPLE_INTERVAL; - int interval = SAMPLE_INTERVAL * audio->timingFactor; + timestamp -= audio->lastSample; + timestamp -= audio->sampleIndex * interval; int sample; for (sample = audio->sampleIndex; timestamp >= interval && sample < GB_MAX_SAMPLES; ++sample, timestamp -= interval) {