diff --git a/CHANGES b/CHANGES index ada5bd698..5aa3abebd 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ Emulation fixes: - GBA SIO: Fix MULTI mode SIOCNT bit 7 writes on secondary GBAs (fixes mgba.io/i/3110) Other fixes: - GBA Audio: Fix crash if audio FIFOs and timers get out of sync + - GBA Audio: Fix crash in audio subsampling if timing lockstep breaks - GBA Memory: Let raw access read high MMIO addresses - Qt: Fix crash when applying changes to GB I/O registers in I/O view - Qt: Fix LCDC background priority/enable bit being mis-mapped in I/O view diff --git a/src/gba/audio.c b/src/gba/audio.c index e03dcc006..e99a63c33 100644 --- a/src/gba/audio.c +++ b/src/gba/audio.c @@ -268,6 +268,9 @@ void GBAAudioWriteSOUNDBIAS(struct GBAAudio* audio, uint16_t value) { if (oldSampleInterval != audio->sampleInterval) { timestamp -= audio->lastSample; audio->sampleIndex = timestamp >> (9 - GBARegisterSOUNDBIASGetResolution(value)); + if (audio->sampleIndex < 0 || audio->sampleIndex >= GBA_MAX_SAMPLES) { + audio->sampleIndex = 0; + } if (audio->p->stream && audio->p->stream->audioRateChanged) { audio->p->stream->audioRateChanged(audio->p->stream, GBA_ARM7TDMI_FREQUENCY / audio->sampleInterval); }